1" 2" cream-vim-foldfunctions.vim 3" 4" Cream -- An easy-to-use configuration of the famous Vim text editor 5" [ http://cream.sourceforge.net ] Copyright (C) 2001-2011 Steve Hall 6" 7" License: 8" This program is free software; you can redistribute it and/or modify 9" it under the terms of the GNU General Public License as published by 10" the Free Software Foundation; either version 3 of the License, or 11" (at your option) any later version. 12" [ http://www.gnu.org/licenses/gpl.html ] 13" 14" This program is distributed in the hope that it will be useful, but 15" WITHOUT ANY WARRANTY; without even the implied warranty of 16" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17" General Public License for more details. 18" 19" You should have received a copy of the GNU General Public License 20" along with this program; if not, write to the Free Software 21" Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 22" 02111-1307, USA. 23" 24" 25" Description: 26" Add fold marks for all functions in the form 27" 28" " MyFunction() {_{_{_1 29" function! MyFunction() 30" 31" and place 32" 33" " vim_:_foldmethod=marker 34" 35" at the bottom of the current file. (Where the underscores "_" are 36" omitted above.) 37" 38 39 40" register as a Cream add-on 41if exists("$CREAM") 42 43 call Cream_addon_register( 44 \ 'Vim Fold Functions', 45 \ 'Fold all functions in the current document', 46 \ "Create a comment line above each Vim function with the function's name followed by a fold marker.", 47 \ 'Cream Devel.Fold Vim Functions', 48 \ 'call Cream_vim_foldfunctions()', 49 \ '<Nil>' 50 \ ) 51endif 52 53function! Cream_vim_foldfunctions() 54" fold all functions in a given Vim filetype document 55" Note: Weirdness in syntaxes below is to prevent folding. ;) 56 57 " if filetype not Vim, quit 58 if &filetype != "vim" 59 call confirm( 60 \ "Function designed only for Vim files. Please check this document's filetype.\n" . 61 \ "\n", "&Ok", 1, "Info") 62 return 63 endif 64 65 " fold all functions 66 execute '%substitute/^function[!] \(\k\+\)()$/" \1() {' . '{' . '{' . '1\r\1()/gei' 67 68 " add fold marker at bottom line 69 ""*** BROKEN 70 "call setline("$", getline("$") . "\n\" vim" . ":foldmethod=marker") 71 ""*** 72 let mypos = Cream_pos() 73 " go to last line 74 normal G 75 normal $ 76 execute "normal a\<CR>\" }" . "}" . "}" . "1\<CR>" 77 call setline("$", "\" vim" . ":foldmethod=marker") 78 79 execute mypos 80 81endfunction 82 83