From 821290599a15452d2604fc5b0a29b6b0aa1b0c07 Mon Sep 17 00:00:00 2001 From: jluehrs2 Date: Sun, 20 Apr 2008 21:48:05 -0500 Subject: add nifty folding stuff --- vimrc | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) 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 +" }}} +" }}} -- cgit v1.2.3-54-g00ecf