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