While programming I'm often dumping call stack frames to my logfiles so I can see how we got to this point, etc. To avoid clutter, I want to "fold" them out of the way most of the time.
Stack frames have this pattern:
...
Normal logfile information that is not part of the frame
0# first line of the frame <fold>
1# next line of the frame <fold>
... ...
99# main <fold>
More information that is not part of the frame
...
I have been using "foldmethod=manual" and going to the lines that begin with 0# and typing zf} (which says to fold until the next blank line). If I build a macro to do this on all the 0# lines, then it does exactly what I expect. My logfile will correctly look like this:
...
Normal logfile information that is not part of the frame
+ 0# first line of the frame <fold>
More information that is not part of the frame
...
Instead, I want to do this fold automatically using foldmethod=expr. My approach is...
I have a vim syntax file for my logfiles, and define these three lines:
set foldexpr=(getline(v:1num)[0]==\"^\\s*\\d+#\")?1:0
set foldmethod=expr
set foldenable
I've also tried set foldexpr=getline(v:1num)=~'^\\s*\\d+#' and set foldexpr=getline(v:1num)=~'^\\s*\\d+\\#'
The pattern I use (to define a foldlevel of '1') is:
- start of line
- 0 or more whitespace
- 1 or more digits
- the hash/pound/octothorpe character All other lines should have a foldlevel of '0'.
Once loaded in vim, using :set I can see these options as I expect:
foldexpr=(getline(v:1num)[0]=="^\s*\d+#")?1:0
foldmethod=expr
No joy. No folds. How can I debug this? What am I doing wrong?
Thank you!
edit: I have vim 7.4 "huge", that was compiled with "+folding".