[nvim] apparently usage of l: inside functions is entirely optional

This commit is contained in:
Dmytro Meleshko 2021-03-30 01:22:56 +03:00
parent f9127d6ce2
commit 3d34200ac6
7 changed files with 73 additions and 73 deletions

View file

@ -10,9 +10,9 @@ let s:palette = {
let s:colors = g:dotfiles_colorscheme_base16_colors let s:colors = g:dotfiles_colorscheme_base16_colors
function! s:base16_color(fg, bg) function! s:base16_color(fg, bg)
let l:fg = s:colors[a:fg] let fg = s:colors[a:fg]
let l:bg = s:colors[a:bg] let bg = s:colors[a:bg]
return [l:fg.gui, l:bg.gui, l:fg.cterm, l:bg.cterm] return [fg.gui, bg.gui, fg.cterm, bg.cterm]
endfunction endfunction
let s:section_a = s:base16_color(0x1, 0xB) let s:section_a = s:base16_color(0x1, 0xB)

View file

@ -2,48 +2,48 @@
" A motion for moving over enclosing indentation blocks. Primarily intended " A motion for moving over enclosing indentation blocks. Primarily intended
" for reverse-engineering CrossCode. " for reverse-engineering CrossCode.
function dotfiles#indent_motion#run(direction) function dotfiles#indent_motion#run(direction) abort
let l:cursor_linenr = line(".") let cursor_linenr = line(".")
let l:max_linenr = line("$") let max_linenr = line("$")
let l:retry = 0 let retry = 0
while l:retry <# 2 while retry <# 2
let l:retry += 1 let retry += 1
let l:base_linenr = l:cursor_linenr let base_linenr = cursor_linenr
let l:base_indent = 0 let base_indent = 0
while 1 <=# l:base_linenr && l:base_linenr <=# l:max_linenr while 1 <=# base_linenr && base_linenr <=# max_linenr
let l:base_indent = dotfiles#indent_motion#indent_level_of(l:base_linenr) let base_indent = dotfiles#indent_motion#indent_level_of(base_linenr)
if l:base_indent >=# 0 if base_indent >=# 0
break break
endif endif
let l:base_linenr += a:direction let base_linenr += a:direction
endwhile endwhile
let l:target_linenr = l:base_linenr let target_linenr = base_linenr
let l:curr_linenr = l:base_linenr + a:direction let curr_linenr = base_linenr + a:direction
let l:prev_indent = l:base_indent let prev_indent = base_indent
while 1 <=# l:curr_linenr && l:curr_linenr <=# l:max_linenr while 1 <=# curr_linenr && curr_linenr <=# max_linenr
let l:indent = dotfiles#indent_motion#indent_level_of(l:curr_linenr) let indent = dotfiles#indent_motion#indent_level_of(curr_linenr)
if l:indent >=# 0 if indent >=# 0
if l:indent <# l:base_indent if indent <# base_indent
break break
else else
let l:target_linenr = l:curr_linenr let target_linenr = curr_linenr
endif endif
elseif l:base_indent ==# 0 && l:prev_indent ==# 0 elseif base_indent ==# 0 && prev_indent ==# 0
break break
endif endif
let l:prev_indent = l:indent let prev_indent = indent
let l:curr_linenr += a:direction let curr_linenr += a:direction
endwhile endwhile
if l:target_linenr ==# l:cursor_linenr if target_linenr ==# cursor_linenr
let l:cursor_linenr += a:direction let cursor_linenr += a:direction
if 1 <=# l:cursor_linenr && l:cursor_linenr <=# l:max_linenr if 1 <=# cursor_linenr && cursor_linenr <=# max_linenr
continue continue
endif endif
endif endif
@ -51,7 +51,7 @@ function dotfiles#indent_motion#run(direction)
break break
endwhile endwhile
execute "normal! " . l:target_linenr . "G^" execute "normal! " . target_linenr . "G^"
endfunction endfunction
" <https://github.com/kana/vim-textobj-indent/blob/deb76867c302f933c8f21753806cbf2d8461b548/autoload/textobj/indent.vim#L120-L127> " <https://github.com/kana/vim-textobj-indent/blob/deb76867c302f933c8f21753806cbf2d8461b548/autoload/textobj/indent.vim#L120-L127>

View file

@ -1,6 +1,6 @@
function dotfiles#utils#array_remove_element(array, element) function dotfiles#utils#array_remove_element(array, element)
let l:index = index(a:array, a:element) let index = index(a:array, a:element)
if l:index >= 0 if index >= 0
call remove(a:array, l:index) call remove(a:array, index)
endif endif
endfunction endfunction

View file

@ -24,23 +24,23 @@
let s:colors = g:dotfiles_colorscheme_base16_colors let s:colors = g:dotfiles_colorscheme_base16_colors
function s:hi(group, fg, bg, attr, guisp) function s:hi(group, fg, bg, attr, guisp)
let l:args = '' let args = ''
if a:fg isnot '' if a:fg isnot ''
let l:fg = s:is_number(a:fg) ? s:colors[a:fg] : {'gui': a:fg, 'cterm': a:fg} let fg = s:is_number(a:fg) ? s:colors[a:fg] : {'gui': a:fg, 'cterm': a:fg}
let l:args .= ' guifg=' . l:fg.gui . ' ctermfg=' . l:fg.cterm let args .= ' guifg=' . fg.gui . ' ctermfg=' . fg.cterm
endif endif
if a:bg isnot '' if a:bg isnot ''
let l:bg = s:is_number(a:bg) ? s:colors[a:bg] : {'gui': a:bg, 'cterm': a:bg} let bg = s:is_number(a:bg) ? s:colors[a:bg] : {'gui': a:bg, 'cterm': a:bg}
let l:args .= ' guibg=' . l:bg.gui . ' ctermbg=' . l:bg.cterm let args .= ' guibg=' . bg.gui . ' ctermbg=' . bg.cterm
endif endif
if a:attr isnot '' if a:attr isnot ''
let l:args .= ' gui=' . a:attr . ' cterm=' . a:attr let args .= ' gui=' . a:attr . ' cterm=' . a:attr
endif endif
if a:guisp isnot '' if a:guisp isnot ''
let l:guisp = s:is_number(a:guisp) ? s:colors[a:guisp].gui : a:guisp let guisp = s:is_number(a:guisp) ? s:colors[a:guisp].gui : a:guisp
let l:args .= ' guisp=' . l:guisp let args .= ' guisp=' . guisp
endif endif
exec 'hi' a:group l:args exec 'hi' a:group args
endfunction endfunction
" }}} " }}}

