(defun forward-to-indentation (&optional arg)
"Move forward ARG lines and position at first nonblank character."
- (interactive "p")
+ (interactive "^p")
(forward-line (or arg 1))
(skip-chars-forward " \t"))
(defun backward-to-indentation (&optional arg)
"Move backward ARG lines and position at first nonblank character."
- (interactive "p")
+ (interactive "^p")
(forward-line (- (or arg 1)))
(skip-chars-forward " \t"))
(defun back-to-indentation ()
"Move point to the first non-whitespace character on this line."
- (interactive)
+ (interactive "^")
(beginning-of-line 1)
(skip-syntax-forward " " (line-end-position))
;; Move back over chars that have whitespace syntax but have the p flag.
Don't use this command in Lisp programs!
\(goto-char (point-min)) is faster and avoids clobbering the mark."
- (interactive "P")
+ (interactive "^P")
(or (consp arg)
(and transient-mark-mode mark-active)
(push-mark))
Don't use this command in Lisp programs!
\(goto-char (point-max)) is faster and avoids clobbering the mark."
- (interactive "P")
+ (interactive "^P")
(or (consp arg)
(and transient-mark-mode mark-active)
(push-mark))
"Deactivate the mark by setting `mark-active' to nil.
\(That makes a difference only in Transient Mark mode.)
Also runs the hook `deactivate-mark-hook'."
- (cond
- ((eq transient-mark-mode 'lambda)
- (setq transient-mark-mode nil))
- (transient-mark-mode
- (setq mark-active nil)
- (run-hooks 'deactivate-mark-hook))))
+ (when transient-mark-mode
+ (if (or (eq transient-mark-mode 'lambda)
+ (and (eq (car-safe transient-mark-mode) 'only)
+ (null (cdr transient-mark-mode))))
+ (setq transient-mark-mode nil)
+ (if (eq (car-safe transient-mark-mode) 'only)
+ (setq transient-mark-mode (cdr transient-mark-mode)))
+ (setq mark-active nil)
+ (run-hooks 'deactivate-mark-hook))))
(defun activate-mark ()
"Activate the mark."
Novice Emacs Lisp programmers often try to use the mark for the wrong
purposes. See the documentation of `set-mark' for more information."
(interactive "P")
- (if (eq transient-mark-mode 'lambda)
- (setq transient-mark-mode nil))
+ (cond ((eq transient-mark-mode 'lambda)
+ (setq transient-mark-mode nil))
+ ((eq (car-safe transient-mark-mode) 'only)
+ (deactivate-mark)))
(cond
((and (consp arg) (> (prefix-numeric-value arg) 4))
(push-mark-command nil))
"Put the mark where point is now, and point where the mark is now.
This command works even when the mark is not active,
and it reactivates the mark.
-With prefix arg, `transient-mark-mode' is enabled temporarily."
+
+If Transient Mark mode is on, a prefix arg deactivates the mark
+if it is active, and otherwise avoids reactivating it. If
+Transient Mark mode is off, a prefix arg enables Transient Mark
+mode temporarily."
(interactive "P")
- (deactivate-mark)
- (let ((omark (mark t)))
+ (let ((omark (mark t))
+ (temp-highlight (eq (car-safe transient-mark-mode) 'only)))
(if (null omark)
(error "No mark set in this buffer"))
+ (deactivate-mark)
(set-mark (point))
(goto-char omark)
- (if (or (and arg (region-active-p)) ; (xor arg (not (region-active-p)))
- (not (or arg (region-active-p))))
- (deactivate-mark)
- (activate-mark))
+ (cond (temp-highlight
+ (setq transient-mark-mode (cons 'only transient-mark-mode)))
+ ((or (and arg (region-active-p)) ; (xor arg (not (region-active-p)))
+ (not (or arg (region-active-p))))
+ (deactivate-mark))
+ (t (activate-mark)))
nil))
+(defun handle-shift-selection ()
+ "Check for shift translation, and operate on the mark accordingly.
+This is called whenever a command with a `^' character in its
+`interactive' spec is invoked while `shift-select-mode' is
+non-nil.
+
+If the command was invoked through shift-translation, set the
+mark and activate the region temporarily, unless it was already
+set in this way. If the command was invoked without
+shift-translation and a region is temporarily active, deactivate
+the mark."
+ (cond (this-command-keys-shift-translated
+ (unless (and mark-active
+ (eq (car-safe transient-mark-mode) 'only))
+ (setq transient-mark-mode
+ (cons 'only
+ (unless (eq transient-mark-mode 'lambda)
+ transient-mark-mode)))
+ (push-mark nil nil t)))
+ ((eq (car-safe transient-mark-mode) 'only)
+ (setq transient-mark-mode (cdr transient-mark-mode))
+ (deactivate-mark))))
+
(define-minor-mode transient-mark-mode
"Toggle Transient Mark mode.
With arg, turn Transient Mark mode on if arg is positive, off otherwise.
:init-value (not noninteractive)
:group 'editing-basics)
+;; The variable transient-mark-mode is ugly: it can take on special
+;; values. Document these here.
+(defvar transient-mark-mode t
+ "*Non-nil if Transient Mark mode is enabled.
+See the command `transient-mark-mode' for a description of this minor mode.
+
+Non-nil also enables highlighting of the region whenever the mark is active.
+The variable `highlight-nonselected-windows' controls whether to highlight
+all windows or just the selected window.
+
+If the value is `lambda', that enables Transient Mark mode
+temporarily. After any subsequent action that would normally
+deactivate the mark (such as buffer modification), Transient Mark mode
+is turned off.
+
+If the value is (only . OLDVAL), that enables Transient Mark mode
+temporarily. After any subsequent point motion command that is not
+shift-translated, or any other action that would normally deactivate
+the mark (such as buffer modification), the value of
+`transient-mark-mode' is set to OLDVAL.")
+
(defvar widen-automatically t
"Non-nil means it is ok for commands to call `widen' when they want to.
Some commands will do this in order to go to positions outside
If you are thinking of using this in a Lisp program, consider
using `forward-line' instead. It is usually easier to use
and more reliable (no dependence on goal column, etc.)."
- (interactive "p\np")
+ (interactive "^p\np")
(or arg (setq arg 1))
(if (and next-line-add-newlines (= arg 1))
(if (save-excursion (end-of-line) (eobp))
If you are thinking of using this in a Lisp program, consider using
`forward-line' with a negative argument instead. It is usually easier
to use and more reliable (no dependence on goal column, etc.)."
- (interactive "p\np")
+ (interactive "^p\np")
(or arg (setq arg 1))
(if (interactive-p)
(condition-case nil
With argument ARG not nil or 1, move forward ARG - 1 lines first.
If point reaches the beginning or end of buffer, it stops there.
To ignore intangibility, bind `inhibit-point-motion-hooks' to t."
- (interactive "p")
+ (interactive "^p")
(or arg (setq arg 1))
(let (done)
(while (not done)
With argument ARG not nil or 1, move forward ARG - 1 lines first.
If point reaches the beginning or end of buffer, it stops there.
To ignore intangibility, bind `inhibit-point-motion-hooks' to t."
- (interactive "p")
+ (interactive "^p")
(or arg (setq arg 1))
(let ((orig (point))
(defun backward-word (&optional arg)
"Move backward until encountering the beginning of a word.
With argument, do this that many times."
- (interactive "p")
+ (interactive "^p")
(forward-word (- (or arg 1))))
(defun mark-word (&optional arg allow-extend)