I want to be able to save my buffer local evil markers (m to mark a location and then ' or ` to jump to it) across emacs sessions/instances. I'm not really sure how to do this. I tried installing/using session and adding them like so:

(add-to-list 'session-locals-include 'evil-markers-alist)

This doesn't work though, and I'm not sure what else to try. Thanks.

  • Vim automatically saves buffer-local markers to disk by default. Evil doesn't, because it doesn't emulate Vim's +viminfo feature. Have you submitted a feature request to the Evil issue tracker? Have they responded? May 27 '15 at 3:17
  • @angelic_sedition really, this isn't about evil, it's about persistent buffer-local-variables. The latter is far more general and useful, and I'm quite interested in the answer. I've created a tag for your question.
    – PythonNut
    Jul 14 '15 at 2:54
  • @PythonNut Well I've found that the problem is specifically with the the markers (I think). Both desktop and session.el store buffer local variables for the evil-markers-alist, but they do not end up matching the actual value (anything like (108 . #<marker at 54991 in file.org>) is left out). I'd guess this is because they can't or don't know how to save a marker object.
    – noctuid
    Sep 17 '15 at 19:19
  • 1
    As of May 2017 it's an open issue. May 31 '17 at 18:13

Here is my solution: Put below code in your .emacs or .spacemacs.

You'll need manually put upper-case marker name and file name at line: evil-add-to-alist. I also modified evil-goto-mark to fix a bug that introduced by set evil-markers-alist directly. The old code assume when the marker is a cons, the buffer has been closed. (when buffer closed, it convert marker to cons).

  (setq alist (default-value 'evil-markers-alist))
  (evil-add-to-alist 'alist ?E '("/path/to/yourfile" . 1))
  (setq-default evil-markers-alist alist)

  (evil-define-command evil-goto-mark (char &optional noerror)
    "Go to the marker specified by CHAR."
    :keep-visual t
    :repeat nil
    :type exclusive
    (interactive (list (read-char)))
    (let ((marker (evil-get-marker char)))
       ((markerp marker)
        (switch-to-buffer (marker-buffer marker))
        (goto-char (marker-position marker)))
       ((numberp marker)
        (goto-char marker))
       ((consp marker)
        (when (or (and (find-buffer-visiting (car marker))
                       (switch-to-buffer (find-buffer-visiting (car marker)) )
                  (and (y-or-n-p (format "Visit file %s again? "
                                         (car marker)))
                       (find-file (car marker))))
          (goto-char (cdr marker))))
       ((not noerror)
        (user-error "Marker `%c' is not set%s" char
                    (if (evil-global-marker-p char) ""
                      " in this buffer"))))))
  • I forget to mention this only works for global marker. ( upper case marker)
    – Hao Deng
    Dec 16 '15 at 17:03
  • can you give example how to 'manually put upper-case marker name and file name at line'? Jun 14 '20 at 1:22

desktop.el supports storing/restoring markers (now at least). (add-to-list 'desktop-locals-to-save 'evil-markers-alist) or (cl-pushnew 'evil-markers-alist desktop-locals-to-save) work for me.

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.