summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjluehrs2 <jluehrs2@uiuc.edu>2008-04-20 21:48:05 -0500
committerjluehrs2 <jluehrs2@uiuc.edu>2008-04-20 21:48:05 -0500
commit821290599a15452d2604fc5b0a29b6b0aa1b0c07 (patch)
treef1ab02ada24354f61eac4969e71130f91a523550
parent8b8d5499906b9e74e3c68e4fa0153cf9b9346eb5 (diff)
downloadvim-foldtext-821290599a15452d2604fc5b0a29b6b0aa1b0c07.tar.gz
vim-foldtext-821290599a15452d2604fc5b0a29b6b0aa1b0c07.zip
add nifty folding stuff
-rw-r--r--vimrc55
1 files changed, 55 insertions, 0 deletions
diff --git a/vimrc b/vimrc
index 8c3cd91..52a05e9 100644
--- a/vimrc
+++ b/vimrc
@@ -135,6 +135,9 @@ set cinoptions+=b1
" Folding {{{
" fold only when I ask for it damnit!
set foldmethod=marker
+
+" use my custom fold display function (see bottom)
+set foldtext=Base_foldtext()
"}}}
"}}}
@@ -185,6 +188,9 @@ autocmd FileType perl setlocal keywordprg=perldoc\ -f
" Latex :make converts to pdf {{{
autocmd FileType tex setlocal makeprg=~/bin/latexpdf\ --show\ %
" }}}
+" Set up custom folding {{{
+autocmd FileType tex set foldtext=Latex_foldtext()
+" }}}
"}}}
" Insert-mode remappings/abbreviations {{{
@@ -274,3 +280,52 @@ if file_readable(s:session_file) && expand("%:.") !~ '^/'
endif
" }}}
" }}}
+
+" Folding {{{
+" Base {{{
+function Base_foldtext(...)
+ " if we're passed in a string, use that as the display, otherwise use the
+ " contents of the line at the start of the fold
+ if a:0 > 0
+ let line = a:1
+ else
+ let line = getline(v:foldstart)
+ endif
+
+ " remove the marker that caused this fold from the display
+ let foldmarkers = split(&foldmarker, ',')
+ let line = substitute(line, '\V\s\?' . foldmarkers[0] . '\s\?', ' ', '')
+
+ " remove any remaining leading or trailing whitespace
+ let line = substitute(line, '^\s*\(.\{-}\)\s*$', '\1', '')
+
+ " align everything, and pad the end of the display with -
+ let line = printf('%-' . (63 - v:foldlevel) . 's', line)
+ let line = substitute(line, '\%( \)\@<= \%( *$\)\@=', '-', 'g')
+
+ " format the line count
+ let nlines = printf('%12s',
+ \ '(' . (v:foldend - v:foldstart + 1) . ' lines) ')
+
+ return '+-' . v:folddashes . ' ' . line . nlines
+endfunction
+" }}}
+" Latex {{{
+let s:latex_types = {'thm': 'Theorem', 'cor': 'Corollary',
+ \ 'lem': 'Lemma', 'defn': 'Definition'}
+function Latex_foldtext()
+ let line = getline(v:foldstart)
+
+ " if we get the start of a theorem, format the display nicely
+ " XXX: allow the label to be on the following line
+ let matches = matchlist(line,
+ \ '\\begin{\([^}]*\)}.*\\label{\([^}]*\)}')
+ if !empty(matches) && has_key(s:latex_types, matches[1])
+ return Base_foldtext(s:latex_types[matches[1]] . ": " . matches[2])
+ endif
+
+ " otherwise, just strip latex comments from the line
+ return Base_foldtext(substitute(line, '\s\?%\s\?', ' ', ''))
+endfunction
+" }}}
+" }}}