Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define b:undo_ftplugin and fix b:match_words #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions ftplugin/fish.vim
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -31,9 +39,20 @@ endif
" argument to fish instead of man.
execute 'setlocal keywordprg=fish\ '.expand('<sfile>:p:h:h').'/bin/man.fish'

let b:match_words =
\ escape('<%(begin|function|if|switch|while|for)>:<end>', '<>%|)')
let b:match_words = escape(
\'<%(begin|function|%(else\s\+)\@<!if|switch|while|for)>:<else\s\+if>:<else>:<end>'
\, '<>%|)')

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
65 changes: 65 additions & 0 deletions ftplugin/fishprofile.vim
Original file line number Diff line number Diff line change
@@ -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: