Suppose I store the current mark into a variable using mark
or (mark-marker)
. Then I move point elsewhere and insert some text. Which function should I use to jump to the saved mark?
Asked
Active
Viewed 1,149 times
2 Answers
4
Save the mark as a marker:
(setq my-var (mark-marker))
Then:
(goto-char my-var)
This works regardless of the buffer where you set the variable to the marker:
(let ((buf (marker-buffer foo)))
(switch-to-buffer buf)(goto-char foo))
Or if you want to go to that place temporarily, in Lisp code (i.e., without switching to that buffer):
(with-current-buffer (marker-buffer foo)
(goto-char foo))

Drew
- 75,699
- 9
- 109
- 225
-
I opened a C++ file and run `(mark-marker)` but it returns `#
`, while some other buffers the marks do have buffers. Do you know when does this happen? – Tu Do Feb 24 '15 at 19:11 -
@TuDo From what I understand, you need to set the mark first. Try doing `(push-mark)` and then `(mark-marker)`. – Kaushal Modi Feb 24 '15 at 19:37
2
The goto-char
function works. It will teleport you to the mark in the same buffer.
(goto-char (mark))

Kaushal Modi
- 25,203
- 3
- 74
- 179