Mercurial > emacs
comparison lisp/emulation/pc-select.el @ 86155:39b88001b04b
(pc-select-shifted-mark): New var.
(ensure-mark): Set it.
(maybe-deactivate-mark): New fun.
Use it everywhere instead of (setq mark-active nil)
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Fri, 16 Nov 2007 17:58:30 +0000 |
parents | a55a536ce0db |
children | a54bf760b43d |
comparison
equal
deleted
inserted
replaced
86154:1cdfc94602cb | 86155:39b88001b04b |
---|---|
133 (defvar pc-select-default-key-bindings nil | 133 (defvar pc-select-default-key-bindings nil |
134 "These key bindings always get set by PC Selection mode.") | 134 "These key bindings always get set by PC Selection mode.") |
135 | 135 |
136 (unless pc-select-default-key-bindings | 136 (unless pc-select-default-key-bindings |
137 (let ((lst | 137 (let ((lst |
138 ;; This is to avoid confusion with the delete-selection-mode | 138 ;; This is to avoid confusion with the delete-selection-mode. |
139 ;; On simple displays you cant see that a region is active and | 139 ;; On simple displays you can't see that a region is active and |
140 ;; will be deleted on the next keypress IMHO especially for | 140 ;; will be deleted on the next keypress IMHO especially for |
141 ;; copy-region-as-kill this is confusing. | 141 ;; copy-region-as-kill this is confusing. |
142 ;; The same goes for exchange-point-and-mark | 142 ;; The same goes for exchange-point-and-mark |
143 '(("\M-w" . copy-region-as-kill-nomark) | 143 '(("\M-w" . copy-region-as-kill-nomark) |
144 ("\C-x\C-x" . exchange-point-and-mark-nomark) | 144 ("\C-x\C-x" . exchange-point-and-mark-nomark) |
180 | 180 |
181 ([S-prior] . scroll-down-mark) | 181 ([S-prior] . scroll-down-mark) |
182 ([prior] . scroll-down-nomark) | 182 ([prior] . scroll-down-nomark) |
183 | 183 |
184 ;; Next four lines are from Pete Forman. | 184 ;; Next four lines are from Pete Forman. |
185 ([C-down] . forward-paragraph-nomark) ; KNextPara cDn | 185 ([C-down] . forward-paragraph-nomark) ; KNextPara cDn |
186 ([C-up] . backward-paragraph-nomark) ; KPrevPara cUp | 186 ([C-up] . backward-paragraph-nomark) ; KPrevPara cUp |
187 ([S-C-down] . forward-paragraph-mark) | 187 ([S-C-down] . forward-paragraph-mark) |
188 ([S-C-up] . backward-paragraph-mark)))) | 188 ([S-C-up] . backward-paragraph-mark)))) |
189 | 189 |
190 (setq pc-select-default-key-bindings lst))) | 190 (setq pc-select-default-key-bindings lst))) |
252 "Holds the old mapping of [M-delete] in the `function-key-map'. | 252 "Holds the old mapping of [M-delete] in the `function-key-map'. |
253 This variable holds the value associated with [M-delete] in the | 253 This variable holds the value associated with [M-delete] in the |
254 `function-key-map' before PC Selection mode had changed that | 254 `function-key-map' before PC Selection mode had changed that |
255 association.") | 255 association.") |
256 | 256 |
257 (defvar pc-select-shifted-mark nil | |
258 "Holds whether we ourselves did activate the mark. Only then | |
259 should we deactivate if later on.") | |
260 | |
257 ;;;; | 261 ;;;; |
258 ;; misc | 262 ;; misc |
259 ;;;; | 263 ;;;; |
260 | 264 |
261 (provide 'pc-select) | 265 (provide 'pc-select) |
282 ;; non-interactive | 286 ;; non-interactive |
283 ;;;; | 287 ;;;; |
284 (defun ensure-mark() | 288 (defun ensure-mark() |
285 ;; make sure mark is active | 289 ;; make sure mark is active |
286 ;; test if it is active, if it isn't, set it and activate it | 290 ;; test if it is active, if it isn't, set it and activate it |
287 (or mark-active (set-mark-command nil))) | 291 (or mark-active (set-mark-command nil)) |
292 (setq pc-select-shifted-mark t)) | |
293 | |
294 (defun maybe-deactivate-mark() | |
295 ;; maybe switch off mark (only if *we* switched it on) | |
296 (if pc-select-shifted-mark | |
297 (progn | |
298 (setq mark-active nil) | |
299 (setq pc-select-shifted-mark nil)))) | |
288 | 300 |
289 ;;;;;;;;;;;;;;;;;;;;;;;;;;; | 301 ;;;;;;;;;;;;;;;;;;;;;;;;;;; |
290 ;;;;; forward and mark | 302 ;;;;; forward and mark |
291 ;;;;;;;;;;;;;;;;;;;;;;;;;;; | 303 ;;;;;;;;;;;;;;;;;;;;;;;;;;; |
292 | 304 |
425 | 437 |
426 (defun forward-char-nomark (&optional arg) | 438 (defun forward-char-nomark (&optional arg) |
427 "Deactivate mark; move point right ARG characters \(left if ARG negative). | 439 "Deactivate mark; move point right ARG characters \(left if ARG negative). |
428 On reaching end of buffer, stop and signal error." | 440 On reaching end of buffer, stop and signal error." |
429 (interactive "p") | 441 (interactive "p") |
430 (setq mark-active nil) | 442 (maybe-deactivate-mark) |
431 (forward-char arg)) | 443 (forward-char arg)) |
432 | 444 |
433 (defun forward-word-nomark (&optional arg) | 445 (defun forward-word-nomark (&optional arg) |
434 "Deactivate mark; move point right ARG words \(backward if ARG is negative). | 446 "Deactivate mark; move point right ARG words \(backward if ARG is negative). |
435 Normally returns t. | 447 Normally returns t. |
436 If an edge of the buffer is reached, point is left there | 448 If an edge of the buffer is reached, point is left there |
437 and nil is returned." | 449 and nil is returned." |
438 (interactive "p") | 450 (interactive "p") |
439 (setq mark-active nil) | 451 (maybe-deactivate-mark) |
440 (forward-word arg)) | 452 (forward-word arg)) |
441 | 453 |
442 (defun forward-line-nomark (&optional arg) | 454 (defun forward-line-nomark (&optional arg) |
443 "Deactivate mark; move cursor vertically down ARG lines." | 455 "Deactivate mark; move cursor vertically down ARG lines." |
444 (interactive "p") | 456 (interactive "p") |
445 (setq mark-active nil) | 457 (maybe-deactivate-mark) |
446 (forward-line arg) | 458 (forward-line arg) |
447 (setq this-command 'forward-line) | 459 (setq this-command 'forward-line) |
448 ) | 460 ) |
449 | 461 |
450 (defun forward-sexp-nomark (&optional arg) | 462 (defun forward-sexp-nomark (&optional arg) |
451 "Deactivate mark; move forward across one balanced expression (sexp). | 463 "Deactivate mark; move forward across one balanced expression (sexp). |
452 With argument, do it that many times. Negative arg -N means | 464 With argument, do it that many times. Negative arg -N means |
453 move backward across N balanced expressions." | 465 move backward across N balanced expressions." |
454 (interactive "p") | 466 (interactive "p") |
455 (setq mark-active nil) | 467 (maybe-deactivate-mark) |
456 (forward-sexp arg)) | 468 (forward-sexp arg)) |
457 | 469 |
458 (defun forward-paragraph-nomark (&optional arg) | 470 (defun forward-paragraph-nomark (&optional arg) |
459 "Deactivate mark; move forward to end of paragraph. | 471 "Deactivate mark; move forward to end of paragraph. |
460 With arg N, do it N times; negative arg -N means move backward N paragraphs. | 472 With arg N, do it N times; negative arg -N means move backward N paragraphs. |
462 A line which `paragraph-start' matches either separates paragraphs | 474 A line which `paragraph-start' matches either separates paragraphs |
463 \(if `paragraph-separate' matches it also) or is the first line of a paragraph. | 475 \(if `paragraph-separate' matches it also) or is the first line of a paragraph. |
464 A paragraph end is the beginning of a line which is not part of the paragraph | 476 A paragraph end is the beginning of a line which is not part of the paragraph |
465 to which the end of the previous line belongs, or the end of the buffer." | 477 to which the end of the previous line belongs, or the end of the buffer." |
466 (interactive "p") | 478 (interactive "p") |
467 (setq mark-active nil) | 479 (maybe-deactivate-mark) |
468 (forward-paragraph arg)) | 480 (forward-paragraph arg)) |
469 | 481 |
470 (defun next-line-nomark (&optional arg) | 482 (defun next-line-nomark (&optional arg) |
471 "Deactivate mark; move cursor vertically down ARG lines. | 483 "Deactivate mark; move cursor vertically down ARG lines. |
472 If there is no character in the target line exactly under the current column, | 484 If there is no character in the target line exactly under the current column, |
481 The command \\[set-goal-column] can be used to create | 493 The command \\[set-goal-column] can be used to create |
482 a semipermanent goal column to which this command always moves. | 494 a semipermanent goal column to which this command always moves. |
483 Then it does not try to move vertically. This goal column is stored | 495 Then it does not try to move vertically. This goal column is stored |
484 in `goal-column', which is nil when there is none." | 496 in `goal-column', which is nil when there is none." |
485 (interactive "p") | 497 (interactive "p") |
486 (setq mark-active nil) | 498 (maybe-deactivate-mark) |
487 (with-no-warnings (next-line arg)) | 499 (with-no-warnings (next-line arg)) |
488 (setq this-command 'next-line)) | 500 (setq this-command 'next-line)) |
489 | 501 |
490 (defun end-of-line-nomark (&optional arg) | 502 (defun end-of-line-nomark (&optional arg) |
491 "Deactivate mark; move point to end of current line. | 503 "Deactivate mark; move point to end of current line. |
492 With argument ARG not nil or 1, move forward ARG - 1 lines first. | 504 With argument ARG not nil or 1, move forward ARG - 1 lines first. |
493 If scan reaches end of buffer, stop there without error." | 505 If scan reaches end of buffer, stop there without error." |
494 (interactive "p") | 506 (interactive "p") |
495 (setq mark-active nil) | 507 (maybe-deactivate-mark) |
496 (end-of-line arg) | 508 (end-of-line arg) |
497 (setq this-command 'end-of-line)) | 509 (setq this-command 'end-of-line)) |
498 | 510 |
499 (defun backward-line-nomark (&optional arg) | 511 (defun backward-line-nomark (&optional arg) |
500 "Deactivate mark; move cursor vertically up ARG lines." | 512 "Deactivate mark; move cursor vertically up ARG lines." |
501 (interactive "p") | 513 (interactive "p") |
502 (setq mark-active nil) | 514 (maybe-deactivate-mark) |
503 (if (null arg) | 515 (if (null arg) |
504 (setq arg 1)) | 516 (setq arg 1)) |
505 (forward-line (- arg)) | 517 (forward-line (- arg)) |
506 (setq this-command 'forward-line) | 518 (setq this-command 'forward-line) |
507 ) | 519 ) |
510 "Deactivate mark; scroll down ARG lines; or near full screen if no ARG. | 522 "Deactivate mark; scroll down ARG lines; or near full screen if no ARG. |
511 A near full screen is `next-screen-context-lines' less than a full screen. | 523 A near full screen is `next-screen-context-lines' less than a full screen. |
512 Negative ARG means scroll upward. | 524 Negative ARG means scroll upward. |
513 When calling from a program, supply a number as argument or nil." | 525 When calling from a program, supply a number as argument or nil." |
514 (interactive "P") | 526 (interactive "P") |
515 (setq mark-active nil) | 527 (maybe-deactivate-mark) |
516 (cond (pc-select-override-scroll-error | 528 (cond (pc-select-override-scroll-error |
517 (condition-case nil (scroll-down arg) | 529 (condition-case nil (scroll-down arg) |
518 (beginning-of-buffer (goto-char (point-min))))) | 530 (beginning-of-buffer (goto-char (point-min))))) |
519 (t (scroll-down arg)))) | 531 (t (scroll-down arg)))) |
520 | 532 |
526 of the accessible part of the buffer. | 538 of the accessible part of the buffer. |
527 | 539 |
528 Don't use this command in Lisp programs! | 540 Don't use this command in Lisp programs! |
529 \(goto-char (point-max)) is faster and avoids clobbering the mark." | 541 \(goto-char (point-max)) is faster and avoids clobbering the mark." |
530 (interactive "P") | 542 (interactive "P") |
531 (setq mark-active nil) | 543 (maybe-deactivate-mark) |
532 (let ((size (- (point-max) (point-min)))) | 544 (let ((size (- (point-max) (point-min)))) |
533 (goto-char (if arg | 545 (goto-char (if arg |
534 (- (point-max) | 546 (- (point-max) |
535 (if (> size 10000) | 547 (if (> size 10000) |
536 ;; Avoid overflow for large buffer sizes! | 548 ;; Avoid overflow for large buffer sizes! |
661 | 673 |
662 (defun backward-char-nomark (&optional arg) | 674 (defun backward-char-nomark (&optional arg) |
663 "Deactivate mark; move point left ARG characters (right if ARG negative). | 675 "Deactivate mark; move point left ARG characters (right if ARG negative). |
664 On attempt to pass beginning or end of buffer, stop and signal error." | 676 On attempt to pass beginning or end of buffer, stop and signal error." |
665 (interactive "p") | 677 (interactive "p") |
666 (setq mark-active nil) | 678 (maybe-deactivate-mark) |
667 (backward-char arg)) | 679 (backward-char arg)) |
668 | 680 |
669 (defun backward-word-nomark (&optional arg) | 681 (defun backward-word-nomark (&optional arg) |
670 "Deactivate mark; move backward until encountering the end of a word. | 682 "Deactivate mark; move backward until encountering the end of a word. |
671 With argument, do this that many times." | 683 With argument, do this that many times." |
672 (interactive "p") | 684 (interactive "p") |
673 (setq mark-active nil) | 685 (maybe-deactivate-mark) |
674 (backward-word arg)) | 686 (backward-word arg)) |
675 | 687 |
676 (defun backward-sexp-nomark (&optional arg) | 688 (defun backward-sexp-nomark (&optional arg) |
677 "Deactivate mark; move backward across one balanced expression (sexp). | 689 "Deactivate mark; move backward across one balanced expression (sexp). |
678 With argument, do it that many times. Negative arg -N means | 690 With argument, do it that many times. Negative arg -N means |
679 move forward across N balanced expressions." | 691 move forward across N balanced expressions." |
680 (interactive "p") | 692 (interactive "p") |
681 (setq mark-active nil) | 693 (maybe-deactivate-mark) |
682 (backward-sexp arg)) | 694 (backward-sexp arg)) |
683 | 695 |
684 (defun backward-paragraph-nomark (&optional arg) | 696 (defun backward-paragraph-nomark (&optional arg) |
685 "Deactivate mark; move backward to start of paragraph. | 697 "Deactivate mark; move backward to start of paragraph. |
686 With arg N, do it N times; negative arg -N means move forward N paragraphs. | 698 With arg N, do it N times; negative arg -N means move forward N paragraphs. |
691 paragraph is preceded by a blank line, the paragraph starts at that | 703 paragraph is preceded by a blank line, the paragraph starts at that |
692 blank line. | 704 blank line. |
693 | 705 |
694 See `forward-paragraph' for more information." | 706 See `forward-paragraph' for more information." |
695 (interactive "p") | 707 (interactive "p") |
696 (setq mark-active nil) | 708 (maybe-deactivate-mark) |
697 (backward-paragraph arg)) | 709 (backward-paragraph arg)) |
698 | 710 |
699 (defun previous-line-nomark (&optional arg) | 711 (defun previous-line-nomark (&optional arg) |
700 "Deactivate mark; move cursor vertically up ARG lines. | 712 "Deactivate mark; move cursor vertically up ARG lines. |
701 If there is no character in the target line exactly over the current column, | 713 If there is no character in the target line exactly over the current column, |
704 | 716 |
705 The command \\[set-goal-column] can be used to create | 717 The command \\[set-goal-column] can be used to create |
706 a semipermanent goal column to which this command always moves. | 718 a semipermanent goal column to which this command always moves. |
707 Then it does not try to move vertically." | 719 Then it does not try to move vertically." |
708 (interactive "p") | 720 (interactive "p") |
709 (setq mark-active nil) | 721 (maybe-deactivate-mark) |
710 (with-no-warnings (previous-line arg)) | 722 (with-no-warnings (previous-line arg)) |
711 (setq this-command 'previous-line)) | 723 (setq this-command 'previous-line)) |
712 | 724 |
713 (defun beginning-of-line-nomark (&optional arg) | 725 (defun beginning-of-line-nomark (&optional arg) |
714 "Deactivate mark; move point to beginning of current line. | 726 "Deactivate mark; move point to beginning of current line. |
715 With argument ARG not nil or 1, move forward ARG - 1 lines first. | 727 With argument ARG not nil or 1, move forward ARG - 1 lines first. |
716 If scan reaches end of buffer, stop there without error." | 728 If scan reaches end of buffer, stop there without error." |
717 (interactive "p") | 729 (interactive "p") |
718 (setq mark-active nil) | 730 (maybe-deactivate-mark) |
719 (beginning-of-line arg)) | 731 (beginning-of-line arg)) |
720 | 732 |
721 (defun scroll-up-nomark (&optional arg) | 733 (defun scroll-up-nomark (&optional arg) |
722 "Deactivate mark; scroll upward ARG lines; or near full screen if no ARG. | 734 "Deactivate mark; scroll upward ARG lines; or near full screen if no ARG. |
723 A near full screen is `next-screen-context-lines' less than a full screen. | 735 A near full screen is `next-screen-context-lines' less than a full screen. |
724 Negative ARG means scroll downward. | 736 Negative ARG means scroll downward. |
725 When calling from a program, supply a number as argument or nil." | 737 When calling from a program, supply a number as argument or nil." |
726 (interactive "P") | 738 (interactive "P") |
727 (setq mark-active nil) | 739 (maybe-deactivate-mark) |
728 (cond (pc-select-override-scroll-error | 740 (cond (pc-select-override-scroll-error |
729 (condition-case nil (scroll-up arg) | 741 (condition-case nil (scroll-up arg) |
730 (end-of-buffer (goto-char (point-max))))) | 742 (end-of-buffer (goto-char (point-max))))) |
731 (t (scroll-up arg)))) | 743 (t (scroll-up arg)))) |
732 | 744 |
738 of the accessible part of the buffer. | 750 of the accessible part of the buffer. |
739 | 751 |
740 Don't use this command in Lisp programs! | 752 Don't use this command in Lisp programs! |
741 \(goto-char (point-min)) is faster and avoids clobbering the mark." | 753 \(goto-char (point-min)) is faster and avoids clobbering the mark." |
742 (interactive "P") | 754 (interactive "P") |
743 (setq mark-active nil) | 755 (maybe-deactivate-mark) |
744 (let ((size (- (point-max) (point-min)))) | 756 (let ((size (- (point-max) (point-min)))) |
745 (goto-char (if arg | 757 (goto-char (if arg |
746 (+ (point-min) | 758 (+ (point-min) |
747 (if (> size 10000) | 759 (if (> size 10000) |
748 ;; Avoid overflow for large buffer sizes! | 760 ;; Avoid overflow for large buffer sizes! |
982 :initialize 'custom-initialize-default | 994 :initialize 'custom-initialize-default |
983 :type 'boolean | 995 :type 'boolean |
984 :group 'pc-select | 996 :group 'pc-select |
985 :require 'pc-select) | 997 :require 'pc-select) |
986 | 998 |
987 ;;; arch-tag: 10697b70-ae07-4f3e-ad23-7814a3f418c2 | 999 ;; arch-tag: 10697b70-ae07-4f3e-ad23-7814a3f418c2 |
988 ;;; pc-select.el ends here | 1000 ;;; pc-select.el ends here |