wolray / symbol-overlay

Highlight symbols with keymap-enabled overlays
346 stars 42 forks source link

Is that possible to persist overlay information? #63

Open xuning97 opened 4 years ago

xuning97 commented 4 years ago

So next time, when the file is reopened, those overlay still exists.

purcell commented 4 years ago

Not currently possible, but if you can make symbol-overlay-keywords-alist persist somehow, then that should do the trick. I'm not aware of any packages for persisting buffer-specific variables over time, but I imagine such a thing exists.

florommel commented 3 years ago

Built-in desktop provides functions to save and restore sessions. It has a desktop-locals-to-save list. Do something like this to restore the overlays when loading a session:

(defun desktop-after-read-restore-symbol-overlay ()
    (require 'symbol-overlay)
    (run-with-idle-timer
     0 nil
     (lambda ()
       (dolist (buf (buffer-list))
         (with-current-buffer buf (symbol-overlay-after-revert))))))
  (eval-after-load "desktop"
    (progn (add-to-list 'desktop-locals-to-save 'symbol-overlay-keywords-alist)
           (add-hook 'desktop-after-read-hook #'desktop-after-read-restore-symbol-overlay)))