I would like to get foldexpr
to work on my .emacs
file like outshine.el
does. In other words, I would like to get the fold levels as in this example:
0
;;; 0
1
1
;;;; 1
2
2
;;;;; 2
3
;;;; 1
2
;;; 0
1
1
(Notation like that found at Advanced Folding _ Learn Vimscript the Hard Way.)
In summary, I think the foldexpr
will have to check current lines and previous lines.
If the current line has at least 3 ;
, then fold level will be 3 less. Otherwise, if the previous line has at least 3, the current will have fold level 2 less, else fold level should be equal to previous line.
That is the effect I tried to achieve with
function ELispLevel()
let n = len(matchstr(getline(v:lnum), '^;\+'))
let m = len(matchstr(getline(v:lnum-1), '^;\+'))
if n >= 2
return ">" . n-3
else
if m >= 2
return ">" . m-2
else
return "="
endif
endfunction
(Credit for most of the code goes to the discussion of markdown folding at Vim Markdown Folding? - Stack Overflow, especially a comment by Omar AntolĂn-Camarena.)
I am guessing this does not work. Some of my less trivial modifications include the n-3
and m-2
, so maybe I just screwed up the syntax there. But I'm afraid my error could be anywhere, and hope someone can find it.
I also have the following to try to activate it for my init.el
file,
aug filetype_lisp
au!
" au FileType lisp setl fdm=marker fmr=;;;,;;+
au FileType lisp setlocal foldmethod=expr foldexpr=ELispLevel()
aug END
(BTW, a third link that I learned some of this from is vim - Explaining foldexpr syntax - Stack Overflow)