help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: vim's jumplist equivalent in emacs?


From: Thomas
Subject: Re: vim's jumplist equivalent in emacs?
Date: 11 Dec 2006 21:54:23 -0800
User-agent: G2/1.0

Thank you all for the answers about using marks.
But I thought they lack jumping forward and I decided to start my first

emacs lisp code as follows. (I mapped C-p, C-o, C-l to the functions) I

think this code is really ugly and any comments are welcome. And can
anyone please advice me how to make 'push-place-uniq' automatically
called every time when I execute some kind of jump actions like
searching texts, opening a file or searching tags etc?

(defvar backward-jump-list nil)
(defvar forward-jump-list nil)


(setq backward-jump-list nil)
(setq forward-jump-list nil)


(defmacro push-place-uniq (place jump-list)
  ;; if the place is already at the head of jump-list, ignore it
  ;; otherwise add it at the head of jump-list
  (list 'if
        (list 'equal place (list 'car jump-list))
        t
        (list 'push place jump-list)))


(defun get-current-place ()
  "Return (current-buffer current-point)"
  (interactive)
  (cons (current-buffer) (point)))


(defun push-current-place ()
  "Push current-place to backward-jump-list and clear
forward-jump-list"
  (interactive)
  (setq forward-jump-list nil)
  (push-place-uniq (get-current-place) backward-jump-list))


(defun backward-jump ()
  "Move to the place at the head of backward-jump-list."
  "Pop it from backward-jump-list and push it to forward-jump-list"
  (interactive)
  (cond
   (backward-jump-list
    (push-place-uniq (get-current-place) forward-jump-list)
    (setq next-place (pop backward-jump-list))
    (cond ((equal next-place (get-current-place))
          (setq next-place (pop backward-jump-list))))
    (setq current-buffer (car next-place))
    (setq current-point (cdr next-place))
    (switch-to-buffer current-buffer)
    (goto-char current-point)
    (push-place-uniq next-place forward-jump-list))))


(defun forward-jump ()
  "Move to the place at the head of forward-jump-list."
  "Pop it from forward-jump-list and push it to backward-jump-list"
  (interactive)
  (cond
   (forward-jump-list
    (push-place-uniq (get-current-place) backward-jump-list)
    (setq next-place (pop forward-jump-list))
    (cond ((equal next-place (get-current-place))
          (setq next-place (pop forward-jump-list))))
    (setq current-buffer (car next-place))
    (setq current-point (cdr next-place))
    (switch-to-buffer current-buffer)
    (goto-char current-point)
    (push-place-uniq next-place backward-jump-list))))


(global-set-key "\C-p" 'push-current-place)
(global-set-key "\C-o" 'backward-jump)
(global-set-key "\C-l" 'forward-jump)

Holger Sparr 작성:

> On Thu, 07 Dec 2006, "Robert Thorpe" <rthorpe@realworldtech.com> wrote:
>
> > Emacs has no jump list unfortunately.  Almost every operation will set
> > the mark though, as Mathias said.
> >
> > If you do a search you can get back to where you were using C-u C-spc.
> > There are other useful operations.  If you find a tag with M-. then C-u
> > C-spc will return you to where you were.  Though in Emacs C-u C-spc
> > will not return you to where you were when opening a file.
>
> You could push the mark before opening another file (advice the opening
> function) and use the global-mark-ring with C-x C-SPC to jump back.
> 
> Holger
> 
> --



reply via email to

[Prev in Thread] Current Thread [Next in Thread]