I am using web-mode to fold/unfold code. When I fold code, kill buffer and re open it, code folding disappears.

How to preserve code folding even after killing and reopening buffer?


1 Answer 1


I've tried Vimish fold, and it seems to do what you ask. Below is my setup for the keybindings:

(require 'vimish-fold)
(vimish-fold-global-mode 1)
;; this registers a region for future folding/unfolding
(global-set-key (kbd "C-c v") #'vimish-fold)
;; this unregisters the region under point from folding/unfolding
(global-set-key (kbd "C-c d") #'vimish-fold-delete)
;; this is the actual fold/unfold command
(global-set-key (kbd "C-c t") #'vimish-fold-toggle)

I think Mark is the author of this mode, so, maybe he'll chime in and write something about it too.

  • vimish fold doesn't preserve fold if i restart emacs, do you know any other packages which does that? Oct 8, 2015 at 13:36
  • @ChillarAnand did Emacs close in emergency, i.e. such that it wasn't able to run hooks on closing? I'm asking this because it looks like vimish-fold saves the folds information at the time Emacs closes. You may, however force it to by running M-: (vimish-fold--kill-emacs-hook). But there are few other things about saving folds that I personally don't like: 1. huge file names for the files where folds info is recorded. 2. foldining info isn't recorded for killed buffers. I'll put an fr in the bug tracker for this.
    – wvxvw
    Oct 8, 2015 at 14:42
  • There are also two other alternatives I know about, but neither of them saves folds between Emacs sessions: org-struct mode (allows you to use comments in other modes to embed Org-like headings which you can then collapse and expand) and hide-show minor mode, which is the basic folding, except it doesn't have the option to save the folding either.
    – wvxvw
    Oct 8, 2015 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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