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

Small improvements. #28

Open
wants to merge 1 commit 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
2 changes: 2 additions & 0 deletions autoload/fish.vim
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,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! '[=']
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably use :retab for this. Why do you feel you need to fix the indentation of the output from the program that is made for fixing indentation? Does it get something wrong?

endif
endfunction

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

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should maybe try to keep support for old-style funced file names too.


" 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 append(0, ['function '.expand('%:t:r'),
\'',
\'end']) |
\ 2
10 changes: 9 additions & 1 deletion ftplugin/fish.vim
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,16 @@ endif
" argument to fish instead of man.
execute 'setlocal keywordprg=fish\ '.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|if|switch|while|for)>:<end>', '<>%|)')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason you dropped this use of escape? I think it's more readable.

\ '\<\%(begin\|function\|'.s:if.'\|switch\|while\|for\)\>'
\.':\<\%(else\%(\s*if\)\?\|case\)\>:\<end\>'

let b:endwise_addition = 'end'
let b:endwise_words = 'begin,function,if,switch,while,for'
Expand Down
17 changes: 17 additions & 0 deletions plugin/fish.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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$')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you forcing a reindent here?


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason for preferring setline over append here?

\'',
\'end']) |
\ 2
3 changes: 3 additions & 0 deletions syntax/fish.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ if exists('b:current_syntax')
finish
endif

syntax sync clear
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be necessary in a syntax file.

syntax sync fromstart
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? It can be slow for large files, or Vim would just do it by default for all filetypes. It should only really be used for things like heredocs, which last I checked fish didn't have, but I guess it has multiline strings that can be used similarly. But how often do you have strings span more than a few lines? Do you really need to sync all the way from start?


syntax case match

syntax keyword fishKeyword begin function end
Expand Down