From 4d7a9e1f61dd6d3f3e55ef28e5f6b0f8fa4b6ca5 Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Wed, 9 Jul 2014 21:10:01 -0700 Subject: [PATCH 1/2] Add an ftplugin for fish profile output files There's no standard extension for these files, so no ftdetect, but an ftplugin called `fishprofile` is defined that sets up tabstop and folding to make it easier to read/navigate these files. When reading a fish profile file, run `:setf fishprofile` to turn on the plugin. --- ftplugin/fishprofile.vim | 65 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 ftplugin/fishprofile.vim diff --git a/ftplugin/fishprofile.vim b/ftplugin/fishprofile.vim new file mode 100644 index 0000000..d5028d2 --- /dev/null +++ b/ftplugin/fishprofile.vim @@ -0,0 +1,65 @@ +" File: ftplugin/fishprofile.vim +" Author: Kevin Ballard +" Description: Filetype plugin for fish profile files +" Last Change: Jul 09, 2014 + +if exists('b:did_ftplugin') + finish +endif +let b:did_ftplugin = 1 + +let s:save_cpo = &cpo +set cpo&vim + +" Functions {{{1 + +" This function can't be script-local, it doesn't work when recalculating. I +" don't know why that is. +function! FishProfileFoldExpr(lnum) + let len = strlen(matchstr(getline(a:lnum), '\d*\t\d*\t\zs-*>')) + return len ? '>'.len : '=' +endfunction + +" This function can't be script-local, apparently that just doesn't work. +function! FishProfileFoldText(foldstart, foldend) " {{{ + let line = getline(a:foldstart) + + " expand tabs into spaces + while 1 + let idx = stridx(line, "\t") + if idx == -1 + break + endif + let width = strdisplaywidth("\t", idx) + let line = strpart(line, 0, idx) . repeat(" ", width) . line[idx+1:] + endwhile + + let numlines = a:foldend - a:foldstart + 1 + return line . '… (' . numlines . ')' +endfunction " }}} + +" Variables {{{1 + +setlocal foldmethod=expr +setlocal foldexpr=FishProfileFoldExpr(v:lnum) +setlocal foldlevel=0 +setlocal foldtext=FishProfileFoldText(v:foldstart,v:foldend) + +setlocal tabstop=8 + +" }}}1 + +" Cleanup {{{1 + +let b:undo_ftplugin = " + \ setlocal foldexpr< foldmethod< foldlevel< foldtext< tabstop< + \|delfunction FishProfileFoldExpr + \|delfunction FishProfileFoldText + \" + +" }}}1 + +let &cpo = s:save_cpo +unlet s:save_cpo + +" vim: set noet sw=4 ts=4 sts=4: From 41f8e71c6cb4533a856d0c29740c4be83ffa92aa Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Mon, 14 Jul 2014 00:42:12 -0700 Subject: [PATCH 2/2] Define b:undo_ftplugin and fix b:match_words Clean up the ftplugin a bit. Use the save_cpo pattern to ensure cpo is set appropriately, and define a b:undo_ftplugin. Change the b:match_words definition to match else/else if. --- ftplugin/fish.vim | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/ftplugin/fish.vim b/ftplugin/fish.vim index 7c2ddf3..d9467ff 100644 --- a/ftplugin/fish.vim +++ b/ftplugin/fish.vim @@ -1,3 +1,11 @@ +if exists('b:did_ftplugin') + finish +end +let b:did_ftplugin = 1 + +let s:save_cpo = &cpo +set cpo&vim + setlocal comments=:# setlocal commentstring=#%s setlocal define=\\v^\\s*function> @@ -31,9 +39,20 @@ endif " argument to fish instead of man. execute 'setlocal keywordprg=fish\ '.expand(':p:h:h').'/bin/man.fish' -let b:match_words = - \ escape('<%(begin|function|if|switch|while|for)>:', '<>%|)') +let b:match_words = escape( + \'<%(begin|function|%(else\s\+)\@:::' + \, '<>%|)') let b:endwise_addition = 'end' let b:endwise_words = 'begin,function,if,switch,while,for' let b:endwise_syngroups = 'fishKeyword,fishConditional,fishRepeat' + +let b:undo_ftplugin = " + \ setlocal comments< commentstring< define< foldexpr< formatoptions< + \|setlocal include< iskeyword< suffixesadd< + \|setlocal formatexpr< omnifunc< path< keywordprg< + \|unlet! b:match_words b:endwise_addition b:endwise_words b:endwise_syngroups + \" + +let &cpo = s:save_cpo +unlet s:save_cpo