mirror of
https://github.com/keanuplayz/dotfiles.git
synced 2024-08-15 02:33:12 +00:00
[nvim] apparently usage of l: inside functions is entirely optional
This commit is contained in:
parent
f9127d6ce2
commit
3d34200ac6
7 changed files with 73 additions and 73 deletions
|
@ -10,9 +10,9 @@ let s:palette = {
|
|||
|
||||
let s:colors = g:dotfiles_colorscheme_base16_colors
|
||||
function! s:base16_color(fg, bg)
|
||||
let l:fg = s:colors[a:fg]
|
||||
let l:bg = s:colors[a:bg]
|
||||
return [l:fg.gui, l:bg.gui, l:fg.cterm, l:bg.cterm]
|
||||
let fg = s:colors[a:fg]
|
||||
let bg = s:colors[a:bg]
|
||||
return [fg.gui, bg.gui, fg.cterm, bg.cterm]
|
||||
endfunction
|
||||
|
||||
let s:section_a = s:base16_color(0x1, 0xB)
|
||||
|
|
|
@ -2,48 +2,48 @@
|
|||
" A motion for moving over enclosing indentation blocks. Primarily intended
|
||||
" for reverse-engineering CrossCode.
|
||||
|
||||
function dotfiles#indent_motion#run(direction)
|
||||
let l:cursor_linenr = line(".")
|
||||
let l:max_linenr = line("$")
|
||||
function dotfiles#indent_motion#run(direction) abort
|
||||
let cursor_linenr = line(".")
|
||||
let max_linenr = line("$")
|
||||
|
||||
let l:retry = 0
|
||||
while l:retry <# 2
|
||||
let l:retry += 1
|
||||
let retry = 0
|
||||
while retry <# 2
|
||||
let retry += 1
|
||||
|
||||
let l:base_linenr = l:cursor_linenr
|
||||
let l:base_indent = 0
|
||||
while 1 <=# l:base_linenr && l:base_linenr <=# l:max_linenr
|
||||
let l:base_indent = dotfiles#indent_motion#indent_level_of(l:base_linenr)
|
||||
if l:base_indent >=# 0
|
||||
let base_linenr = cursor_linenr
|
||||
let base_indent = 0
|
||||
while 1 <=# base_linenr && base_linenr <=# max_linenr
|
||||
let base_indent = dotfiles#indent_motion#indent_level_of(base_linenr)
|
||||
if base_indent >=# 0
|
||||
break
|
||||
endif
|
||||
let l:base_linenr += a:direction
|
||||
let base_linenr += a:direction
|
||||
endwhile
|
||||
|
||||
let l:target_linenr = l:base_linenr
|
||||
let target_linenr = base_linenr
|
||||
|
||||
let l:curr_linenr = l:base_linenr + a:direction
|
||||
let l:prev_indent = l:base_indent
|
||||
while 1 <=# l:curr_linenr && l:curr_linenr <=# l:max_linenr
|
||||
let l:indent = dotfiles#indent_motion#indent_level_of(l:curr_linenr)
|
||||
let curr_linenr = base_linenr + a:direction
|
||||
let prev_indent = base_indent
|
||||
while 1 <=# curr_linenr && curr_linenr <=# max_linenr
|
||||
let indent = dotfiles#indent_motion#indent_level_of(curr_linenr)
|
||||
|
||||
if l:indent >=# 0
|
||||
if l:indent <# l:base_indent
|
||||
if indent >=# 0
|
||||
if indent <# base_indent
|
||||
break
|
||||
else
|
||||
let l:target_linenr = l:curr_linenr
|
||||
let target_linenr = curr_linenr
|
||||
endif
|
||||
elseif l:base_indent ==# 0 && l:prev_indent ==# 0
|
||||
elseif base_indent ==# 0 && prev_indent ==# 0
|
||||
break
|
||||
endif
|
||||
|
||||
let l:prev_indent = l:indent
|
||||
let l:curr_linenr += a:direction
|
||||
let prev_indent = indent
|
||||
let curr_linenr += a:direction
|
||||
endwhile
|
||||
|
||||
if l:target_linenr ==# l:cursor_linenr
|
||||
let l:cursor_linenr += a:direction
|
||||
if 1 <=# l:cursor_linenr && l:cursor_linenr <=# l:max_linenr
|
||||
if target_linenr ==# cursor_linenr
|
||||
let cursor_linenr += a:direction
|
||||
if 1 <=# cursor_linenr && cursor_linenr <=# max_linenr
|
||||
continue
|
||||
endif
|
||||
endif
|
||||
|
@ -51,7 +51,7 @@ function dotfiles#indent_motion#run(direction)
|
|||
break
|
||||
endwhile
|
||||
|
||||
execute "normal! " . l:target_linenr . "G^"
|
||||
execute "normal! " . target_linenr . "G^"
|
||||
endfunction
|
||||
|
||||
" <https://github.com/kana/vim-textobj-indent/blob/deb76867c302f933c8f21753806cbf2d8461b548/autoload/textobj/indent.vim#L120-L127>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
function dotfiles#utils#array_remove_element(array, element)
|
||||
let l:index = index(a:array, a:element)
|
||||
if l:index >= 0
|
||||
call remove(a:array, l:index)
|
||||
let index = index(a:array, a:element)
|
||||
if index >= 0
|
||||
call remove(a:array, index)
|
||||
endif
|
||||
endfunction
|
||||
|
|
|
@ -24,23 +24,23 @@
|
|||
|
||||
let s:colors = g:dotfiles_colorscheme_base16_colors
|
||||
function s:hi(group, fg, bg, attr, guisp)
|
||||
let l:args = ''
|
||||
let args = ''
|
||||
if a:fg isnot ''
|
||||
let l: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 fg = s:is_number(a:fg) ? s:colors[a:fg] : {'gui': a:fg, 'cterm': a:fg}
|
||||
let args .= ' guifg=' . fg.gui . ' ctermfg=' . fg.cterm
|
||||
endif
|
||||
if a:bg isnot ''
|
||||
let l: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 bg = s:is_number(a:bg) ? s:colors[a:bg] : {'gui': a:bg, 'cterm': a:bg}
|
||||
let args .= ' guibg=' . bg.gui . ' ctermbg=' . bg.cterm
|
||||
endif
|
||||
if a:attr isnot ''
|
||||
let l:args .= ' gui=' . a:attr . ' cterm=' . a:attr
|
||||
let args .= ' gui=' . a:attr . ' cterm=' . a:attr
|
||||
endif
|
||||
if a:guisp isnot ''
|
||||
let l:guisp = s:is_number(a:guisp) ? s:colors[a:guisp].gui : a:guisp
|
||||
let l:args .= ' guisp=' . l:guisp
|
||||
let guisp = s:is_number(a:guisp) ? s:colors[a:guisp].gui : a:guisp
|
||||
let args .= ' guisp=' . guisp
|
||||
endif
|
||||
exec 'hi' a:group l:args
|
||||
exec 'hi' a:group args
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
|
|
|
@ -163,10 +163,10 @@ set commentstring=//%s
|
|||
|
||||
" * and # in the Visual mode will search the selected text
|
||||
function! s:VisualStarSearch(search_cmd)
|
||||
let l:tmp = @"
|
||||
let tmp = @"
|
||||
normal! y
|
||||
let @/ = '\V' . substitute(escape(@", a:search_cmd . '\'), '\n', '\\n', 'g')
|
||||
let @" = l:tmp
|
||||
let @" = tmp
|
||||
endfunction
|
||||
" HACK: my mappings are added on VimEnter to override mappings from the
|
||||
" vim-indexed-search plugin
|
||||
|
|
|
@ -52,12 +52,12 @@ nnoremap <silent><expr> <CR> empty(&buftype) ? ":write<bar>wall\<CR>" : "\<CR>"
|
|||
" DiffWithSaved {{{
|
||||
" Compare current buffer with the actual (saved) file on disk
|
||||
function s:DiffWithSaved()
|
||||
let l:filetype = &filetype
|
||||
let filetype = &filetype
|
||||
diffthis
|
||||
vnew | read # | normal! ggdd
|
||||
diffthis
|
||||
setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile readonly nomodifiable
|
||||
let &filetype = l:filetype
|
||||
let &filetype = filetype
|
||||
endfunction
|
||||
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
|
||||
" saves the argument list in the session file.
|
||||
function s:EditGlob(...)
|
||||
for l:glob in a:000
|
||||
for l:name in glob(l:glob, 0, 1)
|
||||
execute 'edit' fnameescape(l:name)
|
||||
for glob in a:000
|
||||
for name in glob(glob, 0, 1)
|
||||
execute 'edit' fnameescape(name)
|
||||
endfor
|
||||
endfor
|
||||
endfunction
|
||||
|
@ -135,31 +135,31 @@ nnoremap <silent><expr> <CR> empty(&buftype) ? ":write<bar>wall\<CR>" : "\<CR>"
|
|||
" create directory {{{
|
||||
" Creates the parent directory of the file if it doesn't exist
|
||||
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
|
||||
if empty(&buftype) && !s:IsUrl(l:file)
|
||||
let l:dir = fnamemodify(l:file, ':h')
|
||||
if !isdirectory(l:dir) | call mkdir(l:dir, 'p') | endif
|
||||
if empty(&buftype) && !s:IsUrl(file)
|
||||
let dir = fnamemodify(file, ':h')
|
||||
if !isdirectory(dir) | call mkdir(dir, 'p') | endif
|
||||
endif
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" fix whitespace {{{
|
||||
function s:FixWhitespaceOnSave()
|
||||
let l:pos = getpos('.')
|
||||
let pos = getpos('.')
|
||||
" remove trailing whitespace
|
||||
keeppatterns %s/\s\+$//e
|
||||
" remove trailing newlines
|
||||
keeppatterns %s/\($\n\s*\)\+\%$//e
|
||||
call setpos('.', l:pos)
|
||||
call setpos('.', pos)
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" auto-format with Coc.nvim {{{
|
||||
let g:coc_format_on_save_ignore = []
|
||||
function s:FormatOnSave()
|
||||
let l:file = expand('<afile>')
|
||||
if IsCocEnabled() && !s:IsUrl(l:file) && index(g:coc_format_on_save_ignore, &filetype) < 0
|
||||
let file = expand('<afile>')
|
||||
if IsCocEnabled() && !s:IsUrl(file) && index(g:coc_format_on_save_ignore, &filetype) < 0
|
||||
silent CocFormat
|
||||
endif
|
||||
endfunction
|
||||
|
|
|
@ -41,18 +41,18 @@ endif
|
|||
|
||||
" Bbye with confirmation, or fancy buffer closer {{{
|
||||
function s:CloseBuffer(cmd) abort
|
||||
let l:cmd = a:cmd
|
||||
let cmd = a:cmd
|
||||
if &modified
|
||||
let l:answer = confirm("Save changes?", "&Yes\n&No\n&Cancel")
|
||||
if l:answer ==# 1 " Yes
|
||||
let answer = confirm("Save changes?", "&Yes\n&No\n&Cancel")
|
||||
if answer ==# 1 " Yes
|
||||
write
|
||||
elseif l:answer ==# 2 " No
|
||||
let l:cmd .= '!'
|
||||
elseif answer ==# 2 " No
|
||||
let cmd .= '!'
|
||||
else " Cancel/Other
|
||||
return
|
||||
endif
|
||||
endif
|
||||
execute l:cmd
|
||||
execute cmd
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
|
@ -108,19 +108,19 @@ endif
|
|||
let g:airline#extensions#tabline#left_alt_sep = ''
|
||||
|
||||
function StatusLine_filesize()
|
||||
let l:bytes = getfsize(expand('%'))
|
||||
if l:bytes < 0 | return '' | endif
|
||||
let bytes = getfsize(expand('%'))
|
||||
if bytes < 0 | return '' | endif
|
||||
|
||||
let l:factor = 1
|
||||
for l:unit in ['B', 'K', 'M', 'G']
|
||||
let l:next_factor = l:factor * 1024
|
||||
if l:bytes < l:next_factor
|
||||
let l:number_str = printf('%.2f', (l:bytes * 1.0) / l:factor)
|
||||
let factor = 1
|
||||
for unit in ['B', 'K', 'M', 'G']
|
||||
let next_factor = factor * 1024
|
||||
if bytes < next_factor
|
||||
let number_str = printf('%.2f', (bytes * 1.0) / factor)
|
||||
" remove trailing zeros
|
||||
let l:number_str = substitute(l:number_str, '\v\.?0+$', '', '')
|
||||
return l:number_str . l:unit
|
||||
let number_str = substitute(number_str, '\v\.?0+$', '', '')
|
||||
return number_str . unit
|
||||
endif
|
||||
let l:factor = l:next_factor
|
||||
let factor = next_factor
|
||||
endfor
|
||||
endfunction
|
||||
call airline#parts#define('filesize', { 'function': 'StatusLine_filesize' })
|
||||
|
|
Loading…
Reference in a new issue