summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjluehrs2 <jluehrs2@uiuc.edu>2008-04-20 22:45:19 -0500
committerjluehrs2 <jluehrs2@uiuc.edu>2008-04-20 22:45:19 -0500
commita21f697209dee1a037f4e79cb7702a3b634c304d (patch)
treebf9a51e33c1f81cf555c79465b73e8e613b53501
parenta81b05fc4d2e1d49d6557df854c5b688125d14dc (diff)
downloadvim-foldtext-a21f697209dee1a037f4e79cb7702a3b634c304d.tar.gz
vim-foldtext-a21f697209dee1a037f4e79cb7702a3b634c304d.zip
move the foldtext overrides up with the rest of the folding stuff
-rw-r--r--vimrc141
1 files changed, 71 insertions, 70 deletions
diff --git a/vimrc b/vimrc
index 92297db..541b438 100644
--- a/vimrc
+++ b/vimrc
@@ -136,8 +136,78 @@ set cinoptions+=b1
" fold only when I ask for it damnit!
set foldmethod=marker
-" use my custom fold display function (see bottom)
+" use my custom fold display function
set foldtext=Base_foldtext()
+
+" foldtext overrides {{{
+" 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' . foldmarkers[0], ' ', '')
+
+ " remove comments that we know about
+ let comment = split(&commentstring, '%s')
+ if comment[0] != ''
+ let line = substitute(line, '\V' . comment[0], ' ', '')
+ endif
+ if comment[1] != ''
+ let line = substitute(line, '\V' . comment[1], ' ', '')
+ endif
+
+ " 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('%-' . (62 - v:foldlevel) . 's', line)
+ let line = substitute(line, '\%( \)\@<= \%( *$\)\@=', '-', 'g')
+
+ " format the line count
+ let nlines = printf('%13s',
+ \ '(' . (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
+
+ return Base_foldtext()
+endfunction
+" }}}
+" C++ {{{
+function Cpp_foldtext()
+ let line = getline(v:foldstart)
+
+ let block_open = stridx(line, '/*')
+ let line_open = stridx(line, '//')
+ if block_open == -1 || line_open < block_open
+ return Base_foldtext(substitute(line, '//', ' ', ''))
+ endif
+
+ return Base_foldtext(line)
+endfunction
+" }}}
+" }}}
"}}}
"}}}
@@ -282,72 +352,3 @@ 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' . foldmarkers[0], ' ', '')
-
- " remove comments that we know about
- let comment = split(&commentstring, '%s')
- if comment[0] != ''
- let line = substitute(line, '\V' . comment[0], ' ', '')
- endif
- if comment[1] != ''
- let line = substitute(line, '\V' . comment[1], ' ', '')
- endif
-
- " 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('%-' . (62 - v:foldlevel) . 's', line)
- let line = substitute(line, '\%( \)\@<= \%( *$\)\@=', '-', 'g')
-
- " format the line count
- let nlines = printf('%13s',
- \ '(' . (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
-
- return Base_foldtext()
-endfunction
-" }}}
-" C++ {{{
-function Cpp_foldtext()
- let line = getline(v:foldstart)
-
- let block_open = stridx(line, '/*')
- let line_open = stridx(line, '//')
- if block_open == -1 || line_open < block_open
- return Base_foldtext(substitute(line, '//', ' ', ''))
- endif
-
- return Base_foldtext(line)
-endfunction
-" }}}
-" }}}