Skip to content

Commit b005e8c

Browse files
Raimondiblank_name
authored andcommitted
Small improvements.
- 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 <>
1 parent 5af7761 commit b005e8c

4 files changed

Lines changed: 30 additions & 14 deletions

File tree

autoload/fish.vim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ function! fish#Format()
113113
let l:command = v:lnum.','.(v:lnum+v:count-1).'!fish_indent'
114114
echo l:command
115115
execute l:command
116+
" Fix indentation and replace tabs with spaces if necessary.
117+
normal! '[=']
116118
endif
117119
endfunction
118120

ftdetect/fish.vim

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
autocmd BufRead,BufNewFile *.fish setfiletype fish
22

3+
" Set filetype when using funced.
4+
autocmd BufRead fish_funced.* setfiletype fish
5+
6+
" Fish histories are YAML documents.
7+
autocmd BufRead,BufNewFile ~/.config/fish/fish_{read_,}history setfiletype yaml
8+
39
" Detect fish scripts by the shebang line.
410
autocmd BufRead *
511
\ if getline(1) =~# '\v^#!%(\f*/|/usr/bin/env\s*<)fish>' |
612
\ setlocal filetype=fish |
713
\ endif
8-
9-
" Move cursor to first empty line when using funced.
10-
autocmd BufRead fish_funced_*_*.fish call search('^$')
11-
12-
" Fish histories are YAML documents.
13-
autocmd BufRead,BufNewFile ~/.config/fish/fish_{read_,}history setfiletype yaml
14-
15-
" Universal variable storages should not be hand edited.
16-
autocmd BufRead,BufNewFile ~/.config/fish/fishd.* setlocal readonly
17-
18-
" Mimic `funced` when manually creating functions.
19-
autocmd BufNewFile ~/.config/fish/functions/*.fish
20-
\ call setline(1, ['function '.expand('%:t:r'), '', 'end']) | 2

ftplugin/fish.vim

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,15 @@ endif
3939
" argument to fish instead of man.
4040
execute 'setlocal keywordprg=fish\ '.fnameescape(expand('<sfile>:p:h:h').'/bin/man.fish')
4141

42+
let b:match_ignorecase = 0
43+
if has('patch-7.3.1037')
44+
let s:if = '%(else\s\+)\@15<!if'
45+
else
46+
let s:if = '%(else\s\+)\@<!if'
47+
endif
48+
4249
let b:match_words = escape(
43-
\'<%(begin|function|%(else\s\+)\@<!if|switch|while|for)>:<else\s\+if>:<else>:<end>'
50+
\'<%(begin|function|'.s:if.'|switch|while|for)>:<else\s\+if|case>:<else>:<end>'
4451
\, '<>%|)')
4552

4653
let b:endwise_addition = 'end'

plugin/fish.vim

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
if get(g:, 'loaded_fish', 0)
2+
finish
3+
endif
4+
let loaded_fish = 1
5+
6+
" Universal variable storages should not be hand edited.
7+
autocmd BufRead,BufNewFile ~/.config/fish/fishd.* setlocal readonly
8+
9+
" Move cursor to first empty line when using funced.
10+
autocmd BufRead fish_funced.* exec "normal! gg=G" | call search('^\s*\zs$')
11+
12+
" Mimic `funced` when manually creating functions.
13+
autocmd BufNewFile ~/.config/fish/functions/*.fish
14+
\ call setline(1, ['function '.expand('%:t:r'), '', 'end']) | 2

0 commit comments

Comments
 (0)