"========================================================== " File: lwebfold.vim " Author: Dimitris Michail " CVS: $Id: lwebfold.vim,v 1.1 2004/11/12 13:44:08 michail Exp $ " Created: Thu Nov 04 23:00 CET 2004 " " Description: Syntax folding for LEDA's Lweb system. Should " also work with noweb. " Supports folding either the documentation chunks " () or the code chunks (). " " Installation: " " Create a file ~/.vim/after/filetype.vim with contents " " augroup filetypedetect " au BufNewFile,BufRead *.lw setf lweb " au BufNewFile,BufRead *.nw setf noweb " augroup END " " Copy this file to ~/.vim/lwebfold.vim or where ever you " like and then add the following lines to ~/.vimrc " " let g:noLwebAutoFolding=1 " let g:noLwebManualFolding=1 " au BufNewFile,BufRead *.lw source ~/.vim/lwebfold.vim " au BufNewFile,BufRead *.nw source ~/.vim/lwebfold.vim " " In case you did not use ~/.vim/lwebfold.vim the previous " line requires a change. " " Comment the let g:noLwebAutoFolding command to force folding " on startup. " Uncomment the let g:noLwebManualFolding command to pervent " folding of the manual entries. " " Otherwise pressing folds the documentation inside " the lweb file. Pressing folds the code inside " the lweb file. " " Known bugs: " - If a manual entry is only one line, then it is not " folded correctly. " Example: /*{\Mtext Only one line}*/ " "========================================================== " Make sure we do this only once if exists('s:runAlready') call MakeLwebFolds(1) finish endif let s:runAlready = 1 " Boolean, on whether we are folding documentation chunks " or code chunks. let b:docFolds = 1 " source SyntaxFolds.vim because we need a few functions from it. runtime plugin/SyntaxFolds.vim " make map, F6 is refresh folds nnoremap Lweb_RefreshFolds :call MakeLwebFolds(1) nmap Lweb_RefreshFolds " make map, Shift-F6 is refresh folds on code nnoremap Lweb_RefreshCodeFolds :call MakeLwebCodeFolds(1) nmap Lweb_RefreshCodeFolds " ======================================================== " Lweb_SetFoldOptions: Initialize folding {{{ function! Lweb_SetFoldOptions() if exists('b:doneSetFoldOptions') return endif let b:doneSetFoldOptions = 1 " set any options required " NONE for now " create folds call MakeLwebFolds(1) endfunction " MakeLwebFolds: function to create fold items for Lweb. {{{ " function! MakeLwebFolds(force) if &ft != 'lweb' && &ft != 'noweb' return endif " Destroy previous folding, if we were folding code chunks if b:docFolds == 0 let b:docFolds = 1 let b:numFoldItems = 0 normal! zE endif " Documentation chunks call AddSyntaxFoldItem ( \ '^@', \ '^\s*<<', \ 0, \ -1, \ ) " In Lweb there is also a @c chunk for examples " We let the previous rule to match this as well. " Latex preamble " Match from documentclass to first @ call AddSyntaxFoldItem ( \ '^\s*\\document\(class\|style\)', \'^@', \ 0, \ -1, \ ) " LEDA manual commands " Match from /*{ until }*/ " " BUG: Does not work for 1 line input. if !exists('g:noLwebManualFolding') call AddSyntaxFoldItem ( \ '^\s*\/\*{', \ '}\*\/', \ 0, \ 0, \ ) endif " Make the actual folding call MakeSyntaxFolds(a:force) normal! zv endfunction " }}} " MakeLwebFolds: function to create fold items for Lweb code. {{{ " function! MakeLwebCodeFolds(force) if &ft != 'lweb' && &ft != 'noweb' return endif " Destroy previous folding, if we were folding " documentation chunks if b:docFolds == 1 let b:docFolds = 0 let b:numFoldItems = 0 normal! zE endif " Code chunks call AddSyntaxFoldItem ( \ '^<<.*>>=', \ '^@', \ 0, \ -1, \ ) " Make the actual folding call MakeSyntaxFolds(a:force) normal! zv endfunction " }}} " fold by default? if !exists('g:noLwebAutoFolding') call Lweb_SetFoldOptions() endif