summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Stankiewicz <sheerun@sher.pl>2016-05-02 10:46:45 +0200
committerAdam Stankiewicz <sheerun@sher.pl>2016-05-02 10:46:45 +0200
commit905031eb9536adb38d793c1ced6d61057d3ca456 (patch)
tree97f9b716b7db05d5c454997acf33a05678e5dfe4
parent76d23a21e6904b1c09ddad1cb3fa769bbfe17991 (diff)
downloadvim-polyglot-905031eb9536adb38d793c1ced6d61057d3ca456.tar.gz
vim-polyglot-905031eb9536adb38d793c1ced6d61057d3ca456.zip
Add fish syntax, closes #109
-rw-r--r--README.md1
-rw-r--r--autoload/fish.vim70
-rwxr-xr-xbuild1
-rw-r--r--compiler/fish.vim11
-rw-r--r--ftdetect/polyglot.vim16
-rw-r--r--ftplugin/fish.vim43
-rw-r--r--indent/fish.vim6
-rw-r--r--syntax/fish.vim41
8 files changed, 189 insertions, 0 deletions
diff --git a/README.md b/README.md
index 57bca0c0..1d4ba3f4 100644
--- a/README.md
+++ b/README.md
@@ -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)
diff --git a/autoload/fish.vim b/autoload/fish.vim
new file mode 100644
index 00000000..ac422a42
--- /dev/null
+++ b/autoload/fish.vim
@@ -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
diff --git a/build b/build
index 445208ea..83019237 100755
--- a/build
+++ b/build
@@ -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
diff --git a/compiler/fish.vim b/compiler/fish.vim
new file mode 100644
index 00000000..11fad0c6
--- /dev/null
+++ b/compiler/fish.vim
@@ -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
diff --git a/ftdetect/polyglot.vim b/ftdetect/polyglot.vim
index 1b7746d4..da43539c 100644
--- a/ftdetect/polyglot.vim
+++ b/ftdetect/polyglot.vim
@@ -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
diff --git a/ftplugin/fish.vim b/ftplugin/fish.vim
new file mode 100644
index 00000000..f365208a
--- /dev/null
+++ b/ftplugin/fish.vim
@@ -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
diff --git a/indent/fish.vim b/indent/fish.vim
new file mode 100644
index 00000000..c5f8e50e
--- /dev/null
+++ b/indent/fish.vim
@@ -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
diff --git a/syntax/fish.vim b/syntax/fish.vim
new file mode 100644
index 00000000..ff2faeac
--- /dev/null
+++ b/syntax/fish.vim
@@ -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