Move rarely used functions to autoload

This commit is contained in:
Kenneth Benzie 2017-11-20 22:35:27 +00:00
parent e292b937d0
commit 4040dc7508
4 changed files with 52 additions and 69 deletions

View File

@ -10,6 +10,7 @@ function! do#isort()
edit! edit!
endfunction endfunction
" Strip white space from right of all lines.
" TODO: Make do#rstrip_lines work on a range " TODO: Make do#rstrip_lines work on a range
function! do#rstrip_lines() function! do#rstrip_lines()
let l:line = line('.') let l:line = line('.')
@ -18,3 +19,36 @@ function! do#rstrip_lines()
nohlsearch nohlsearch
call cursor(l:line, l:column) call cursor(l:line, l:column)
endfunction endfunction
" Set the tab width for the current filetype
function! do#set_tab_width(width)
execute 'setlocal tabstop='.a:width
execute 'setlocal shiftwidth='.a:width
execute 'setlocal softtabstop='.a:width
echo 'Tab width is now '.a:width
endfunction
" Toggle GitHub style bullet checkbox
function! do#toggle_checkbox()
" Get current line
let l:line = getline('.')
" Get the ' ' or 'x' character from within the task bullet
let l:pattern = '[-\*+] \[\zs[ x]\ze]'
let l:char = matchstr(l:line, l:pattern)
" Toggle the ' ' or 'x' character
if l:char ==? 'x'
let l:char = ' '
else
let l:char = 'x'
endif
" Replace the current line with a new one
call setline(line('.'), substitute(l:line, l:pattern, l:char, ''))
endfunction
" Show highlight groups under the cursor
function! do#cursor_highlight_groups()
let l:hi = synIDattr(synID(line('.'),col('.'),1),'name')
let l:trans = synIDattr(synID(line('.'),col('.'),0),'name')
let l:lo = synIDattr(synIDtrans(synID(line('.'),col('.'),1)),'name')
echo 'hi<'.l:hi.'> trans<'.l:trans.'> lo<'.l:lo.'>'
endfunction

View File

@ -1,3 +1,15 @@
" Sort Python Imports
command! ISort call do#isort() command! ISort call do#isort()
" Strip white space from right of all lines.
" TODO: Make RStripLines work on a range " TODO: Make RStripLines work on a range
command! RStripLines call do#rstrip_lines() command! RStripLines call do#rstrip_lines()
" Set tab width
command! -nargs=1 TabWidth call do#set_tab_width(<f-args>)
" Toggle Checkbox
command! ToggleCheckbox call do#toggle_checkbox()
" Show highlight groups under the cursor
command! CursorHighlightGroups :call do#cursor_highlight_groups()

View File

@ -39,74 +39,5 @@ function! s:Synstack()
endfunction endfunction
command Synstack :call s:Synstack() command Synstack :call s:Synstack()
" Stringify
" Make a code block in to a C string literal
function! s:Stringify()
" Escape existing escape characters
execute 's/\\/\\\\/ge'
" Escape quotes
execute 's/"/\\"/ge'
" Prepend quote
execute 's/^/"/g'
" Append carriage return, quote
execute 's/$/\\n"/g'
noh
endfunction
map <silent> <leader>s :call s:Stringify()<CR>
" Make a C string literal in to a code block
function! s:Destringify()
" Remove final quote and carriage return
execute 's/\\n"\s*$//ge'
" Remove first quote
execute 's:^\(\s*\)":\1:ge'
" Remove quote escapes
execute 's/\\"/"/ge'
" Remove escapes of escapes characters
execute 's/\\\\/\\/ge'
noh
endfunction
map <silent> <leader>S :call s:Destringify()<CR>
" Invoke terminal command without prompt and then redraw. " Invoke terminal command without prompt and then redraw.
command! -nargs=+ Silent execute 'silent <args>' | redraw! command! -nargs=+ Silent execute 'silent <args>' | redraw!
" Set the tab width for the current filetype
function! s:TabWidth(width)
execute 'setlocal tabstop='.a:width
execute 'setlocal shiftwidth='.a:width
execute 'setlocal softtabstop='.a:width
echo 'Tab width is now '.a:width
endfunction
command! -nargs=1 TabWidth :call s:TabWidth(<f-args>)
" Toggle GitHub style bullet checkbox
function! s:CheckboxToggle()
" Get current line
let l:line = getline('.')
" Get the ' ' or 'x' character from within the task bullet
let l:pattern = '[-\*+] \[\zs[ x]\ze]'
let l:char = matchstr(l:line, l:pattern)
" Toggle the ' ' or 'x' character
if l:char ==? 'x'
let l:char = ' '
else
let l:char = 'x'
endif
" Replace the current line with a new one
call setline(line('.'), substitute(l:line, l:pattern, l:char, ''))
endfunction
command! CheckboxToggle :call s:CheckboxToggle()
nnoremap <leader><CR> :CheckboxToggle<CR>
" Show highlight groups under the cursor
function! s:CursorHighlightGroups()
let l:hi = synIDattr(synID(line('.'),col('.'),1),'name')
let l:trans = synIDattr(synID(line('.'),col('.'),0),'name')
let l:lo = synIDattr(synIDtrans(synID(line('.'),col('.'),1)),'name')
echo 'hi<'.l:hi.'> trans<'.l:trans.'> lo<'.l:lo.'>'
endfunction
command! CursorHighlightGroups :call s:CursorHighlightGroups()
nnoremap <leader>hi :CursorHighlightGroups<CR>

View File

@ -85,3 +85,9 @@ noremap K <nop>
" Split line at the cursor " Split line at the cursor
nnoremap [j i<CR><Esc> nnoremap [j i<CR><Esc>
nnoremap ]j a<CR><Esc> nnoremap ]j a<CR><Esc>
" Toggle Checkbox
nnoremap <leader><CR> :ToggleCheckbox<CR>
" Show highlight groups under the cursor
nnoremap <leader>hi :CursorHighlightGroups<CR>