View file

@ -163,10 +163,10 @@ set commentstring=//%s
" * and # in the Visual mode will search the selected text " * and # in the Visual mode will search the selected text
function! s:VisualStarSearch(search_cmd) function! s:VisualStarSearch(search_cmd)
let l:tmp = @" let tmp = @"
normal! y normal! y
let @/ = '\V' . substitute(escape(@", a:search_cmd . '\'), '\n', '\\n', 'g') let @/ = '\V' . substitute(escape(@", a:search_cmd . '\'), '\n', '\\n', 'g')
let @" = l:tmp let @" = tmp
endfunction endfunction
" HACK: my mappings are added on VimEnter to override mappings from the " HACK: my mappings are added on VimEnter to override mappings from the
" vim-indexed-search plugin " vim-indexed-search plugin

View file

@ -52,12 +52,12 @@ nnoremap <silent><expr> <CR> empty(&buftype) ? ":write<bar>wall\<CR>" : "\<CR>"
" DiffWithSaved {{{ " DiffWithSaved {{{
" Compare current buffer with the actual (saved) file on disk " Compare current buffer with the actual (saved) file on disk
function s:DiffWithSaved() function s:DiffWithSaved()
let l:filetype = &filetype let filetype = &filetype
diffthis diffthis
vnew | read # | normal! ggdd vnew | read # | normal! ggdd
diffthis diffthis
setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile readonly nomodifiable setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile readonly nomodifiable
let &filetype = l:filetype let &filetype = filetype
endfunction endfunction
command DiffWithSaved call s:DiffWithSaved() command DiffWithSaved call s:DiffWithSaved()
" }}} " }}}
@ -100,9 +100,9 @@ nnoremap <silent><expr> <CR> empty(&buftype) ? ":write<bar>wall\<CR>" : "\<CR>"
" argument list, so it doesn't play well with Obsession.vim because it " argument list, so it doesn't play well with Obsession.vim because it
" saves the argument list in the session file. " saves the argument list in the session file.
function s:EditGlob(...) function s:EditGlob(...)
for l:glob in a:000 for glob in a:000
for l:name in glob(l:glob, 0, 1) for name in glob(glob, 0, 1)
execute 'edit' fnameescape(l:name) execute 'edit' fnameescape(name)
endfor endfor
endfor endfor
endfunction endfunction
@ -135,31 +135,31 @@ nnoremap <silent><expr> <CR> empty(&buftype) ? ":write<bar>wall\<CR>" : "\<CR>"
" create directory {{{ " create directory {{{
" Creates the parent directory of the file if it doesn't exist " Creates the parent directory of the file if it doesn't exist
function s:CreateDirOnSave() function s:CreateDirOnSave()
let l:file = expand('<afile>') let file = expand('<afile>')
" check if this is a regular file and its path is not a URL " check if this is a regular file and its path is not a URL
if empty(&buftype) && !s:IsUrl(l:file) if empty(&buftype) && !s:IsUrl(file)
let l:dir = fnamemodify(l:file, ':h') let dir = fnamemodify(file, ':h')
if !isdirectory(l:dir) | call mkdir(l:dir, 'p') | endif if !isdirectory(dir) | call mkdir(dir, 'p') | endif
endif endif
endfunction endfunction
" }}} " }}}
" fix whitespace {{{ " fix whitespace {{{
function s:FixWhitespaceOnSave() function s:FixWhitespaceOnSave()
let l:pos = getpos('.') let pos = getpos('.')
" remove trailing whitespace " remove trailing whitespace
keeppatterns %s/\s\+$//e keeppatterns %s/\s\+$//e
" remove trailing newlines " remove trailing newlines
keeppatterns %s/\($\n\s*\)\+\%$//e keeppatterns %s/\($\n\s*\)\+\%$//e
call setpos('.', l:pos) call setpos('.', pos)
endfunction endfunction
" }}} " }}}
" auto-format with Coc.nvim {{{ " auto-format with Coc.nvim {{{
let g:coc_format_on_save_ignore = [] let g:coc_format_on_save_ignore = []
function s:FormatOnSave() function s:FormatOnSave()
let l:file = expand('<afile>') let file = expand('<afile>')
if IsCocEnabled() && !s:IsUrl(l:file) && index(g:coc_format_on_save_ignore, &filetype) < 0 if IsCocEnabled() && !s:IsUrl(file) && index(g:coc_format_on_save_ignore, &filetype) < 0
silent CocFormat silent CocFormat
endif endif
endfunction endfunction

View file

@ -41,18 +41,18 @@ endif
" Bbye with confirmation, or fancy buffer closer {{{ " Bbye with confirmation, or fancy buffer closer {{{
function s:CloseBuffer(cmd) abort function s:CloseBuffer(cmd) abort
let l:cmd = a:cmd let cmd = a:cmd
if &modified if &modified
let l:answer = confirm("Save changes?", "&Yes\n&No\n&Cancel") let answer = confirm("Save changes?", "&Yes\n&No\n&Cancel")
if l:answer ==# 1 " Yes if answer ==# 1 " Yes
write write
elseif l:answer ==# 2 " No elseif answer ==# 2 " No
let l:cmd .= '!' let cmd .= '!'
else " Cancel/Other else " Cancel/Other
return return
endif endif
endif endif
execute l:cmd execute cmd
endfunction endfunction
" }}} " }}}
@ -108,19 +108,19 @@ endif
let g:airline#extensions#tabline#left_alt_sep = '' let g:airline#extensions#tabline#left_alt_sep = ''
function StatusLine_filesize() function StatusLine_filesize()
let l:bytes = getfsize(expand('%')) let bytes = getfsize(expand('%'))
if l:bytes < 0 | return '' | endif if bytes < 0 | return '' | endif
let l:factor = 1 let factor = 1
for l:unit in ['B', 'K', 'M', 'G'] for unit in ['B', 'K', 'M', 'G']
let l:next_factor = l:factor * 1024 let next_factor = factor * 1024
if l:bytes < l:next_factor if bytes < next_factor
let l:number_str = printf('%.2f', (l:bytes * 1.0) / l:factor) let number_str = printf('%.2f', (bytes * 1.0) / factor)
" remove trailing zeros " remove trailing zeros
let l:number_str = substitute(l:number_str, '\v\.?0+$', '', '') let number_str = substitute(number_str, '\v\.?0+$', '', '')
return l:number_str . l:unit return number_str . unit
endif endif
let l:factor = l:next_factor let factor = next_factor
endfor endfor
endfunction endfunction
call airline#parts#define('filesize', { 'function': 'StatusLine_filesize' }) call airline#parts#define('filesize', { 'function': 'StatusLine_filesize' })