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?
2 Answers
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))
-
I opened a C++ file and run
(mark-marker)
but it returns#<marker in no buffer>
, while some other buffers the marks do have buffers. Do you know when does this happen?– Tu DoFeb 24, 2015 at 19:11 -
@TuDo From what I understand, you need to set the mark first. Try doing
(push-mark)
and then(mark-marker)
. Feb 24, 2015 at 19:37
The goto-char
function works. It will teleport you to the mark in the same buffer.
(goto-char (mark))