aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim F. Storm2002-04-14 17:27:55 +0000
committerKim F. Storm2002-04-14 17:27:55 +0000
commit868c2f498c7c0677f2229aef382bbfe427eb780d (patch)
tree7934ab80eeab5798861eebdc3c18298453041f9e
parent5e55c9ebe5f54d22ff540e04429968f24f5321f5 (diff)
downloademacs-868c2f498c7c0677f2229aef382bbfe427eb780d.tar.gz
emacs-868c2f498c7c0677f2229aef382bbfe427eb780d.zip
(pop-to-mark-command, push-mark-command): New commands.
(set-mark-command): Use them. Enhanced functionality when command is repeated: - If first command set the mark (no prefix arg), repeat temporarily enables transient-mark-mode. - If first command jumped to mark off ring (with argument), repeat (with or without arg) jump to next mark off ring. - Use C-u C-u prefix to set mark after jump. (exchange-point-and-mark): Temporarily enable transient-mark-mode if prefix arg.
-rw-r--r--lisp/simple.el86
1 files changed, 64 insertions, 22 deletions
diff --git a/lisp/simple.el b/lisp/simple.el
index c8ce9932011..df7955098e0 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -2233,10 +2233,12 @@ a mistake; see the documentation of `set-mark'."
2233 "Deactivate the mark by setting `mark-active' to nil. 2233 "Deactivate the mark by setting `mark-active' to nil.
2234\(That makes a difference only in Transient Mark mode.) 2234\(That makes a difference only in Transient Mark mode.)
2235Also runs the hook `deactivate-mark-hook'." 2235Also runs the hook `deactivate-mark-hook'."
2236 (if transient-mark-mode 2236 (cond
2237 (progn 2237 ((eq transient-mark-mode 'lambda)
2238 (setq mark-active nil) 2238 (setq transient-mark-mode nil))
2239 (run-hooks 'deactivate-mark-hook)))) 2239 (transient-mark-mode
2240 (setq mark-active nil)
2241 (run-hooks 'deactivate-mark-hook))))
2240 2242
2241(defun set-mark (pos) 2243(defun set-mark (pos)
2242 "Set this buffer's mark to POS. Don't use this function! 2244 "Set this buffer's mark to POS. Don't use this function!
@@ -2286,23 +2288,56 @@ Start discarding off end if gets this big."
2286 :type 'integer 2288 :type 'integer
2287 :group 'editing-basics) 2289 :group 'editing-basics)
2288 2290
2291(defun pop-to-mark-command ()
2292 "Jump to mark, and pop a new position for mark off the ring
2293\(does not affect global mark ring\)."
2294 (interactive)
2295 (if (null (mark t))
2296 (error "No mark set in this buffer")
2297 (setq this-command 'pop-to-mark-command)
2298 (goto-char (mark t))
2299 (pop-mark)))
2300
2301(defun push-mark-command (arg)
2302 "Set mark at where point is.
2303If no prefix arg and mark is already set there, just activate it."
2304 (interactive "P")
2305 (let ((mark (marker-position (mark-marker))))
2306 (if (or arg (null mark) (/= mark (point)))
2307 (push-mark nil nil t)
2308 (setq mark-active t)
2309 (message "Mark activated"))))
2310
2289(defun set-mark-command (arg) 2311(defun set-mark-command (arg)
2290 "Set mark at where point is, or jump to mark. 2312 "Set mark at where point is, or jump to mark.
2291With no prefix argument, set mark, push old mark position on local mark 2313With no prefix argument, set mark, push old mark position on local mark
2292ring, and push mark on global mark ring. 2314ring, and push mark on global mark ring. Immediately repeating the
2315command activates `transient-mark-mode' temporarily.
2316
2293With argument, jump to mark, and pop a new position for mark off the ring 2317With argument, jump to mark, and pop a new position for mark off the ring
2294\(does not affect global mark ring\). 2318\(does not affect global mark ring\). Repeating the command without
2319an argument jumps to the next position off the mark ring.
2295 2320
2296Novice Emacs Lisp programmers often try to use the mark for the wrong 2321Novice Emacs Lisp programmers often try to use the mark for the wrong
2297purposes. See the documentation of `set-mark' for more information." 2322purposes. See the documentation of `set-mark' for more information."
2298 (interactive "P") 2323 (interactive "P")
2299 (if (null arg) 2324 (if (eq transient-mark-mode 'lambda)
2300 (progn 2325 (setq transient-mark-mode nil))
2301 (push-mark nil nil t)) 2326 (cond
2302 (if (null (mark t)) 2327 ((not (eq this-command 'set-mark-command))
2303 (error "No mark set in this buffer") 2328 (push-mark-command t))
2304 (goto-char (mark t)) 2329 ((eq last-command 'pop-to-mark-command)
2305 (pop-mark)))) 2330 (if (and (consp arg) (> (prefix-numeric-value arg) 4))
2331 (push-mark-command nil)
2332 (pop-to-mark-command)))
2333 (arg
2334 (pop-to-mark-command))
2335 ((and (eq last-command 'set-mark-command)
2336 mark-active (null transient-mark-mode))
2337 (setq transient-mark-mode 'lambda)
2338 (message "Transient-mark-mode temporarily enabled"))
2339 (t
2340 (push-mark-command nil))))
2306 2341
2307(defun push-mark (&optional location nomsg activate) 2342(defun push-mark (&optional location nomsg activate)
2308 "Set mark at LOCATION (point, by default) and push old mark on mark ring. 2343 "Set mark at LOCATION (point, by default) and push old mark on mark ring.
@@ -2354,17 +2389,24 @@ Does not set point. Does nothing if mark ring is empty."
2354 (setq mark-ring (cdr mark-ring))))) 2389 (setq mark-ring (cdr mark-ring)))))
2355 2390
2356(defalias 'exchange-dot-and-mark 'exchange-point-and-mark) 2391(defalias 'exchange-dot-and-mark 'exchange-point-and-mark)
2357(defun exchange-point-and-mark () 2392(defun exchange-point-and-mark (&optional arg)
2358 "Put the mark where point is now, and point where the mark is now. 2393 "Put the mark where point is now, and point where the mark is now.
2359This command works even when the mark is not active, 2394This command works even when the mark is not active,
2360and it reactivates the mark." 2395and it reactivates the mark.
2361 (interactive nil) 2396With prefix arg, `transient-mark-mode' is enabled temporarily."
2362 (let ((omark (mark t))) 2397 (interactive "P")
2363 (if (null omark) 2398 (if arg
2364 (error "No mark set in this buffer")) 2399 (if mark-active
2365 (set-mark (point)) 2400 (if (null transient-mark-mode)
2366 (goto-char omark) 2401 (setq transient-mark-mode 'lambda))
2367 nil)) 2402 (setq arg nil)))
2403 (unless arg
2404 (let ((omark (mark t)))
2405 (if (null omark)
2406 (error "No mark set in this buffer"))
2407 (set-mark (point))
2408 (goto-char omark)
2409 nil)))
2368 2410
2369(defun transient-mark-mode (arg) 2411(defun transient-mark-mode (arg)
2370 "Toggle Transient Mark mode. 2412 "Toggle Transient Mark mode.