aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-07-03 17:30:38 +1200
committerTom Ryder <tom@sanctum.geek.nz>2018-07-03 17:30:38 +1200
commitaf3569d8a74c744770e77f2b2b8d7956c5d6f8c0 (patch)
treee0c8187060dbc892e1d52bebcea3427338129ab6
parent7ba4d39c0544de736ef16ac6f6451e439c656c4a (diff)
downloaddotfiles-af3569d8a74c744770e77f2b2b8d7956c5d6f8c0.tar.gz
Add _v/_V Vim maps for Perl version bumps
-rw-r--r--vim/after/ftplugin/perl.vim9
-rw-r--r--vim/autoload/perl.vim28
2 files changed, 37 insertions, 0 deletions
diff --git a/vim/after/ftplugin/perl.vim b/vim/after/ftplugin/perl.vim
index e9747aa3..37cd1c08 100644
--- a/vim/after/ftplugin/perl.vim
+++ b/vim/after/ftplugin/perl.vim
@@ -25,3 +25,12 @@ let b:undo_ftplugin = b:undo_ftplugin
\ . '|nunmap <buffer> <LocalLeader>c'
\ . '|nunmap <buffer> <LocalLeader>l'
\ . '|nunmap <buffer> <LocalLeader>t'
+
+" Bump version numbers
+nnoremap <buffer> <LocalLeader>v
+ \ :<C-U>call perl#BumpVersionMinor()<CR>
+nnoremap <buffer> <LocalLeader>V
+ \ :<C-U>call perl#BumpVersionMajor()<CR>
+let b:undo_ftplugin = b:undo_ftplugin
+ \ . '|nunmap <buffer> <LocalLeader>v'
+ \ . '|nunmap <buffer> <LocalLeader>V'
diff --git a/vim/autoload/perl.vim b/vim/autoload/perl.vim
new file mode 100644
index 00000000..ca9b2990
--- /dev/null
+++ b/vim/autoload/perl.vim
@@ -0,0 +1,28 @@
+" Quick-and-dirty version number bumper
+function! perl#BumpVersion(major) abort
+ let l:view = winsaveview()
+ let l:search = @/
+ let l:li = search('\C^our \$VERSION\s*=')
+ if !l:li
+ echomsg 'No version number declaration found'
+ return
+ endif
+ if a:major
+ silent execute "normal! /[0-9]\<CR>\<C-A>"
+ echomsg 'Major version bumped: '.getline('.')
+ else
+ silent execute "normal! $?[0-9]\<CR>\<C-A>"
+ echomsg 'Minor version bumped: '.getline('.')
+ endif
+ let @/ = l:search
+ call winrestview(l:view)
+endfunction
+
+" Explanatory wrappers
+function! perl#BumpVersionMinor() abort
+ call perl#BumpVersion(0)
+endfunction
+
+function! perl#BumpVersionMajor() abort
+ call perl#BumpVersion(1)
+endfunction