12

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.

4
  • 1
    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? Commented May 27, 2015 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. Commented Jul 14, 2015 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. Commented Sep 17, 2015 at 19:19
  • 1
    As of May 2017 it's an open issue. Commented May 31, 2017 at 18:13

2 Answers 2

2

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.

1
  • Does this store buffer-local markers as well global markers? How does it handle conflicts between two simultaneously running emacs sessions? Commented Feb 19, 2024 at 18:02
1

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))) (cond ((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")))))) ) 
2
  • I forget to mention this only works for global marker. ( upper case marker) Commented Dec 16, 2015 at 17:03
  • can you give example how to 'manually put upper-case marker name and file name at line'? Commented Jun 14, 2020 at 1:22

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.