Skip to content

Commit

Permalink
Small improvements.
Browse files Browse the repository at this point in the history
- funced and fish_indent always uses tabs for indentation, use
  fish#Indent() to fix it. Works better with the improved fish#Indent().
- ftdetect should contain filetype detection code. Move autocmds to
  plugin/fish.vim.
- Match new funced temp file name.
- Add "else", "else if" and "case" to b:match_words to follow what's
  used by Vim's ftplugins.

blankname:
- dropped the syntax changes (cc: dag#28)

Co-authored-by: blankname <>
  • Loading branch information
Raimondi authored and blank_name committed Jan 5, 2020
1 parent 5af7761 commit b005e8c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
2 changes: 2 additions & 0 deletions autoload/fish.vim
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ function! fish#Format()
let l:command = v:lnum.','.(v:lnum+v:count-1).'!fish_indent'
echo l:command
execute l:command
" Fix indentation and replace tabs with spaces if necessary.
normal! '[=']
endif
endfunction

Expand Down
19 changes: 6 additions & 13 deletions ftdetect/fish.vim
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
autocmd BufRead,BufNewFile *.fish setfiletype fish

" Set filetype when using funced.
autocmd BufRead fish_funced.* setfiletype fish

" Fish histories are YAML documents.
autocmd BufRead,BufNewFile ~/.config/fish/fish_{read_,}history setfiletype yaml

" Detect fish scripts by the shebang line.
autocmd BufRead *
\ if getline(1) =~# '\v^#!%(\f*/|/usr/bin/env\s*<)fish>' |
\ setlocal filetype=fish |
\ endif

" Move cursor to first empty line when using funced.
autocmd BufRead fish_funced_*_*.fish call search('^$')

" Fish histories are YAML documents.
autocmd BufRead,BufNewFile ~/.config/fish/fish_{read_,}history setfiletype yaml

" Universal variable storages should not be hand edited.
autocmd BufRead,BufNewFile ~/.config/fish/fishd.* setlocal readonly

" Mimic `funced` when manually creating functions.
autocmd BufNewFile ~/.config/fish/functions/*.fish
\ call setline(1, ['function '.expand('%:t:r'), '', 'end']) | 2
9 changes: 8 additions & 1 deletion ftplugin/fish.vim
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,15 @@ endif
" argument to fish instead of man.
execute 'setlocal keywordprg=fish\ '.fnameescape(expand('<sfile>:p:h:h').'/bin/man.fish')

let b:match_ignorecase = 0
if has('patch-7.3.1037')
let s:if = '%(else\s\+)\@15<!if'
else
let s:if = '%(else\s\+)\@<!if'
endif

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

let b:endwise_addition = 'end'
Expand Down
14 changes: 14 additions & 0 deletions plugin/fish.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
if get(g:, 'loaded_fish', 0)
finish
endif
let loaded_fish = 1

" Universal variable storages should not be hand edited.
autocmd BufRead,BufNewFile ~/.config/fish/fishd.* setlocal readonly

" Move cursor to first empty line when using funced.
autocmd BufRead fish_funced.* exec "normal! gg=G" | call search('^\s*\zs$')

" Mimic `funced` when manually creating functions.
autocmd BufNewFile ~/.config/fish/functions/*.fish
\ call setline(1, ['function '.expand('%:t:r'), '', 'end']) | 2

0 comments on commit b005e8c

Please sign in to comment.