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

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

Re: how to just back to previous location quickly?


From: Barman Brakjoller
Subject: Re: how to just back to previous location quickly?
Date: 25 Apr 2003 01:27:48 -0700

> I've been using the following code for several years and I am very
> happy with it. You just quickly store your position (using C-. in my
> setting), move somewhere else and then can toggle between the stored
> and the new position using C-,.
> 
> Of course the keybinding is a matter of taste...

And here is mine, which is very similar. The big difference is that
once you jumped back to the saved position, you can jump between the
two by using jump-last-posiiton:

(defun save-current-position ()
  "Saves current cursor position in register 0"
  (interactive)
  (point-to-register 0)
  (delete (assoc 1 register-alist) register-alist)
  (message "Position saved."))

(defun jump-last-position ()
  "Jump to position saved with previous `save-current-position´,
OR if run two times with no `save-current-position´ in between,
jump to the last position it was run from."
  (interactive)
  (if (get-register 0)
      (progn
        (point-to-register 1)
        (jump-to-register 0)
        (delete (assoc 0 register-alist) register-alist)
        (message "Jumped to last saved or last jump-position"))
    (if (get-register 1)
        (progn
          (point-to-register 0)
          (jump-to-register 1)
          (delete (assoc 1 register-alist) register-alist)
          (message "Jumped to last saved or last jump-position"))
      (message "No pos saved"))))

Of course it is quite ugly to just hijack register 0, but it is a
register that a user at least cannot type using the keyboard (or maybe
by using C-q first, I don't know and I don't care... :)


reply via email to

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