3

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 2

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))
2
  • 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, 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
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 and acknowledge that you have read and understand our privacy policy and code of conduct.

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