18216
|
1 ;;; pc-select.el --- emulate mark, cut, copy and paste from Motif
|
|
2 ;;; (or MAC GUI or MS-windoze (bah)) look-and-feel
|
|
3 ;;; including key bindings.
|
13233
|
4
|
18216
|
5 ;; Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
|
13233
|
6
|
|
7 ;; Author: Michael Staats <michael@thp.Uni-Duisburg.DE>
|
|
8 ;; Created: 26 Sep 1995
|
|
9
|
|
10 ;; This file is part of GNU Emacs.
|
|
11
|
|
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
13 ;; it under the terms of the GNU General Public License as published by
|
|
14 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
15 ;; any later version.
|
|
16
|
|
17 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20 ;; GNU General Public License for more details.
|
|
21
|
|
22 ;; You should have received a copy of the GNU General Public License
|
14169
|
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
25 ;; Boston, MA 02111-1307, USA.
|
13233
|
26
|
|
27 ;;; Commentary:
|
14169
|
28
|
13233
|
29 ;; This package emulates the mark, copy, cut and paste look-and-feel of motif
|
|
30 ;; programs (which is the same as the MAC gui and (sorry for that) MS-Windows).
|
|
31 ;; It modifies the keybindings of the cursor keys and the next, prior,
|
|
32 ;; home and end keys. They will modify mark-active.
|
|
33 ;; You can still get the old behaviour of cursor moving with the
|
|
34 ;; control sequences C-f, C-b, etc.
|
|
35 ;; This package uses transient-mark-mode and
|
|
36 ;; delete-selection-mode.
|
|
37 ;;
|
|
38 ;; In addition to that all key-bindings from the pc-mode are
|
|
39 ;; done here too (as suggested by RMS).
|
|
40 ;;
|
|
41 ;; As I found out after I finished the first version, s-region.el tries
|
|
42 ;; to do the same.... But my code is a little more complete and using
|
|
43 ;; delete-selection-mode is very important for the look-and-feel.
|
|
44 ;; Pete Forman <pete.forman@airgun.wg.waii.com> provided some motif
|
|
45 ;; compliant keybindings which I added. I had to modify them a little
|
|
46 ;; to add the -mark and -nomark functionality of cursor moving.
|
|
47 ;;
|
|
48 ;; Credits:
|
|
49 ;; Many thanks to all who made comments.
|
|
50 ;; Thanks to RMS and Ralf Muschall <prm@rz.uni-jena.de> for criticism.
|
|
51 ;; Kevin Cutts <cutts@ukraine.corp.mot.com> added the beginning-of-buffer
|
|
52 ;; and end-of-buffer functions which I modified a little.
|
|
53 ;; David Biesack <sasdjb@unx.sas.com> suggested some more cleanup.
|
|
54 ;; Thanks to Pete Forman <pete.forman@airgun.wg.waii.com>
|
|
55 ;; for additional motif keybindings.
|
14382
|
56 ;; Thanks to jvromans@squirrel.nl (Johan Vromans) for a bug report
|
|
57 ;; concerning setting of this-command.
|
15907
|
58 ;; Dan Nicolaescu <done@nexus.sorostm.ro> suggested suppressing the
|
|
59 ;; scroll-up/scroll-down error.
|
18216
|
60 ;; Eli Barzilay (eli@cs.bgu.ac.il) suggested the sexps functions and
|
|
61 ;; keybindings.
|
13233
|
62 ;;
|
|
63 ;; Ok, some details about the idea of pc-selection-mode:
|
|
64 ;;
|
|
65 ;; o The standard keys for moving around (right, left, up, down, home, end,
|
|
66 ;; prior, next, called "move-keys" from now on) will always de-activate
|
|
67 ;; the mark.
|
|
68 ;; o If you press "Shift" together with the "move-keys", the region
|
|
69 ;; you pass along is activated
|
|
70 ;; o You have the copy, cut and paste functions (as in many other programs)
|
|
71 ;; which will operate on the active region
|
|
72 ;; It was not possible to bind them to C-v, C-x and C-c for obvious
|
|
73 ;; emacs reasons.
|
|
74 ;; They will be bound according to the "old" behaviour to S-delete (cut),
|
|
75 ;; S-insert (paste) and C-insert (copy). These keys do the same in many
|
|
76 ;; other programs.
|
15907
|
77 ;;
|
13233
|
78
|
15907
|
79 ;;;; Customization:
|
|
80
|
|
81 (defvar pc-select-override-scroll-error t
|
|
82 "*Non-nil means don't generate error on scrolling past edge of buffer.
|
|
83 This variable applies in PC Selection mode only.
|
|
84 The scroll commands normally generate an error if you try to scroll
|
|
85 past the top or bottom of the buffer. This is annoying when selecting
|
|
86 text with these commands. If you set this variable to non-nil, these
|
|
87 errors are suppressed.")
|
13233
|
88
|
18216
|
89 (defvar pc-select-selection-keys-only nil
|
|
90 "*Non-nil means only bind the basic selection keys when started.
|
|
91 Other keys that emulate pc-behavior will be untouched.
|
|
92 This gives mostly Emacs-like behaviour with only the selection keys enabled.")
|
|
93
|
|
94 (defvar pc-select-meta-moves-sexps nil
|
|
95 "*Non-nil means move sexp-wise with Meta key, otherwise move word-wise.")
|
|
96
|
13233
|
97 ;;;;
|
|
98 ;; misc
|
|
99 ;;;;
|
|
100
|
|
101 (provide 'pc-select)
|
|
102
|
|
103 (defun copy-region-as-kill-nomark (beg end)
|
|
104 "Save the region as if killed; but don't kill it; deactivate mark.
|
|
105 If `interprogram-cut-function' is non-nil, also save the text for a window
|
15907
|
106 system cut and paste.
|
|
107
|
13233
|
108 Deactivating mark is to avoid confusion with delete-selection-mode
|
|
109 and transient-mark-mode."
|
|
110 (interactive "r")
|
|
111 (copy-region-as-kill beg end)
|
|
112 (setq mark-active nil)
|
|
113 (message "Region saved"))
|
|
114
|
18216
|
115 (defun exchange-point-and-mark-nomark ()
|
|
116 (interactive)
|
|
117 (exchange-point-and-mark)
|
|
118 (setq mark-active nil))
|
|
119
|
13233
|
120 ;;;;
|
|
121 ;; non-interactive
|
|
122 ;;;;
|
|
123 (defun ensure-mark()
|
|
124 ;; make sure mark is active
|
|
125 ;; test if it is active, if it isn't, set it and activate it
|
15931
|
126 (or mark-active (set-mark-command nil)))
|
13233
|
127
|
|
128 ;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
129 ;;;;; forward and mark
|
|
130 ;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
131
|
|
132 (defun forward-char-mark (&optional arg)
|
|
133 "Ensure mark is active; move point right ARG characters (left if ARG negative).
|
|
134 On reaching end of buffer, stop and signal error."
|
|
135 (interactive "p")
|
|
136 (ensure-mark)
|
|
137 (forward-char arg))
|
|
138
|
|
139 (defun forward-word-mark (&optional arg)
|
|
140 "Ensure mark is active; move point right ARG words (backward if ARG is negative).
|
|
141 Normally returns t.
|
|
142 If an edge of the buffer is reached, point is left there
|
|
143 and nil is returned."
|
|
144 (interactive "p")
|
|
145 (ensure-mark)
|
|
146 (forward-word arg))
|
|
147
|
15907
|
148 (defun forward-line-mark (&optional arg)
|
|
149 "Ensure mark is active; move cursor vertically down ARG lines."
|
|
150 (interactive "p")
|
|
151 (ensure-mark)
|
|
152 (forward-line arg)
|
|
153 (setq this-command 'forward-line)
|
|
154 )
|
|
155
|
18216
|
156 (defun forward-sexp-mark (&optional arg)
|
|
157 "Ensure mark is active; move forward across one balanced expression (sexp).
|
|
158 With argument, do it that many times. Negative arg -N means
|
|
159 move backward across N balanced expressions."
|
|
160 (interactive "p")
|
|
161 (ensure-mark)
|
|
162 (forward-sexp arg))
|
|
163
|
13233
|
164 (defun forward-paragraph-mark (&optional arg)
|
|
165 "Ensure mark is active; move forward to end of paragraph.
|
15907
|
166 With arg N, do it N times; negative arg -N means move backward N paragraphs.
|
|
167
|
13233
|
168 A line which `paragraph-start' matches either separates paragraphs
|
14382
|
169 \(if `paragraph-separate' matches it also) or is the first line of a paragraph.
|
13233
|
170 A paragraph end is the beginning of a line which is not part of the paragraph
|
|
171 to which the end of the previous line belongs, or the end of the buffer."
|
|
172 (interactive "p")
|
|
173 (ensure-mark)
|
|
174 (forward-paragraph arg))
|
15907
|
175
|
13233
|
176 (defun next-line-mark (&optional arg)
|
|
177 "Ensure mark is active; move cursor vertically down ARG lines.
|
|
178 If there is no character in the target line exactly under the current column,
|
|
179 the cursor is positioned after the character in that line which spans this
|
|
180 column, or at the end of the line if it is not long enough.
|
|
181 If there is no line in the buffer after this one, behavior depends on the
|
|
182 value of `next-line-add-newlines'. If non-nil, it inserts a newline character
|
|
183 to create a line, and moves the cursor to that line. Otherwise it moves the
|
|
184 cursor to the end of the buffer \(if already at the end of the buffer, an error
|
15907
|
185 is signaled).
|
|
186
|
13233
|
187 The command C-x C-n can be used to create
|
|
188 a semipermanent goal column to which this command always moves.
|
|
189 Then it does not try to move vertically. This goal column is stored
|
|
190 in `goal-column', which is nil when there is none."
|
|
191 (interactive "p")
|
|
192 (ensure-mark)
|
14382
|
193 (next-line arg)
|
|
194 (setq this-command 'next-line))
|
13233
|
195
|
|
196 (defun end-of-line-mark (&optional arg)
|
|
197 "Ensure mark is active; move point to end of current line.
|
|
198 With argument ARG not nil or 1, move forward ARG - 1 lines first.
|
|
199 If scan reaches end of buffer, stop there without error."
|
|
200 (interactive "p")
|
|
201 (ensure-mark)
|
14382
|
202 (end-of-line arg)
|
|
203 (setq this-command 'end-of-line))
|
13233
|
204
|
15907
|
205 (defun backward-line-mark (&optional arg)
|
|
206 "Ensure mark is active; move cursor vertically up ARG lines."
|
|
207 (interactive "p")
|
|
208 (ensure-mark)
|
|
209 (if (null arg)
|
|
210 (setq arg 1))
|
|
211 (forward-line (- arg))
|
|
212 (setq this-command 'forward-line)
|
|
213 )
|
|
214
|
13233
|
215 (defun scroll-down-mark (&optional arg)
|
|
216 "Ensure mark is active; scroll down ARG lines; or near full screen if no ARG.
|
|
217 A near full screen is `next-screen-context-lines' less than a full screen.
|
|
218 Negative ARG means scroll upward.
|
|
219 When calling from a program, supply a number as argument or nil."
|
|
220 (interactive "P")
|
|
221 (ensure-mark)
|
15931
|
222 (cond (pc-select-override-scroll-error
|
|
223 (condition-case nil (scroll-down arg)
|
|
224 (beginning-of-buffer (goto-char (point-min)))))
|
|
225 (t (scroll-down arg))))
|
13233
|
226
|
|
227 (defun end-of-buffer-mark (&optional arg)
|
|
228 "Ensure mark is active; move point to the end of the buffer.
|
15907
|
229 With arg N, put point N/10 of the way from the end.
|
|
230
|
13233
|
231 If the buffer is narrowed, this command uses the beginning and size
|
15907
|
232 of the accessible part of the buffer.
|
|
233
|
13233
|
234 Don't use this command in Lisp programs!
|
|
235 \(goto-char \(point-max)) is faster and avoids clobbering the mark."
|
|
236 (interactive "P")
|
|
237 (ensure-mark)
|
|
238 (let ((size (- (point-max) (point-min))))
|
|
239 (goto-char (if arg
|
|
240 (- (point-max)
|
|
241 (if (> size 10000)
|
|
242 ;; Avoid overflow for large buffer sizes!
|
|
243 (* (prefix-numeric-value arg)
|
|
244 (/ size 10))
|
|
245 (/ (* size (prefix-numeric-value arg)) 10)))
|
|
246 (point-max))))
|
|
247 ;; If we went to a place in the middle of the buffer,
|
|
248 ;; adjust it to the beginning of a line.
|
|
249 (if arg (forward-line 1)
|
|
250 ;; If the end of the buffer is not already on the screen,
|
|
251 ;; then scroll specially to put it near, but not at, the bottom.
|
|
252 (if (let ((old-point (point)))
|
|
253 (save-excursion
|
|
254 (goto-char (window-start))
|
|
255 (vertical-motion (window-height))
|
|
256 (< (point) old-point)))
|
|
257 (progn
|
|
258 (overlay-recenter (point))
|
|
259 (recenter -3)))))
|
|
260
|
|
261 ;;;;;;;;;
|
|
262 ;;;;; no mark
|
|
263 ;;;;;;;;;
|
|
264
|
|
265 (defun forward-char-nomark (&optional arg)
|
|
266 "Deactivate mark; move point right ARG characters \(left if ARG negative).
|
|
267 On reaching end of buffer, stop and signal error."
|
|
268 (interactive "p")
|
|
269 (setq mark-active nil)
|
|
270 (forward-char arg))
|
|
271
|
|
272 (defun forward-word-nomark (&optional arg)
|
|
273 "Deactivate mark; move point right ARG words \(backward if ARG is negative).
|
|
274 Normally returns t.
|
|
275 If an edge of the buffer is reached, point is left there
|
|
276 and nil is returned."
|
|
277 (interactive "p")
|
|
278 (setq mark-active nil)
|
|
279 (forward-word arg))
|
|
280
|
15907
|
281 (defun forward-line-nomark (&optional arg)
|
|
282 "Deactivate mark; move cursor vertically down ARG lines."
|
|
283 (interactive "p")
|
|
284 (setq mark-active nil)
|
|
285 (forward-line arg)
|
|
286 (setq this-command 'forward-line)
|
|
287 )
|
|
288
|
18216
|
289 (defun forward-sexp-nomark (&optional arg)
|
|
290 "Deactivate mark; move forward across one balanced expression (sexp).
|
|
291 With argument, do it that many times. Negative arg -N means
|
|
292 move backward across N balanced expressions."
|
|
293 (interactive "p")
|
|
294 (setq mark-active nil)
|
|
295 (forward-sexp arg))
|
|
296
|
13233
|
297 (defun forward-paragraph-nomark (&optional arg)
|
|
298 "Deactivate mark; move forward to end of paragraph.
|
15907
|
299 With arg N, do it N times; negative arg -N means move backward N paragraphs.
|
|
300
|
13233
|
301 A line which `paragraph-start' matches either separates paragraphs
|
14382
|
302 \(if `paragraph-separate' matches it also) or is the first line of a paragraph.
|
13233
|
303 A paragraph end is the beginning of a line which is not part of the paragraph
|
|
304 to which the end of the previous line belongs, or the end of the buffer."
|
|
305 (interactive "p")
|
|
306 (setq mark-active nil)
|
|
307 (forward-paragraph arg))
|
|
308
|
|
309 (defun next-line-nomark (&optional arg)
|
|
310 "Deactivate mark; move cursor vertically down ARG lines.
|
|
311 If there is no character in the target line exactly under the current column,
|
|
312 the cursor is positioned after the character in that line which spans this
|
|
313 column, or at the end of the line if it is not long enough.
|
|
314 If there is no line in the buffer after this one, behavior depends on the
|
|
315 value of `next-line-add-newlines'. If non-nil, it inserts a newline character
|
|
316 to create a line, and moves the cursor to that line. Otherwise it moves the
|
|
317 cursor to the end of the buffer (if already at the end of the buffer, an error
|
15907
|
318 is signaled).
|
|
319
|
13233
|
320 The command C-x C-n can be used to create
|
|
321 a semipermanent goal column to which this command always moves.
|
|
322 Then it does not try to move vertically. This goal column is stored
|
|
323 in `goal-column', which is nil when there is none."
|
|
324 (interactive "p")
|
|
325 (setq mark-active nil)
|
14382
|
326 (next-line arg)
|
|
327 (setq this-command 'next-line))
|
13233
|
328
|
|
329 (defun end-of-line-nomark (&optional arg)
|
|
330 "Deactivate mark; move point to end of current line.
|
|
331 With argument ARG not nil or 1, move forward ARG - 1 lines first.
|
|
332 If scan reaches end of buffer, stop there without error."
|
|
333 (interactive "p")
|
|
334 (setq mark-active nil)
|
14382
|
335 (end-of-line arg)
|
|
336 (setq this-command 'end-of-line))
|
13233
|
337
|
15907
|
338 (defun backward-line-nomark (&optional arg)
|
|
339 "Deactivate mark; move cursor vertically up ARG lines."
|
|
340 (interactive "p")
|
|
341 (setq mark-active nil)
|
|
342 (if (null arg)
|
|
343 (setq arg 1))
|
|
344 (forward-line (- arg))
|
|
345 (setq this-command 'forward-line)
|
|
346 )
|
|
347
|
13233
|
348 (defun scroll-down-nomark (&optional arg)
|
|
349 "Deactivate mark; scroll down ARG lines; or near full screen if no ARG.
|
|
350 A near full screen is `next-screen-context-lines' less than a full screen.
|
|
351 Negative ARG means scroll upward.
|
|
352 When calling from a program, supply a number as argument or nil."
|
|
353 (interactive "P")
|
|
354 (setq mark-active nil)
|
15931
|
355 (cond (pc-select-override-scroll-error
|
|
356 (condition-case nil (scroll-down arg)
|
|
357 (beginning-of-buffer (goto-char (point-min)))))
|
|
358 (t (scroll-down arg))))
|
13233
|
359
|
|
360 (defun end-of-buffer-nomark (&optional arg)
|
|
361 "Deactivate mark; move point to the end of the buffer.
|
15907
|
362 With arg N, put point N/10 of the way from the end.
|
|
363
|
13233
|
364 If the buffer is narrowed, this command uses the beginning and size
|
15907
|
365 of the accessible part of the buffer.
|
|
366
|
13233
|
367 Don't use this command in Lisp programs!
|
14382
|
368 \(goto-char (point-max)) is faster and avoids clobbering the mark."
|
13233
|
369 (interactive "P")
|
|
370 (setq mark-active nil)
|
|
371 (let ((size (- (point-max) (point-min))))
|
|
372 (goto-char (if arg
|
|
373 (- (point-max)
|
|
374 (if (> size 10000)
|
|
375 ;; Avoid overflow for large buffer sizes!
|
|
376 (* (prefix-numeric-value arg)
|
|
377 (/ size 10))
|
|
378 (/ (* size (prefix-numeric-value arg)) 10)))
|
|
379 (point-max))))
|
|
380 ;; If we went to a place in the middle of the buffer,
|
|
381 ;; adjust it to the beginning of a line.
|
|
382 (if arg (forward-line 1)
|
|
383 ;; If the end of the buffer is not already on the screen,
|
|
384 ;; then scroll specially to put it near, but not at, the bottom.
|
|
385 (if (let ((old-point (point)))
|
|
386 (save-excursion
|
|
387 (goto-char (window-start))
|
|
388 (vertical-motion (window-height))
|
|
389 (< (point) old-point)))
|
|
390 (progn
|
|
391 (overlay-recenter (point))
|
|
392 (recenter -3)))))
|
|
393
|
|
394
|
|
395 ;;;;;;;;;;;;;;;;;;;;
|
|
396 ;;;;;; backwards and mark
|
|
397 ;;;;;;;;;;;;;;;;;;;;
|
|
398
|
|
399 (defun backward-char-mark (&optional arg)
|
|
400 "Ensure mark is active; move point left ARG characters (right if ARG negative).
|
|
401 On attempt to pass beginning or end of buffer, stop and signal error."
|
|
402 (interactive "p")
|
|
403 (ensure-mark)
|
|
404 (backward-char arg))
|
|
405
|
|
406 (defun backward-word-mark (&optional arg)
|
|
407 "Ensure mark is active; move backward until encountering the end of a word.
|
|
408 With argument, do this that many times."
|
|
409 (interactive "p")
|
|
410 (ensure-mark)
|
|
411 (backward-word arg))
|
|
412
|
18216
|
413 (defun backward-sexp-mark (&optional arg)
|
|
414 "Ensure mark is active; move backward across one balanced expression (sexp).
|
|
415 With argument, do it that many times. Negative arg -N means
|
|
416 move forward across N balanced expressions."
|
|
417 (interactive "p")
|
|
418 (ensure-mark)
|
|
419 (backward-sexp arg))
|
|
420
|
13233
|
421 (defun backward-paragraph-mark (&optional arg)
|
|
422 "Ensure mark is active; move backward to start of paragraph.
|
15907
|
423 With arg N, do it N times; negative arg -N means move forward N paragraphs.
|
|
424
|
13233
|
425 A paragraph start is the beginning of a line which is a
|
|
426 `first-line-of-paragraph' or which is ordinary text and follows a
|
|
427 paragraph-separating line; except: if the first real line of a
|
|
428 paragraph is preceded by a blank line, the paragraph starts at that
|
15907
|
429 blank line.
|
|
430
|
13233
|
431 See `forward-paragraph' for more information."
|
|
432 (interactive "p")
|
|
433 (ensure-mark)
|
|
434 (backward-paragraph arg))
|
|
435
|
|
436 (defun previous-line-mark (&optional arg)
|
|
437 "Ensure mark is active; move cursor vertically up ARG lines.
|
|
438 If there is no character in the target line exactly over the current column,
|
|
439 the cursor is positioned after the character in that line which spans this
|
15907
|
440 column, or at the end of the line if it is not long enough.
|
|
441
|
13233
|
442 The command C-x C-n can be used to create
|
|
443 a semipermanent goal column to which this command always moves.
|
15907
|
444 Then it does not try to move vertically.
|
|
445
|
13233
|
446 If you are thinking of using this in a Lisp program, consider using
|
|
447 `forward-line' with a negative argument instead. It is usually easier
|
|
448 to use and more reliable (no dependence on goal column, etc.)."
|
|
449 (interactive "p")
|
|
450 (ensure-mark)
|
14382
|
451 (previous-line arg)
|
|
452 (setq this-command 'previous-line))
|
13233
|
453
|
|
454 (defun beginning-of-line-mark (&optional arg)
|
|
455 "Ensure mark is active; move point to beginning of current line.
|
|
456 With argument ARG not nil or 1, move forward ARG - 1 lines first.
|
|
457 If scan reaches end of buffer, stop there without error."
|
|
458 (interactive "p")
|
|
459 (ensure-mark)
|
|
460 (beginning-of-line arg))
|
|
461
|
|
462
|
|
463 (defun scroll-up-mark (&optional arg)
|
|
464 "Ensure mark is active; scroll upward ARG lines; or near full screen if no ARG.
|
|
465 A near full screen is `next-screen-context-lines' less than a full screen.
|
|
466 Negative ARG means scroll downward.
|
|
467 When calling from a program, supply a number as argument or nil."
|
|
468 (interactive "P")
|
|
469 (ensure-mark)
|
15931
|
470 (cond (pc-select-override-scroll-error
|
|
471 (condition-case nil (scroll-up arg)
|
|
472 (end-of-buffer (goto-char (point-max)))))
|
|
473 (t (scroll-up arg))))
|
13233
|
474
|
|
475 (defun beginning-of-buffer-mark (&optional arg)
|
|
476 "Ensure mark is active; move point to the beginning of the buffer.
|
15907
|
477 With arg N, put point N/10 of the way from the beginning.
|
|
478
|
13233
|
479 If the buffer is narrowed, this command uses the beginning and size
|
15907
|
480 of the accessible part of the buffer.
|
|
481
|
13233
|
482 Don't use this command in Lisp programs!
|
|
483 \(goto-char (p\oint-min)) is faster and avoids clobbering the mark."
|
|
484 (interactive "P")
|
|
485 (ensure-mark)
|
|
486 (let ((size (- (point-max) (point-min))))
|
|
487 (goto-char (if arg
|
|
488 (+ (point-min)
|
|
489 (if (> size 10000)
|
|
490 ;; Avoid overflow for large buffer sizes!
|
|
491 (* (prefix-numeric-value arg)
|
|
492 (/ size 10))
|
|
493 (/ (+ 10 (* size (prefix-numeric-value arg))) 10)))
|
|
494 (point-min))))
|
|
495 (if arg (forward-line 1)))
|
|
496
|
|
497 ;;;;;;;;
|
|
498 ;;; no mark
|
|
499 ;;;;;;;;
|
|
500
|
|
501 (defun backward-char-nomark (&optional arg)
|
|
502 "Deactivate mark; move point left ARG characters (right if ARG negative).
|
|
503 On attempt to pass beginning or end of buffer, stop and signal error."
|
|
504 (interactive "p")
|
|
505 (setq mark-active nil)
|
|
506 (backward-char arg))
|
|
507
|
|
508 (defun backward-word-nomark (&optional arg)
|
|
509 "Deactivate mark; move backward until encountering the end of a word.
|
|
510 With argument, do this that many times."
|
|
511 (interactive "p")
|
|
512 (setq mark-active nil)
|
|
513 (backward-word arg))
|
|
514
|
18216
|
515 (defun backward-sexp-nomark (&optional arg)
|
|
516 "Deactivate mark; move backward across one balanced expression (sexp).
|
|
517 With argument, do it that many times. Negative arg -N means
|
|
518 move forward across N balanced expressions."
|
|
519 (interactive "p")
|
|
520 (setq mark-active nil)
|
|
521 (backward-sexp arg))
|
|
522
|
13233
|
523 (defun backward-paragraph-nomark (&optional arg)
|
|
524 "Deactivate mark; move backward to start of paragraph.
|
15907
|
525 With arg N, do it N times; negative arg -N means move forward N paragraphs.
|
|
526
|
13233
|
527 A paragraph start is the beginning of a line which is a
|
|
528 `first-line-of-paragraph' or which is ordinary text and follows a
|
|
529 paragraph-separating line; except: if the first real line of a
|
|
530 paragraph is preceded by a blank line, the paragraph starts at that
|
15907
|
531 blank line.
|
|
532
|
13233
|
533 See `forward-paragraph' for more information."
|
|
534 (interactive "p")
|
|
535 (setq mark-active nil)
|
|
536 (backward-paragraph arg))
|
|
537
|
|
538 (defun previous-line-nomark (&optional arg)
|
|
539 "Deactivate mark; move cursor vertically up ARG lines.
|
|
540 If there is no character in the target line exactly over the current column,
|
|
541 the cursor is positioned after the character in that line which spans this
|
15907
|
542 column, or at the end of the line if it is not long enough.
|
|
543
|
13233
|
544 The command C-x C-n can be used to create
|
|
545 a semipermanent goal column to which this command always moves.
|
|
546 Then it does not try to move vertically."
|
|
547 (interactive "p")
|
|
548 (setq mark-active nil)
|
14382
|
549 (previous-line arg)
|
|
550 (setq this-command 'previous-line))
|
13233
|
551
|
|
552 (defun beginning-of-line-nomark (&optional arg)
|
|
553 "Deactivate mark; move point to beginning of current line.
|
|
554 With argument ARG not nil or 1, move forward ARG - 1 lines first.
|
|
555 If scan reaches end of buffer, stop there without error."
|
|
556 (interactive "p")
|
|
557 (setq mark-active nil)
|
|
558 (beginning-of-line arg))
|
|
559
|
|
560 (defun scroll-up-nomark (&optional arg)
|
|
561 "Deactivate mark; scroll upward ARG lines; or near full screen if no ARG.
|
|
562 A near full screen is `next-screen-context-lines' less than a full screen.
|
|
563 Negative ARG means scroll downward.
|
|
564 When calling from a program, supply a number as argument or nil."
|
|
565 (interactive "P")
|
|
566 (setq mark-active nil)
|
15931
|
567 (cond (pc-select-override-scroll-error
|
|
568 (condition-case nil (scroll-up arg)
|
|
569 (end-of-buffer (goto-char (point-max)))))
|
|
570 (t (scroll-up arg))))
|
13233
|
571
|
|
572 (defun beginning-of-buffer-nomark (&optional arg)
|
|
573 "Deactivate mark; move point to the beginning of the buffer.
|
15907
|
574 With arg N, put point N/10 of the way from the beginning.
|
|
575
|
13233
|
576 If the buffer is narrowed, this command uses the beginning and size
|
15907
|
577 of the accessible part of the buffer.
|
|
578
|
13233
|
579 Don't use this command in Lisp programs!
|
14382
|
580 \(goto-char (point-min)) is faster and avoids clobbering the mark."
|
13233
|
581 (interactive "P")
|
|
582 (setq mark-active nil)
|
|
583 (let ((size (- (point-max) (point-min))))
|
|
584 (goto-char (if arg
|
|
585 (+ (point-min)
|
|
586 (if (> size 10000)
|
|
587 ;; Avoid overflow for large buffer sizes!
|
|
588 (* (prefix-numeric-value arg)
|
|
589 (/ size 10))
|
|
590 (/ (+ 10 (* size (prefix-numeric-value arg))) 10)))
|
|
591 (point-min))))
|
|
592 (if arg (forward-line 1)))
|
|
593
|
13234
|
594 ;;;###autoload
|
13233
|
595 (defun pc-selection-mode ()
|
15907
|
596 "Change mark behaviour to emulate Motif, MAC or MS-Windows cut and paste style.
|
|
597
|
|
598 This mode enables Delete Selection mode and Transient Mark mode.
|
|
599
|
|
600 The arrow keys (and others) are bound to new functions
|
|
601 which modify the status of the mark.
|
|
602
|
|
603 The ordinary arrow keys disable the mark.
|
|
604 The shift-arrow keys move, leaving the mark behind.
|
|
605
|
|
606 C-LEFT and C-RIGHT move back or forward one word, disabling the mark.
|
|
607 S-C-LEFT and S-C-RIGHT move back or forward one word, leaving the mark behind.
|
|
608
|
18216
|
609 M-LEFT and M-RIGHT move back or forward one word or sexp, disabling the mark.
|
|
610 S-M-LEFT and S-M-RIGHT move back or forward one word or sexp, leaving the mark
|
|
611 behind. To control wether these keys move word-wise or sexp-wise set the
|
|
612 variable pc-select-meta-moves-sexps after loading pc-select.el but before
|
|
613 turning pc-selection-mode on.
|
|
614
|
15907
|
615 C-DOWN and C-UP move back or forward a paragraph, disabling the mark.
|
|
616 S-C-DOWN and S-C-UP move back or forward a paragraph, leaving the mark behind.
|
|
617
|
|
618 HOME moves to beginning of line, disabling the mark.
|
|
619 S-HOME moves to beginning of line, leaving the mark behind.
|
|
620 With Ctrl or Meta, these keys move to beginning of buffer instead.
|
|
621
|
|
622 END moves to end of line, disabling the mark.
|
|
623 S-END moves to end of line, leaving the mark behind.
|
|
624 With Ctrl or Meta, these keys move to end of buffer instead.
|
|
625
|
|
626 PRIOR or PAGE-UP scrolls and disables the mark.
|
|
627 S-PRIOR or S-PAGE-UP scrolls and leaves the mark behind.
|
|
628
|
|
629 S-DELETE kills the region (`kill-region').
|
|
630 S-INSERT yanks text from the kill ring (`yank').
|
|
631 C-INSERT copies the region into the kill ring (`copy-region-as-kill').
|
|
632
|
18216
|
633 In addition, certain other PC bindings are imitated (to avoid this, set
|
|
634 the variable pc-select-selection-keys-only to t after loading pc-select.el
|
|
635 but before calling pc-selection-mode):
|
15907
|
636
|
|
637 F6 other-window
|
|
638 DELETE delete-char
|
|
639 C-DELETE kill-line
|
|
640 M-DELETE kill-word
|
|
641 C-M-DELETE kill-sexp
|
|
642 C-BACKSPACE backward-kill-word
|
|
643 M-BACKSPACE undo"
|
|
644
|
13233
|
645 (interactive)
|
|
646 ;;
|
|
647 ;; keybindings
|
|
648 ;;
|
|
649
|
|
650 ;; This is to avoid confusion with the delete-selection-mode
|
|
651 ;; On simple displays you can't see that a region is active and
|
18216
|
652 ;; will be deleted on the next keypress. IMHO especially for
|
|
653 ;; copy-region-as-kill this is confusing.
|
|
654 ;; The same goes for exchange-point-and-mark
|
13233
|
655 (define-key global-map "\M-w" 'copy-region-as-kill-nomark)
|
18216
|
656 (define-key global-map "\C-x\C-x" 'exchange-point-and-mark-nomark)
|
14040
|
657 ;; The following keybindings are for standard ISO keyboards
|
13233
|
658 ;; as they are used with IBM compatible PCs, IBM RS/6000,
|
|
659 ;; MACs, many X-Stations and probably more
|
|
660 (define-key global-map [S-right] 'forward-char-mark)
|
|
661 (define-key global-map [right] 'forward-char-nomark)
|
|
662 (define-key global-map [C-S-right] 'forward-word-mark)
|
|
663 (define-key global-map [C-right] 'forward-word-nomark)
|
18216
|
664 (define-key global-map [S-left] 'backward-char-mark)
|
|
665 (define-key global-map [left] 'backward-char-nomark)
|
|
666 (define-key global-map [C-S-left] 'backward-word-mark)
|
|
667 (define-key global-map [C-left] 'backward-word-nomark)
|
|
668 (cond (pc-select-meta-moves-sexps
|
|
669 (define-key global-map [M-S-right] 'forward-sexp-mark)
|
|
670 (define-key global-map [M-right] 'forward-sexp-nomark)
|
|
671 (define-key global-map [M-S-left] 'backward-sexp-mark)
|
|
672 (define-key global-map [M-left] 'backward-sexp-nomark))
|
|
673 (t
|
|
674 (define-key global-map [M-S-right] 'forward-word-mark)
|
|
675 (define-key global-map [M-right] 'forward-word-nomark)
|
|
676 (define-key global-map [M-S-left] 'backward-word-mark)
|
|
677 (define-key global-map [M-left] 'backward-word-nomark)))
|
13233
|
678
|
|
679 (define-key global-map [S-down] 'next-line-mark)
|
|
680 (define-key global-map [down] 'next-line-nomark)
|
|
681
|
|
682 (define-key global-map [S-end] 'end-of-line-mark)
|
|
683 (define-key global-map [end] 'end-of-line-nomark)
|
|
684 (global-set-key [S-C-end] 'end-of-buffer-mark)
|
|
685 (global-set-key [C-end] 'end-of-buffer-nomark)
|
14382
|
686 (global-set-key [S-M-end] 'end-of-buffer-mark)
|
|
687 (global-set-key [M-end] 'end-of-buffer-nomark)
|
13233
|
688
|
|
689 (define-key global-map [S-next] 'scroll-up-mark)
|
|
690 (define-key global-map [next] 'scroll-up-nomark)
|
|
691
|
|
692 (define-key global-map [S-up] 'previous-line-mark)
|
|
693 (define-key global-map [up] 'previous-line-nomark)
|
|
694
|
|
695 (define-key global-map [S-home] 'beginning-of-line-mark)
|
|
696 (define-key global-map [home] 'beginning-of-line-nomark)
|
|
697 (global-set-key [S-C-home] 'beginning-of-buffer-mark)
|
|
698 (global-set-key [C-home] 'beginning-of-buffer-nomark)
|
14382
|
699 (global-set-key [S-M-home] 'beginning-of-buffer-mark)
|
|
700 (global-set-key [M-home] 'beginning-of-buffer-nomark)
|
13233
|
701
|
15907
|
702 (define-key global-map [M-S-down] 'forward-line-mark)
|
|
703 (define-key global-map [M-down] 'forward-line-nomark)
|
|
704 (define-key global-map [M-S-up] 'backward-line-mark)
|
|
705 (define-key global-map [M-up] 'backward-line-nomark)
|
|
706
|
18216
|
707 (define-key global-map [S-prior] 'scroll-down-mark)
|
|
708 (define-key global-map [prior] 'scroll-down-nomark)
|
13233
|
709
|
18216
|
710 ;; Next four lines are from Pete Forman.
|
|
711 (global-set-key [C-down] 'forward-paragraph-nomark) ; KNextPara cDn
|
|
712 (global-set-key [C-up] 'backward-paragraph-nomark) ; KPrevPara cUp
|
13233
|
713 (global-set-key [S-C-down] 'forward-paragraph-mark)
|
|
714 (global-set-key [S-C-up] 'backward-paragraph-mark)
|
|
715
|
18216
|
716 (or pc-select-selection-keys-only
|
|
717 (progn
|
|
718 (define-key global-map [S-insert] 'yank)
|
|
719 (define-key global-map [C-insert] 'copy-region-as-kill)
|
|
720 (define-key global-map [S-delete] 'kill-region)
|
|
721
|
|
722 ;; The following bindings are useful on Sun Type 3 keyboards
|
|
723 ;; They implement the Get-Delete-Put (copy-cut-paste)
|
|
724 ;; functions from sunview on the L6, L8 and L10 keys
|
|
725 ;; Sam Steingold <sds@ptc.com> says that f16 is copy and f18 is paste.
|
|
726 (define-key global-map [f16] 'copy-region-as-kill)
|
|
727 (define-key global-map [f18] 'yank)
|
|
728 (define-key global-map [f20] 'kill-region)
|
13233
|
729
|
18216
|
730 ;; The following bindings are from Pete Forman.
|
|
731 (global-set-key [f6] 'other-window) ; KNextPane F6
|
|
732 (global-set-key [delete] 'delete-char) ; KDelete Del
|
|
733 (global-set-key [C-delete] 'kill-line) ; KEraseEndLine cDel
|
|
734 (global-set-key [M-backspace] 'undo) ; KUndo aBS
|
|
735
|
|
736 ;; The following bindings are taken from pc-mode.el
|
|
737 ;; as suggested by RMS.
|
|
738 ;; I only used the ones that are not covered above.
|
|
739 (define-key function-key-map [M-delete] [?\M-d])
|
|
740 (global-set-key [C-M-delete] 'kill-sexp)
|
|
741 (global-set-key [C-backspace] 'backward-kill-word)
|
|
742 ;; Next line proposed by Eli Barzilay
|
|
743 (global-set-key [C-escape] 'electric-buffer-list)))
|
13233
|
744 ;;
|
|
745 ;; setup
|
|
746 ;;
|
18216
|
747 ;; Next line proposed by Eli Barzilay
|
|
748 (setq highlight-nonselected-windows nil)
|
13233
|
749 (setq transient-mark-mode t)
|
|
750 (setq mark-even-if-inactive t)
|
15907
|
751 (delete-selection-mode 1)
|
15931
|
752 )
|
13233
|
753 ;;; pc-select.el ends here
|