2

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?

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))
  • 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 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))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.