Add fish syntax, closes #109

This commit is contained in:
Adam Stankiewicz 2016-05-02 10:46:45 +02:00
parent 76d23a21e6
commit 905031eb95
No known key found for this signature in database
GPG Key ID: A62480DCEAC884DF
8 changed files with 189 additions and 0 deletions

View File

@ -44,6 +44,7 @@ Optionally download one of the [releases](https://github.com/sheerun/vim-polyglo
- [emberscript](https://github.com/heartsentwined/vim-ember-script) (syntax, indent, ftplugin, ftdetect)
- [emblem](https://github.com/heartsentwined/vim-emblem) (syntax, indent, ftplugin, ftdetect)
- [erlang](https://github.com/vim-erlang/vim-erlang-runtime) (syntax, indent, ftdetect)
- [fish](https://github.com/dag/vim-fish) (syntax, indent, compiler, autoload, ftplugin, ftdetect)
- [git](https://github.com/tpope/vim-git) (syntax, indent, ftplugin, ftdetect)
- [glsl](https://github.com/tikhomirov/vim-glsl) (syntax, indent, ftdetect)
- [go](https://github.com/fatih/vim-go) (syntax, compiler, indent, ftdetect)

70
autoload/fish.vim Normal file
View File

@ -0,0 +1,70 @@
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'fish') == -1
function! fish#Indent()
let l:prevlnum = prevnonblank(v:lnum - 1)
if l:prevlnum ==# 0
return 0
endif
let l:indent = 0
let l:prevline = getline(l:prevlnum)
if l:prevline =~# '\v^\s*switch>'
let l:indent = &shiftwidth * 2
elseif l:prevline =~# '\v^\s*%(begin|if|else|while|for|function|case)>'
let l:indent = &shiftwidth
endif
let l:line = getline(v:lnum)
if l:line =~# '\v^\s*end>'
return indent(v:lnum) - (l:indent ==# 0 ? &shiftwidth : l:indent)
elseif l:line =~# '\v^\s*%(case|else)>'
return indent(v:lnum) - &shiftwidth
endif
return indent(l:prevlnum) + l:indent
endfunction
function! fish#Format()
if mode() =~# '\v^%(i|R)$'
return 1
else
let l:command = v:lnum.','.(v:lnum+v:count-1).'!fish_indent'
echo l:command
execute l:command
endif
endfunction
function! fish#Fold()
let l:line = getline(v:lnum)
if l:line =~# '\v^\s*%(begin|if|while|for|function|switch)>'
return 'a1'
elseif l:line =~# '\v^\s*end>'
return 's1'
else
return '='
end
endfunction
function! fish#Complete(findstart, base)
if a:findstart
return getline('.') =~# '\v^\s*$' ? -1 : 0
else
if empty(a:base)
return []
endif
let l:results = []
let l:completions =
\ system('fish -c "complete -C'.shellescape(a:base).'"')
let l:cmd = substitute(a:base, '\v\S+$', '', '')
for l:line in split(l:completions, '\n')
let l:tokens = split(l:line, '\t')
call add(l:results, {'word': l:cmd.l:tokens[0],
\'abbr': l:tokens[0],
\'menu': get(l:tokens, 1, '')})
endfor
return l:results
endif
endfunction
function! fish#errorformat()
return '%Afish: %m,%-G%*\\ ^,%-Z%f (line %l):%s'
endfunction
endif

1
build
View File

@ -115,6 +115,7 @@ PACKS="
emberscript:heartsentwined/vim-ember-script
emblem:heartsentwined/vim-emblem
erlang:vim-erlang/vim-erlang-runtime
fish:dag/vim-fish
git:tpope/vim-git
glsl:tikhomirov/vim-glsl
go:fatih/vim-go:_BASIC

11
compiler/fish.vim Normal file
View File

@ -0,0 +1,11 @@
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'fish') == -1
if exists('current_compiler')
finish
endif
let current_compiler = 'fish'
CompilerSet makeprg=fish\ --no-execute\ %
execute 'CompilerSet errorformat='.escape(fish#errorformat(), ' ')
endif

View File

@ -105,6 +105,22 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'erlang') == -1
au BufNewFile,BufRead *.erl,*.hrl,rebar.config,*.app,*.app.src,*.yaws,*.xrl set ft=erlang
endif
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'fish') == -1
autocmd BufRead,BufNewFile *.fish setfiletype fish
autocmd BufRead *
\ if getline(1) =~# '\v^#!%(\f*/|/usr/bin/env\s*<)fish>' |
\ setlocal filetype=fish |
\ endif
autocmd BufRead fish_funced_*_*.fish call search('^$')
autocmd BufRead,BufNewFile ~/.config/fish/fish_{read_,}history setfiletype yaml
autocmd BufRead,BufNewFile ~/.config/fish/fishd.* setlocal readonly
autocmd BufNewFile ~/.config/fish/functions/*.fish
\ call append(0, ['function '.expand('%:t:r'),
\'',
\'end']) |
\ 2
endif
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'git') == -1
autocmd BufNewFile,BufRead *.git/{,modules/**/,worktrees/*/}{COMMIT_EDIT,TAG_EDIT,MERGE_,}MSG set ft=gitcommit

43
ftplugin/fish.vim Normal file
View File

@ -0,0 +1,43 @@
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'fish') == -1
setlocal comments=:#
setlocal commentstring=#%s
setlocal define=\\v^\\s*function>
setlocal foldexpr=fish#Fold()
setlocal formatoptions+=ron1
setlocal formatoptions-=t
setlocal include=\\v^\\s*\\.>
setlocal iskeyword=@,48-57,-,_,.,/
setlocal suffixesadd^=.fish
" Use the 'j' format option when available.
if v:version ># 703 || v:version ==# 703 && has('patch541')
setlocal formatoptions+=j
endif
if executable('fish_indent')
setlocal formatexpr=fish#Format()
endif
if executable('fish')
setlocal omnifunc=fish#Complete
for s:path in split(system("fish -c 'echo $fish_function_path'"))
execute 'setlocal path+='.s:path
endfor
else
setlocal omnifunc=syntaxcomplete#Complete
endif
" Use the 'man' wrapper function in fish to include fish's man pages.
" Have to use a script for this; 'fish -c man' would make the the man page an
" 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:endwise_addition = 'end'
let b:endwise_words = 'begin,function,if,switch,while,for'
let b:endwise_syngroups = 'fishKeyword,fishConditional,fishRepeat'
endif

6
indent/fish.vim Normal file
View File

@ -0,0 +1,6 @@
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'fish') == -1
setlocal indentexpr=fish#Indent()
setlocal indentkeys+==end,=else,=case
endif

41
syntax/fish.vim Normal file
View File

@ -0,0 +1,41 @@
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'fish') == -1
if exists('b:current_syntax')
finish
endif
syntax case match
syntax keyword fishKeyword begin function end
syntax keyword fishConditional if else switch
syntax keyword fishRepeat while for in
syntax keyword fishLabel case
syntax match fishComment /#.*/
syntax match fishSpecial /\\$/
syntax match fishIdentifier /\$[[:alnum:]_]\+/
syntax region fishString start=/'/ skip=/\\'/ end=/'/
syntax region fishString start=/"/ skip=/\\"/ end=/"/ contains=fishIdentifier
syntax match fishCharacter /\v\\[abefnrtv *?~%#(){}\[\]<>&;"']|\\[xX][0-9a-f]{1,2}|\\o[0-7]{1,2}|\\u[0-9a-f]{1,4}|\\U[0-9a-f]{1,8}|\\c[a-z]/
syntax match fishStatement /\v;\s*\zs\k+>/
syntax match fishCommandSub /\v\(\s*\zs\k+>/
syntax region fishLineContinuation matchgroup=fishStatement
\ start='\v^\s*\zs\k+>' skip='\\$' end='$'
\ contains=fishSpecial,fishIdentifier,fishString,fishCharacter,fishStatement,fishCommandSub
highlight default link fishKeyword Keyword
highlight default link fishConditional Conditional
highlight default link fishRepeat Repeat
highlight default link fishLabel Label
highlight default link fishComment Comment
highlight default link fishSpecial Special
highlight default link fishIdentifier Identifier
highlight default link fishString String
highlight default link fishCharacter Character
highlight default link fishStatement Statement
highlight default link fishCommandSub fishStatement
let b:current_syntax = 'fish'
endif