vim:au: Rename functions from CamelCase to snake_case

Make them also script-local as I don't need them outside.
This commit is contained in:
2024-11-01 00:57:58 +01:00
parent 92cc304bbb
commit 4f25801402

View File

@@ -64,7 +64,7 @@ augroup termdebug_bindings
augroup END augroup END
" Highlight word under cursor in other places " Highlight word under cursor in other places
function! HighlightCurrentWord() function! s:highlight_cword()
if exists('w:disable_highlight_cword') if exists('w:disable_highlight_cword')
return return
endif endif
@@ -75,15 +75,15 @@ function! HighlightCurrentWord()
endif endif
" Clear previous highlight and kill the possibly already running timer " Clear previous highlight and kill the possibly already running timer
call ClearHighlights(s:CLEAR_HIGHS_CWORD) call s:clear_highlights(s:CLEAR_HIGHS_CWORD)
" Delay the highlight by 100ms so that not every word is highlighted " Delay the highlight by 100ms so that not every word is highlighted
" while moving the cursor fast. (This kind of simulates a CursorHold " while moving the cursor fast. (This kind of simulates a CursorHold
" event with a custom time) " event with a custom time)
let w:cword_timer_id = timer_start(100, "_HighlightCurrentWord") let w:cword_timer_id = timer_start(100, "s:_highlight_cword")
endfunction endfunction
function! _HighlightCurrentWord(timer_id) function! s:_highlight_cword(timer_id)
unlet w:cword_timer_id unlet w:cword_timer_id
let l:cword = expand('<cword>') let l:cword = expand('<cword>')
@@ -97,21 +97,21 @@ function! _HighlightCurrentWord(timer_id)
endfunction endfunction
" Highlight visual selection in other places " Highlight visual selection in other places
function! HighlightVisualSel() function! s:highlight_selection()
if exists('w:disable_highlight_visual_sel') if exists('w:disable_highlight_visual_sel')
return return
endif endif
" Clear previous highlight and kill the possibly already running timer " Clear previous highlight and kill the possibly already running timer
call ClearHighlights(s:CLEAR_HIGHS_VISUAL) call s:clear_highlights(s:CLEAR_HIGHS_VISUAL)
" Delay the highlight by 100ms so that not every selection is highlighted " Delay the highlight by 100ms so that not every selection is highlighted
" while moving the cursor fast. (This kind of simulates a CursorHold " while moving the cursor fast. (This kind of simulates a CursorHold
" event with a custom time) " event with a custom time)
let w:selection_timer_id = timer_start(100, "_HighlightVisualSel") let w:selection_timer_id = timer_start(100, "s:_highlight_selection")
endfunction endfunction
function! _HighlightVisualSel(timer) function! s:_highlight_selection(timer)
unlet w:selection_timer_id unlet w:selection_timer_id
let l:old_reg = getreg('"') let l:old_reg = getreg('"')
@@ -149,7 +149,7 @@ function! _HighlightVisualSel(timer)
endfunction endfunction
" Clear the highlights of <cword> and visual selection " Clear the highlights of <cword> and visual selection
function! ClearHighlights(what = s:CLEAR_HIGHS_ALL) function! s:clear_highlights(what = s:CLEAR_HIGHS_ALL)
if and(a:what, s:CLEAR_HIGHS_CWORD) if and(a:what, s:CLEAR_HIGHS_CWORD)
if exists('w:cword_match_id') if exists('w:cword_match_id')
call matchdelete(w:cword_match_id) call matchdelete(w:cword_match_id)
@@ -182,28 +182,28 @@ augroup highlight_current
" TODO: `viw` when on the last character of the word does not trigger " TODO: `viw` when on the last character of the word does not trigger
" CursorMoved, but the selection changes " CursorMoved, but the selection changes
au CursorMoved * if mode() == 'n' | au CursorMoved * if mode() == 'n' |
\ call HighlightCurrentWord() | \ call s:highlight_cword() |
\ else | \ else |
\ call HighlightVisualSel() | \ call s:highlight_selection() |
\ endif \ endif
au CursorMovedI * call HighlightCurrentWord() au CursorMovedI * call s:highlight_cword()
au WinLeave * call ClearHighlights() au WinLeave * call s:clear_highlights()
au ModeChanged [vV\x16]*:* call ClearHighlights(s:CLEAR_HIGHS_VISUAL) | call HighlightCurrentWord() au ModeChanged [vV\x16]*:* call s:clear_highlights(s:CLEAR_HIGHS_VISUAL) | call s:highlight_cword()
" NOTE: HighlightVisualSel is not called when entering non-linewise visual " NOTE: s:highlight_selection is not called when entering non-linewise visual
" mode as I rarely need one-character highlighting and I can work " mode as I rarely need one-character highlighting and I can work
" around by moving back and forth once. " around by moving back and forth once.
" TODO: Fix for other ways of entering with a longer selection " TODO: Fix for other ways of entering with a longer selection
au ModeChanged *:[v\x16]* call ClearHighlights(s:CLEAR_HIGHS_CWORD) au ModeChanged *:[v\x16]* call s:clear_highlights(s:CLEAR_HIGHS_CWORD)
au ModeChanged *:V call ClearHighlights(s:CLEAR_HIGHS_CWORD) | call HighlightVisualSel() au ModeChanged *:V call s:clear_highlights(s:CLEAR_HIGHS_CWORD) | call s:highlight_selection()
augroup END augroup END
" When switching focus to another window, keep the cursor location underlined. " When switching focus to another window, keep the cursor location underlined.
function! HighlightOldCursorPos() function! s:highlight_old_cursor_pos()
let w:cursor_pos_match_id = matchaddpos( let w:cursor_pos_match_id = matchaddpos(
\ 'Underlined', \ 'Underlined',
\ [getcurpos()[1:2]]) \ [getcurpos()[1:2]])
endfunction endfunction
function! ClearOldCursorPos() function! s:clear_old_cursor_pos()
if exists('w:cursor_pos_match_id') if exists('w:cursor_pos_match_id')
call matchdelete(w:cursor_pos_match_id) call matchdelete(w:cursor_pos_match_id)
unlet w:cursor_pos_match_id unlet w:cursor_pos_match_id
@@ -211,13 +211,13 @@ function! ClearOldCursorPos()
endfunction endfunction
augroup highlight_old_cursor_pos augroup highlight_old_cursor_pos
au! au!
au WinLeave * call HighlightOldCursorPos() au WinLeave * call s:highlight_old_cursor_pos()
au WinEnter * call ClearOldCursorPos() au WinEnter * call s:clear_old_cursor_pos()
" TODO: WinLeave is not triggered when entering command line mode and " TODO: WinLeave is not triggered when entering command line mode and
" CmdlineEnter is triggered **after** entering " CmdlineEnter is triggered **after** entering
" nnoremap : :call HighlightOldCursorPos()<CR>: " nnoremap : :call s:highlight_old_cursor_pos()<CR>:
" au CmdlineLeave * call ClearOldCursorPos() " au CmdlineLeave * call s:clear_old_cursor_pos()
augroup END augroup END
" Do not mark input from stdin as modified " Do not mark input from stdin as modified