11

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.

PythonNut
  • 10,243
  • 2
  • 29
  • 75
noctuid
  • 429
  • 3
  • 11
  • 1
    Vim automatically saves buffer-local markers to disk by default. Evil doesn't, because it doesn't emulate Vim's [+viminfo](http://vimdoc.sourceforge.net/htmldoc/various.html#+viminfo) feature. Have you submitted a feature request to the [Evil](https://gitorious.org/evil/pages/Home) issue tracker? Have they responded? – unforgettableidSupportsMonica May 27 '15 at 03: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 02: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 . #) 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](https://github.com/emacs-evil/evil/issues/674). – Mirzhan Irkegulov May 31 '17 at 18:13

2 Answers2

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.

noctuid
  • 429
  • 3
  • 11
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"))))))
  )
Hao Deng
  • 11
  • 1