diff options
| author | Chong Yidong | 2008-04-02 20:16:10 +0000 |
|---|---|---|
| committer | Chong Yidong | 2008-04-02 20:16:10 +0000 |
| commit | 109cfe4e37961ae82c00aa0cc56a7fafff3b832a (patch) | |
| tree | e3bf4b63f06febefe113dade0124245f53fd135d | |
| parent | e09655973f544d4a7a3e3ed337ac5e8d167ae5fd (diff) | |
| download | emacs-109cfe4e37961ae82c00aa0cc56a7fafff3b832a.tar.gz emacs-109cfe4e37961ae82c00aa0cc56a7fafff3b832a.zip | |
(deactivate-mark): When the mark is temporarily
active, restore the original value of transient-mark-mode.
(set-mark-command): First deactivate the mark if was temporarily
active.
(exchange-point-and-mark): Reactivate the mark if it was
temporarily active.
(handle-shift-selection): New fun.
(transient-mark-mode): Move var documentation here from buffer.c.
(next-line, previous-line, backward-word, move-end-of-line)
(move-beginning-of-line, forward-to-indentation)
(backward-to-indentation, back-to-indentation)
(beginning-of-buffer, end-of-buffer): Add ^ interactive spec.
| -rw-r--r-- | lisp/simple.el | 106 |
1 files changed, 81 insertions, 25 deletions
diff --git a/lisp/simple.el b/lisp/simple.el index f7abd7260a6..4f2221ee94e 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -686,19 +686,19 @@ useful for editing binary files." | |||
| 686 | 686 | ||
| 687 | (defun forward-to-indentation (&optional arg) | 687 | (defun forward-to-indentation (&optional arg) |
| 688 | "Move forward ARG lines and position at first nonblank character." | 688 | "Move forward ARG lines and position at first nonblank character." |
| 689 | (interactive "p") | 689 | (interactive "^p") |
| 690 | (forward-line (or arg 1)) | 690 | (forward-line (or arg 1)) |
| 691 | (skip-chars-forward " \t")) | 691 | (skip-chars-forward " \t")) |
| 692 | 692 | ||
| 693 | (defun backward-to-indentation (&optional arg) | 693 | (defun backward-to-indentation (&optional arg) |
| 694 | "Move backward ARG lines and position at first nonblank character." | 694 | "Move backward ARG lines and position at first nonblank character." |
| 695 | (interactive "p") | 695 | (interactive "^p") |
| 696 | (forward-line (- (or arg 1))) | 696 | (forward-line (- (or arg 1))) |
| 697 | (skip-chars-forward " \t")) | 697 | (skip-chars-forward " \t")) |
| 698 | 698 | ||
| 699 | (defun back-to-indentation () | 699 | (defun back-to-indentation () |
| 700 | "Move point to the first non-whitespace character on this line." | 700 | "Move point to the first non-whitespace character on this line." |
| 701 | (interactive) | 701 | (interactive "^") |
| 702 | (beginning-of-line 1) | 702 | (beginning-of-line 1) |
| 703 | (skip-syntax-forward " " (line-end-position)) | 703 | (skip-syntax-forward " " (line-end-position)) |
| 704 | ;; Move back over chars that have whitespace syntax but have the p flag. | 704 | ;; Move back over chars that have whitespace syntax but have the p flag. |
| @@ -757,7 +757,7 @@ of the accessible part of the buffer. | |||
| 757 | 757 | ||
| 758 | Don't use this command in Lisp programs! | 758 | Don't use this command in Lisp programs! |
| 759 | \(goto-char (point-min)) is faster and avoids clobbering the mark." | 759 | \(goto-char (point-min)) is faster and avoids clobbering the mark." |
| 760 | (interactive "P") | 760 | (interactive "^P") |
| 761 | (or (consp arg) | 761 | (or (consp arg) |
| 762 | (and transient-mark-mode mark-active) | 762 | (and transient-mark-mode mark-active) |
| 763 | (push-mark)) | 763 | (push-mark)) |
| @@ -782,7 +782,7 @@ of the accessible part of the buffer. | |||
| 782 | 782 | ||
| 783 | Don't use this command in Lisp programs! | 783 | Don't use this command in Lisp programs! |
| 784 | \(goto-char (point-max)) is faster and avoids clobbering the mark." | 784 | \(goto-char (point-max)) is faster and avoids clobbering the mark." |
| 785 | (interactive "P") | 785 | (interactive "^P") |
| 786 | (or (consp arg) | 786 | (or (consp arg) |
| 787 | (and transient-mark-mode mark-active) | 787 | (and transient-mark-mode mark-active) |
| 788 | (push-mark)) | 788 | (push-mark)) |
| @@ -3379,12 +3379,15 @@ a mistake; see the documentation of `set-mark'." | |||
| 3379 | "Deactivate the mark by setting `mark-active' to nil. | 3379 | "Deactivate the mark by setting `mark-active' to nil. |
| 3380 | \(That makes a difference only in Transient Mark mode.) | 3380 | \(That makes a difference only in Transient Mark mode.) |
| 3381 | Also runs the hook `deactivate-mark-hook'." | 3381 | Also runs the hook `deactivate-mark-hook'." |
| 3382 | (cond | 3382 | (when transient-mark-mode |
| 3383 | ((eq transient-mark-mode 'lambda) | 3383 | (if (or (eq transient-mark-mode 'lambda) |
| 3384 | (setq transient-mark-mode nil)) | 3384 | (and (eq (car-safe transient-mark-mode) 'only) |
| 3385 | (transient-mark-mode | 3385 | (null (cdr transient-mark-mode)))) |
| 3386 | (setq mark-active nil) | 3386 | (setq transient-mark-mode nil) |
| 3387 | (run-hooks 'deactivate-mark-hook)))) | 3387 | (if (eq (car-safe transient-mark-mode) 'only) |
| 3388 | (setq transient-mark-mode (cdr transient-mark-mode))) | ||
| 3389 | (setq mark-active nil) | ||
| 3390 | (run-hooks 'deactivate-mark-hook)))) | ||
| 3388 | 3391 | ||
| 3389 | (defun activate-mark () | 3392 | (defun activate-mark () |
| 3390 | "Activate the mark." | 3393 | "Activate the mark." |
| @@ -3545,8 +3548,10 @@ argument, unconditionally set mark where point is, even if | |||
| 3545 | Novice Emacs Lisp programmers often try to use the mark for the wrong | 3548 | Novice Emacs Lisp programmers often try to use the mark for the wrong |
| 3546 | purposes. See the documentation of `set-mark' for more information." | 3549 | purposes. See the documentation of `set-mark' for more information." |
| 3547 | (interactive "P") | 3550 | (interactive "P") |
| 3548 | (if (eq transient-mark-mode 'lambda) | 3551 | (cond ((eq transient-mark-mode 'lambda) |
| 3549 | (setq transient-mark-mode nil)) | 3552 | (setq transient-mark-mode nil)) |
| 3553 | ((eq (car-safe transient-mark-mode) 'only) | ||
| 3554 | (deactivate-mark))) | ||
| 3550 | (cond | 3555 | (cond |
| 3551 | ((and (consp arg) (> (prefix-numeric-value arg) 4)) | 3556 | ((and (consp arg) (> (prefix-numeric-value arg) 4)) |
| 3552 | (push-mark-command nil)) | 3557 | (push-mark-command nil)) |
| @@ -3624,20 +3629,50 @@ Does not set point. Does nothing if mark ring is empty." | |||
| 3624 | "Put the mark where point is now, and point where the mark is now. | 3629 | "Put the mark where point is now, and point where the mark is now. |
| 3625 | This command works even when the mark is not active, | 3630 | This command works even when the mark is not active, |
| 3626 | and it reactivates the mark. | 3631 | and it reactivates the mark. |
| 3627 | With prefix arg, `transient-mark-mode' is enabled temporarily." | 3632 | |
| 3633 | If Transient Mark mode is on, a prefix arg deactivates the mark | ||
| 3634 | if it is active, and otherwise avoids reactivating it. If | ||
| 3635 | Transient Mark mode is off, a prefix arg enables Transient Mark | ||
| 3636 | mode temporarily." | ||
| 3628 | (interactive "P") | 3637 | (interactive "P") |
| 3629 | (deactivate-mark) | 3638 | (let ((omark (mark t)) |
| 3630 | (let ((omark (mark t))) | 3639 | (temp-highlight (eq (car-safe transient-mark-mode) 'only))) |
| 3631 | (if (null omark) | 3640 | (if (null omark) |
| 3632 | (error "No mark set in this buffer")) | 3641 | (error "No mark set in this buffer")) |
| 3642 | (deactivate-mark) | ||
| 3633 | (set-mark (point)) | 3643 | (set-mark (point)) |
| 3634 | (goto-char omark) | 3644 | (goto-char omark) |
| 3635 | (if (or (and arg (region-active-p)) ; (xor arg (not (region-active-p))) | 3645 | (cond (temp-highlight |
| 3636 | (not (or arg (region-active-p)))) | 3646 | (setq transient-mark-mode (cons 'only transient-mark-mode))) |
| 3637 | (deactivate-mark) | 3647 | ((or (and arg (region-active-p)) ; (xor arg (not (region-active-p))) |
| 3638 | (activate-mark)) | 3648 | (not (or arg (region-active-p)))) |
| 3649 | (deactivate-mark)) | ||
| 3650 | (t (activate-mark))) | ||
| 3639 | nil)) | 3651 | nil)) |
| 3640 | 3652 | ||
| 3653 | (defun handle-shift-selection () | ||
| 3654 | "Check for shift translation, and operate on the mark accordingly. | ||
| 3655 | This is called whenever a command with a `^' character in its | ||
| 3656 | `interactive' spec is invoked while `shift-select-mode' is | ||
| 3657 | non-nil. | ||
| 3658 | |||
| 3659 | If the command was invoked through shift-translation, set the | ||
| 3660 | mark and activate the region temporarily, unless it was already | ||
| 3661 | set in this way. If the command was invoked without | ||
| 3662 | shift-translation and a region is temporarily active, deactivate | ||
| 3663 | the mark." | ||
| 3664 | (cond (this-command-keys-shift-translated | ||
| 3665 | (unless (and mark-active | ||
| 3666 | (eq (car-safe transient-mark-mode) 'only)) | ||
| 3667 | (setq transient-mark-mode | ||
| 3668 | (cons 'only | ||
| 3669 | (unless (eq transient-mark-mode 'lambda) | ||
| 3670 | transient-mark-mode))) | ||
| 3671 | (push-mark nil nil t))) | ||
| 3672 | ((eq (car-safe transient-mark-mode) 'only) | ||
| 3673 | (setq transient-mark-mode (cdr transient-mark-mode)) | ||
| 3674 | (deactivate-mark)))) | ||
| 3675 | |||
| 3641 | (define-minor-mode transient-mark-mode | 3676 | (define-minor-mode transient-mark-mode |
| 3642 | "Toggle Transient Mark mode. | 3677 | "Toggle Transient Mark mode. |
| 3643 | With arg, turn Transient Mark mode on if arg is positive, off otherwise. | 3678 | With arg, turn Transient Mark mode on if arg is positive, off otherwise. |
| @@ -3663,6 +3698,27 @@ commands which are sensitive to the Transient Mark mode." | |||
| 3663 | :init-value (not noninteractive) | 3698 | :init-value (not noninteractive) |
| 3664 | :group 'editing-basics) | 3699 | :group 'editing-basics) |
| 3665 | 3700 | ||
| 3701 | ;; The variable transient-mark-mode is ugly: it can take on special | ||
| 3702 | ;; values. Document these here. | ||
| 3703 | (defvar transient-mark-mode t | ||
| 3704 | "*Non-nil if Transient Mark mode is enabled. | ||
| 3705 | See the command `transient-mark-mode' for a description of this minor mode. | ||
| 3706 | |||
| 3707 | Non-nil also enables highlighting of the region whenever the mark is active. | ||
| 3708 | The variable `highlight-nonselected-windows' controls whether to highlight | ||
| 3709 | all windows or just the selected window. | ||
| 3710 | |||
| 3711 | If the value is `lambda', that enables Transient Mark mode | ||
| 3712 | temporarily. After any subsequent action that would normally | ||
| 3713 | deactivate the mark (such as buffer modification), Transient Mark mode | ||
| 3714 | is turned off. | ||
| 3715 | |||
| 3716 | If the value is (only . OLDVAL), that enables Transient Mark mode | ||
| 3717 | temporarily. After any subsequent point motion command that is not | ||
| 3718 | shift-translated, or any other action that would normally deactivate | ||
| 3719 | the mark (such as buffer modification), the value of | ||
| 3720 | `transient-mark-mode' is set to OLDVAL.") | ||
| 3721 | |||
| 3666 | (defvar widen-automatically t | 3722 | (defvar widen-automatically t |
| 3667 | "Non-nil means it is ok for commands to call `widen' when they want to. | 3723 | "Non-nil means it is ok for commands to call `widen' when they want to. |
| 3668 | Some commands will do this in order to go to positions outside | 3724 | Some commands will do this in order to go to positions outside |
| @@ -3720,7 +3776,7 @@ when there is no goal column. | |||
| 3720 | If you are thinking of using this in a Lisp program, consider | 3776 | If you are thinking of using this in a Lisp program, consider |
| 3721 | using `forward-line' instead. It is usually easier to use | 3777 | using `forward-line' instead. It is usually easier to use |
| 3722 | and more reliable (no dependence on goal column, etc.)." | 3778 | and more reliable (no dependence on goal column, etc.)." |
| 3723 | (interactive "p\np") | 3779 | (interactive "^p\np") |
| 3724 | (or arg (setq arg 1)) | 3780 | (or arg (setq arg 1)) |
| 3725 | (if (and next-line-add-newlines (= arg 1)) | 3781 | (if (and next-line-add-newlines (= arg 1)) |
| 3726 | (if (save-excursion (end-of-line) (eobp)) | 3782 | (if (save-excursion (end-of-line) (eobp)) |
| @@ -3753,7 +3809,7 @@ when there is no goal column. | |||
| 3753 | If you are thinking of using this in a Lisp program, consider using | 3809 | If you are thinking of using this in a Lisp program, consider using |
| 3754 | `forward-line' with a negative argument instead. It is usually easier | 3810 | `forward-line' with a negative argument instead. It is usually easier |
| 3755 | to use and more reliable (no dependence on goal column, etc.)." | 3811 | to use and more reliable (no dependence on goal column, etc.)." |
| 3756 | (interactive "p\np") | 3812 | (interactive "^p\np") |
| 3757 | (or arg (setq arg 1)) | 3813 | (or arg (setq arg 1)) |
| 3758 | (if (interactive-p) | 3814 | (if (interactive-p) |
| 3759 | (condition-case nil | 3815 | (condition-case nil |
| @@ -4111,7 +4167,7 @@ which are part of the text that the image rests on.) | |||
| 4111 | With argument ARG not nil or 1, move forward ARG - 1 lines first. | 4167 | With argument ARG not nil or 1, move forward ARG - 1 lines first. |
| 4112 | If point reaches the beginning or end of buffer, it stops there. | 4168 | If point reaches the beginning or end of buffer, it stops there. |
| 4113 | To ignore intangibility, bind `inhibit-point-motion-hooks' to t." | 4169 | To ignore intangibility, bind `inhibit-point-motion-hooks' to t." |
| 4114 | (interactive "p") | 4170 | (interactive "^p") |
| 4115 | (or arg (setq arg 1)) | 4171 | (or arg (setq arg 1)) |
| 4116 | (let (done) | 4172 | (let (done) |
| 4117 | (while (not done) | 4173 | (while (not done) |
| @@ -4146,7 +4202,7 @@ which are part of the text that the image rests on.) | |||
| 4146 | With argument ARG not nil or 1, move forward ARG - 1 lines first. | 4202 | With argument ARG not nil or 1, move forward ARG - 1 lines first. |
| 4147 | If point reaches the beginning or end of buffer, it stops there. | 4203 | If point reaches the beginning or end of buffer, it stops there. |
| 4148 | To ignore intangibility, bind `inhibit-point-motion-hooks' to t." | 4204 | To ignore intangibility, bind `inhibit-point-motion-hooks' to t." |
| 4149 | (interactive "p") | 4205 | (interactive "^p") |
| 4150 | (or arg (setq arg 1)) | 4206 | (or arg (setq arg 1)) |
| 4151 | 4207 | ||
| 4152 | (let ((orig (point)) | 4208 | (let ((orig (point)) |
| @@ -4376,7 +4432,7 @@ With argument 0, interchanges line point is in with line mark is in." | |||
| 4376 | (defun backward-word (&optional arg) | 4432 | (defun backward-word (&optional arg) |
| 4377 | "Move backward until encountering the beginning of a word. | 4433 | "Move backward until encountering the beginning of a word. |
| 4378 | With argument, do this that many times." | 4434 | With argument, do this that many times." |
| 4379 | (interactive "p") | 4435 | (interactive "^p") |
| 4380 | (forward-word (- (or arg 1)))) | 4436 | (forward-word (- (or arg 1)))) |
| 4381 | 4437 | ||
| 4382 | (defun mark-word (&optional arg allow-extend) | 4438 | (defun mark-word (&optional arg allow-extend) |