From d27aa86af0452ebe69453ef0d0aba4c3a5b4e2a9 Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Thu, 24 Jun 2021 17:51:28 +0300 Subject: [PATCH] [nvim] add bangs and aborts to every Vimscript function --- nvim/autoload/airline/themes/dotfiles.vim | 2 +- nvim/colors/dotfiles.vim | 4 ++-- nvim/plugin/completion.vim | 6 +++--- nvim/plugin/editing.vim | 6 +++--- nvim/plugin/files.vim | 24 +++++++++++------------ nvim/plugin/interface.vim | 4 ++-- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/nvim/autoload/airline/themes/dotfiles.vim b/nvim/autoload/airline/themes/dotfiles.vim index 0f7805f..a1ebe81 100644 --- a/nvim/autoload/airline/themes/dotfiles.vim +++ b/nvim/autoload/airline/themes/dotfiles.vim @@ -9,7 +9,7 @@ let s:palette = { \ } let s:colors = g:dotfiles_colorscheme_base16_colors -function! s:base16_color(fg, bg) +function! s:base16_color(fg, bg) abort let fg = s:colors[a:fg] let bg = s:colors[a:bg] return [fg.gui, bg.gui, fg.cterm, bg.cterm] diff --git a/nvim/colors/dotfiles.vim b/nvim/colors/dotfiles.vim index a9f7751..22ada40 100644 --- a/nvim/colors/dotfiles.vim +++ b/nvim/colors/dotfiles.vim @@ -21,12 +21,12 @@ " }}} " The highlighting function {{{ - function s:is_number(value) + function! s:is_number(value) abort return type(a:value) == v:t_number endfunction let s:colors = g:dotfiles_colorscheme_base16_colors - function s:hi(group, fg, bg, attr, sp) + function! s:hi(group, fg, bg, attr, sp) abort let fg = {} let bg = {} let attr = 'NONE' diff --git a/nvim/plugin/completion.vim b/nvim/plugin/completion.vim index 2789e40..894e52c 100644 --- a/nvim/plugin/completion.vim +++ b/nvim/plugin/completion.vim @@ -6,7 +6,7 @@ " }}} if !g:vim_ide - function IsCocEnabled() + function! IsCocEnabled() abort return 0 endfunction finish @@ -17,7 +17,7 @@ endif " coc mappings are enabled let g:coc_filetypes = [] - function IsCocEnabled() + function! IsCocEnabled() abort return index(g:coc_filetypes, &filetype) >= 0 endfunction @@ -64,7 +64,7 @@ endif " }}} " CocFormat {{{ - function s:CocFormat(range, line1, line2) abort + function! s:CocFormat(range, line1, line2) abort if a:range == 0 call CocAction('format') else diff --git a/nvim/plugin/editing.vim b/nvim/plugin/editing.vim index bf4ece6..f5f5336 100644 --- a/nvim/plugin/editing.vim +++ b/nvim/plugin/editing.vim @@ -12,7 +12,7 @@ set commentstring=//%s " Indentination {{{ - function SetIndent(expandtab, shiftwidth) + function! SetIndent(expandtab, shiftwidth) abort let &l:expandtab = a:expandtab let &l:shiftwidth = str2nr(a:shiftwidth) let &l:tabstop = &l:shiftwidth @@ -78,7 +78,7 @@ set commentstring=//%s nmap ] m'yygccp`'j nmap [ m'yygccP`'k - function! PutOutput(cmd) + function! PutOutput(cmd) abort let output = execute(a:cmd) execute "noswapfile pedit" "+" . fnameescape("setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile") fnameescape("preview://" . a:cmd) wincmd P @@ -179,7 +179,7 @@ set commentstring=//%s xnoremap ? ?\%>=line("'<")-1l\%<=line("'>")+1l " * and # in the Visual mode will search the selected text - function! s:VisualStarSearch(search_cmd) + function! s:VisualStarSearch(search_cmd) abort let tmp = @" normal! y let @/ = '\V' . substitute(escape(@", a:search_cmd . '\'), '\n', '\\n', 'g') diff --git a/nvim/plugin/files.vim b/nvim/plugin/files.vim index 2d8e228..386d16c 100644 --- a/nvim/plugin/files.vim +++ b/nvim/plugin/files.vim @@ -23,13 +23,13 @@ nnoremap empty(&buftype) ? ":writewall\" : "\" nnoremap / :grep - function! s:grep_mapping_star_normal() + function! s:grep_mapping_star_normal() abort let word = expand("") if !empty(word) call feedkeys(":\grep " . shellescape('\b' . word . '\b', 1), 'n') endif endfunction - function! s:grep_mapping_star_visual() + function! s:grep_mapping_star_visual() abort let tmp = @" normal! y call feedkeys(":\grep " . shellescape(@", 1), 'n') @@ -71,7 +71,7 @@ nnoremap empty(&buftype) ? ":writewall\" : "\" " DiffWithSaved {{{ " Compare current buffer with the actual (saved) file on disk - function s:DiffWithSaved() + function! s:DiffWithSaved() abort let filetype = &filetype diffthis vnew | read # | normal! ggdd @@ -84,7 +84,7 @@ nnoremap empty(&buftype) ? ":writewall\" : "\" " Reveal {{{ " Reveal file in the system file explorer - function s:Reveal(path) + function! s:Reveal(path) abort if has('macunix') " only macOS has functionality to really 'reveal' a file, that is, to open " its parent directory in Finder and select this file @@ -101,7 +101,7 @@ nnoremap empty(&buftype) ? ":writewall\" : "\" " Open {{{ " opens file or URL with a system program - function s:Open(path) + function! s:Open(path) abort " HACK: 2nd parameter of this function is called 'remote', it tells " whether to open a remote (1) or local (0) file. However, it doesn't work " as expected in this context, because it uses the 'gf' command if it's @@ -119,7 +119,7 @@ nnoremap empty(&buftype) ? ":writewall\" : "\" " Yes, I know about the existence of :args, however it modifies the " argument list, so it doesn't play well with Obsession.vim because it " saves the argument list in the session file. - function s:EditGlob(...) + function! s:EditGlob(...) abort for glob in a:000 for name in glob(glob, 0, 1) execute 'edit' fnameescape(name) @@ -131,7 +131,7 @@ nnoremap empty(&buftype) ? ":writewall\" : "\" " DragOut {{{ " Shows a window for draging (-and-dropping) the currently opened file out. - function s:DragOut(path) + function! s:DragOut(path) abort if empty(a:path) | return | endif if !executable('dragon-drag-and-drop') echoerr "Please install for the DragOut command to work." @@ -148,13 +148,13 @@ nnoremap empty(&buftype) ? ":writewall\" : "\" " on save (BufWritePre) {{{ - function s:IsUrl(str) + function! s:IsUrl(str) abort return a:str =~# '\v^\w+://' endfunction " create directory {{{ " Creates the parent directory of the file if it doesn't exist - function s:CreateDirOnSave() + function! s:CreateDirOnSave() abort let file = expand('') " check if this is a regular file and its path is not a URL if empty(&buftype) && !s:IsUrl(file) @@ -165,7 +165,7 @@ nnoremap empty(&buftype) ? ":writewall\" : "\" " }}} " fix whitespace {{{ - function s:FixWhitespaceOnSave() + function! s:FixWhitespaceOnSave() abort let pos = getpos('.') " remove trailing whitespace keeppatterns %s/\s\+$//e @@ -177,7 +177,7 @@ nnoremap empty(&buftype) ? ":writewall\" : "\" " auto-format with Coc.nvim {{{ let g:coc_format_on_save_ignore = [] - function s:FormatOnSave() + function! s:FormatOnSave() abort let file = expand('') if IsCocEnabled() && !s:IsUrl(file) && index(g:coc_format_on_save_ignore, &filetype) < 0 silent CocFormat @@ -185,7 +185,7 @@ nnoremap empty(&buftype) ? ":writewall\" : "\" endfunction " }}} - function s:OnSave() + function! s:OnSave() abort call s:FixWhitespaceOnSave() call s:FormatOnSave() call s:CreateDirOnSave() diff --git a/nvim/plugin/interface.vim b/nvim/plugin/interface.vim index 769871c..eceb3c3 100644 --- a/nvim/plugin/interface.vim +++ b/nvim/plugin/interface.vim @@ -40,7 +40,7 @@ endif set confirm " Bbye with confirmation, or fancy buffer closer {{{ - function s:CloseBuffer(cmd) abort + function! s:CloseBuffer(cmd) abort let cmd = a:cmd if &modified " @@ -141,7 +141,7 @@ endif " Based on , inspired by " . " But apparently `vimgrep /pattern/ %` can be used instead? - function! s:CmdGlobal(pattern, bang) + function! s:CmdGlobal(pattern, bang) abort let pattern = substitute(a:pattern, "/.*$", "", "") let matches = [] execute "g" . (a:bang ? "!" : "") . "/" . pattern . "/call add(matches, expand(\"%\").\":\".line(\".\").\":\".col(\".\").\":\".getline(\".\"))"