[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: can I move back to the last edit position?
From: |
Miles Bader |
Subject: |
Re: can I move back to the last edit position? |
Date: |
Sat, 11 Sep 2004 09:19:12 +0900 |
Alan Mackenzie <acm@muc.de> writes:
> Because Rokia doesn't know until he's already left this position that he
> wants to jump back. And having to type `C-x r <SPC> R' after every editing
> action is a little irritating, to put it mildly.
>
> It is essential here for the position to be saved automatically.
I'll note that one method I often use to do this is something like:
C-/ C-e C-/
That is, `undo' (which moves point to the location of the undo edit), a
random movement command to interrupt the undo, and then `undo' again to
reverse the effect of my first undo.
This works pretty well, but of course is a bit weird, and potentially
dangerous (if something happens to interrupt you before you redo the
change).
However, it does suggest a possible implementation for a
`goto-last-edit' command: just look at the buffer-undo-list variable,
and jump to the first insert/deletion position you find.
Maybe something like this:
(defun goto-last-edit ()
"Set point to the location of the last insert or delete in the buffer.
Uses buffer undo information, so won't work if undo is disabled."
(interactive)
(let ((undo-records buffer-undo-list)
(pos nil))
(while (and (consp undo-records) (not pos))
(let ((undo (pop undo-records)))
(when (and (consp undo)
(or (stringp (car undo)) (integerp (car undo))))
(setq pos (cdr undo)))))
(if pos
(goto-char pos)
(error "No edits in undo list"))))
-Miles
--
(\(\
(^.^)
(")")
*This is the cute bunny virus, please copy this into your sig so it can spread.
Re: can I move back to the last edit position?, zrr, 2004/09/10
Re: can I move back to the last edit position?, Peter Boettcher, 2004/09/10