unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Adrian Robert" <adrian.b.robert@gmail.com>
To: "emacs- devel" <emacs-devel@gnu.org>
Subject: Patch: enhanced mark navigation commands
Date: Wed, 5 Mar 2008 08:12:35 +0300	[thread overview]
Message-ID: <55f7df060803042112w380b5170qe964002c6c06ab01@mail.gmail.com> (raw)

[-- 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

             reply	other threads:[~2008-03-05  5:12 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-05  5:12 Adrian Robert [this message]
2008-03-05  6:19 ` Patch: enhanced mark navigation commands 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55f7df060803042112w380b5170qe964002c6c06ab01@mail.gmail.com \
    --to=adrian.b.robert@gmail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).