2

I have some sample code like this:

(defun some-function ()
  (interactive)
  (push-mark)
  (goto-char (point-min))
  ; do some stuff
  (pop-mark))

Now I'm expecting pop-mark to get me back to the original location. But that doesn't seem to be happening. Any idea on how to do this properly ?

Drew
  • 75,699
  • 9
  • 109
  • 225
Sibi
  • 3,603
  • 2
  • 22
  • 35
  • I would recommend storing your location points in let-bound variables and then going back there again: `(let* ((point-one (point)) point-two) (goto-char (point-min)) [do stuff . . .] (goto-char point-one))` You can create a place holder for the variable -- e.g., `point-two` and then when you get there, set it with `(setq point-two (point))` – lawlist May 05 '15 at 02:24

1 Answers1

6

From pop-mark's documentation: ...This does not move point in the buffer

I think you want:

;; do some stuff
(goto-char (mark))
(pop-mark)

But if all you care about is returning to a previous location, and not actually using the mark ring, then you could either

1) save (point) in a variable and return to it

2) use save-excursion which does this for you

assem
  • 176
  • 5
  • 8
    `save-excursion` really is the best way to do this. You don't have to worry about saving the initial position of point, just let `save-excursion` do the work for you. – zck May 05 '15 at 03:57