2

I use hideshow (hs-mode) in almost all languages. Most of the time, i keep function header lines visible but the body hidden like this,

function func(arg1, arg2){...}

So, every time I open the file, I do C-c @ C-l to hide the function body. But, when I close emacs, these buffer states are gone and emacs open buffers without hiding the states.

Does any other lib support persisting show/hide info and reusing it?

3

You, sir, are looking for mode hooks: a set of functions that run every time you enter a buffer in a given mode.

Note that mode hooks will not persist state between sessions, but your question really appears to be about running the same command every time you enter a buffer in a given mode.

Now: for hideshow, the default binding C-c @ C-l is for hs-hide-level, whose docstring reads:

(hs-hide-level ARG)

Hide all blocks ARG levels below this block...

Rather than pick an ARG level (you'd probably want 1, I'd guess), you might consider hs-hide-all:

(hs-hide-all)

Hide all top level blocks, displaying only first and last lines...

Let's say you want to hide everything every time you open an elisp buffer. Because the latter function does not require arguments, you could add it directly to a hook like so:

(add-hook 'emacs-lisp-mode-hook #'hs-hide-all)

If you wanted to use the former, you would need to write a specific function (the preferred method), or else wrap it in an anonymous lambda function:

(add-hook 'emacs-lisp-mode-hook (lambda () (hs-hide-level 1))) ; not preferred

(defun my-hs-hide-stuff ()
  (hs-hide-level 1))
(add-hook 'emacs-lisp-mode-hook #'my-hs-hide-stuff)
1
  • this answer is very helpful... the reason, i asked for persistent hide/show info is that, some function bodies that i am interested in can be left in show state.... but i can live with this... thanks, Dan... – Madhavan Mar 1 '15 at 0:40
0

https://github.com/mrkkrp/vimish-fold has persistence by default: when you kill a buffer your folds don't disappear (there is also https://github.com/alexmurray/evil-vimish-fold for evil users)

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.