unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Patch: enhanced mark navigation commands
@ 2008-03-05  5:12 Adrian Robert
  2008-03-05  6:19 ` Miles Bader
                   ` (3 more replies)
  0 siblings, 4 replies; 17+ messages in thread
From: Adrian Robert @ 2008-03-05  5:12 UTC (permalink / raw)
  To: emacs- devel

[-- Attachment #1: Type: text/plain, Size: 515 bytes --]

The attached lisp allows moving around within a buffer or buffers to
places where recent edits or other events took place.  It has been
part of Emacs.app for a while and users have found it useful; I'd like
to propose it being added to the emacs distribution itself, probably
as part of simple.el.

Specifically, the keys M-p and M-n are bound to move forwards and
backwards through the mark history.  Also, immediately after popping a
global mark, e.g., with C-x C-SPC, then the global mark ring is used.

-Adrian

[-- Attachment #2: ns-mark-nav.el --]
[-- Type: application/octet-stream, Size: 2409 bytes --]

;;; ns-mark-nav.el -- mark navigation commands for Emacs

;; Copyright (C) 2005, 2006, 2007
;;        Free Software Foundation, Inc.

;; Author: Adrian Robert (arobert@cogsci.ucsd.edu)
;;         Andrew L. Moore (slewsys@mac.com)

;; This file is part of Emacs.app

;;; Commentary:

;; Support for moving backwards and forwards in the so-called "mark ring".

;; After you load this file, the keys M-p and M-n will move forwards and
;; backwards through the mark history respectively.
;; Generally this is the buffer-local mark ring, but immediately after popping
;; a global mark, e.g., with C-x C-SPC, then the global mark ring is used.

(defvar mark-ring-order 'backward
  "The order in which marks in the current buffer's mark-ring are visited,
either `forward' or `backward' (the default).")
(make-variable-buffer-local 'mark-ring-traversal)
(put 'mark-ring-traversal 'permanent-local t)

(defvar global-mark-ring-order 'backward
  "The order in which marks in the global-mark-ring are visited,
either `forward' or `backward' (the default).")

(defmacro ns-set-mark (ring ring-order order nth)
  "Visit nth mark in ring in ring-order, which is set to order."
  `(progn
     (setq this-command 'set-mark-command)
     (if (not (equal ,ring-order ,order))
	 (progn
	   (setq ,ring-order ,order)
	   (setq ,ring (reverse ,ring))))
     (while (> ,nth 0)
       (setq ,nth (1- ,nth))
       (set-mark-command (eq ,ring mark-ring)))))

(defun ns-pop-mark (order nth)
  "Go to `nth' next/previous mark, depending on whether `direction' is
'forward or 'backward, respectively."
  (if (eq last-command 'pop-global-mark)
      (ns-set-mark global-mark-ring global-mark-ring-order order nth)
    (ns-set-mark mark-ring mark-ring-order order nth)))

;; Main commands
(defun ns-prev-mark (nth)
  "Go to current mark, push it onto mark-ring and pop previous mark.
With prefix argument, nth, go to nth previous mark.
For full description, see `set-mark-command' command."
  (interactive "p")
  (ns-pop-mark 'backward nth))

(defun ns-next-mark (nth)
  "Go to current mark, push it onto mark-ring and pop next mark.
With prefix argument, nth, go to nth next mark.
For full description, see `set-mark-command' command."
  (interactive "p")
  (ns-pop-mark 'forward nth))

;; Keybindings
(global-set-key [(meta p)] 'ns-prev-mark)
(global-set-key [(meta n)] 'ns-next-mark)

(provide 'ns-mark-nav)

;;; mark-nav.el ends here

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2008-03-11 15:08 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-05  5:12 Patch: enhanced mark navigation commands Adrian Robert
2008-03-05  6:19 ` Miles Bader
2008-03-05 12:23   ` paul r
2008-03-05  6:41 ` Dan Nicolaescu
2008-03-06  0:57   ` Juri Linkov
2008-03-06  1:47     ` Dan Nicolaescu
2008-03-06  7:18       ` Drew Adams
2008-03-06 10:09       ` Juri Linkov
2008-03-09 21:55     ` Juri Linkov
2008-03-05 16:11 ` Ted Zlatanov
2008-03-05 19:20   ` Stefan Monnier
2008-03-05 19:48     ` Ted Zlatanov
2008-03-05 22:10       ` Miles Bader
2008-03-10 13:09         ` Ted Zlatanov
2008-03-10 22:34           ` Juri Linkov
2008-03-11 15:08             ` Ted Zlatanov
2008-03-06  0:54 ` Juri Linkov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).