aboutsummaryrefslogtreecommitdiff
path: root/plugin/casefmt.vim
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2022-09-12 21:56:35 -0600
committerJosh Rahm <joshuarahm@gmail.com>2022-09-12 21:56:35 -0600
commit0514c88053e83ff5d1bf3c6ba3cfa80565df368e (patch)
tree9392e402da08ee2f0916c2d206aa69e9868a703f /plugin/casefmt.vim
parent2f99407cd2ce0d0ffbe3f62bc31407033c06d7f7 (diff)
downloadfieldmarshal.vim-0514c88053e83ff5d1bf3c6ba3cfa80565df368e.tar.gz
fieldmarshal.vim-0514c88053e83ff5d1bf3c6ba3cfa80565df368e.tar.bz2
fieldmarshal.vim-0514c88053e83ff5d1bf3c6ba3cfa80565df368e.zip
fieldmarshal.vim: Add utility function for modifying motions
Diffstat (limited to 'plugin/casefmt.vim')
-rw-r--r--plugin/casefmt.vim30
1 files changed, 6 insertions, 24 deletions
diff --git a/plugin/casefmt.vim b/plugin/casefmt.vim
index 4c66a76..752aecd 100644
--- a/plugin/casefmt.vim
+++ b/plugin/casefmt.vim
@@ -52,13 +52,9 @@ function! CaseFmt_AddFormat(key, funcname) abort
\ . "<cmd>let g:CaseFmtFunction=function(\"\<SID>%s\")<cr>"
\ . "<cmd>set operatorfunc=\<SID>casefmt_do<cr>g@", a:key, a:funcname)
- exec printf("vnoremap <silent> <Plug>(casefmt-leader-no-set)%s "
- \ . "<cmd>let g:CaseFmtFunction=function(\"\<SID>%s\")<cr>"
- \ . "<cmd>call \<SID>casefmt_do(visualmode(), 1)<cr>", a:key, a:funcname)
endfunction
-nmap <silent> <Plug>(casefmt-leader) <cmd>let g:CaseFmtProcessor=function("<SID>casefmt_default_processor")<cr><Plug>(casefmt-leader-no-set)
-vmap <silent> <Plug>(casefmt-leader) <cmd>let g:CaseFmtProcessor=function("<SID>casefmt_default_processor")<cr>gv<Plug>(casefmt-leader-no-set)
+noremap <silent> <Plug>(casefmt-leader) <cmd>let g:CaseFmtProcessor=function("<SID>casefmt_default_processor")<cr><Plug>(casefmt-leader-no-set)
for [k, v] in items(s:case_fmts)
call CaseFmt_AddFormat(k, v)
@@ -69,34 +65,20 @@ if g:casefmt_include_bindings
exec printf("vmap <silent> %s <Plug>(casefmt-leader)", g:casefmt_leader)
endif
-nmap <silent> <Plug>(casefmt-leader)j <cmd>let g:CaseFmtProcessor=function("<SID>casefmt_joiner")<cr><Plug>(casefmt-leader-no-set)
-vmap <silent> <Plug>(casefmt-leader)j <cmd>let g:CaseFmtProcessor=function("<SID>casefmt_joiner")<cr>gv<Plug>(casefmt-leader-no-set)
+noremap <silent> <Plug>(casefmt-leader)j <cmd>let g:CaseFmtProcessor=function("<SID>casefmt_joiner")<cr><Plug>(casefmt-leader-no-set)
function! s:casefmt_do(type, ...) abort
- if a:0
- silent exe "norm! gvy"
- elseif a:type == 'line'
- " yank the text described by the motion
- silent exe "norm! '[V']y"
- else
- silent exe "norm! `[v`]y"
- endif
- let yanked = getreg('"', 1, v:true)
- let yankedtype = getregtype('"')
+ let cb = {}
if !exists('g:CaseFmtProcessor')
let g:CaseFmtProcessor = function("\<SID>casefmt_default_processor")
endif
+ let cb.operate = g:CaseFmtProcessor
- let changed = g:CaseFmtProcessor(yanked, yankedtype)
-
- call setreg('"', changed, yankedtype)
-
- norm gvp
+ call fieldmarshal#modifytext(a:type, cb)
- " Reset the yanked text to what it was originally.
- call setreg('"', yanked, yankedtype)
+ normal! ``
endfunction
" Default processor. Calls change case fmt on each word.