aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-07-04 01:18:13 +1200
committerTom Ryder <tom@sanctum.geek.nz>2018-07-04 01:19:13 +1200
commitb8f2d8948c2fe0abd7644664b117760d63888e99 (patch)
tree9ff42869f6daa108880c484c9027fddaea0ec734
parentaf3569d8a74c744770e77f2b2b8d7956c5d6f8c0 (diff)
downloaddotfiles-b8f2d8948c2fe0abd7644664b117760d63888e99.tar.gz
Rewrite Perl version-number bump Vim funcs
-rw-r--r--vim/autoload/perl.vim35
1 files changed, 26 insertions, 9 deletions
diff --git a/vim/autoload/perl.vim b/vim/autoload/perl.vim
index ca9b2990..5349eb49 100644
--- a/vim/autoload/perl.vim
+++ b/vim/autoload/perl.vim
@@ -1,20 +1,32 @@
-" Quick-and-dirty version number bumper
+" Version number specifier format
+let g:perl#verpat = '\m\C^'
+ \ . '\(our\s\+\$VERSION\s*=\D*\)'
+ \ . '\(\d\+\)\.\(\d\+\)'
+ \ . '\(.*\)'
+
+" Version number bumper
function! perl#BumpVersion(major) abort
let l:view = winsaveview()
- let l:search = @/
- let l:li = search('\C^our \$VERSION\s*=')
+ let l:li = search(g:perl#verpat)
if !l:li
echomsg 'No version number declaration found'
return
endif
+ let l:matches = matchlist(getline(l:li), g:perl#verpat)
+ let [l:lvalue, l:major, l:minor, l:rest]
+ \ = matchlist(getline(l:li), g:perl#verpat)[1:4]
+ if a:major
+ let l:major = perl#Incf(l:major)
+ else
+ let l:minor = perl#Incf(l:minor)
+ endif
+ let l:version = l:major.'.'.l:minor
+ call setline(l:li, l:lvalue.l:version.l:rest)
if a:major
- silent execute "normal! /[0-9]\<CR>\<C-A>"
- echomsg 'Major version bumped: '.getline('.')
+ echomsg 'Bumped major $VERSION: '.l:version
else
- silent execute "normal! $?[0-9]\<CR>\<C-A>"
- echomsg 'Minor version bumped: '.getline('.')
+ echomsg 'Bumped minor $VERSION: '.l:version
endif
- let @/ = l:search
call winrestview(l:view)
endfunction
@@ -22,7 +34,12 @@ endfunction
function! perl#BumpVersionMinor() abort
call perl#BumpVersion(0)
endfunction
-
function! perl#BumpVersionMajor() abort
call perl#BumpVersion(1)
endfunction
+
+" Helper function to format a number without decreasing its digit count
+function! perl#Incf(num) abort
+ let l:inc = a:num + 1
+ return repeat('0', strlen(a:num) - strlen(l:inc)).l:inc
+endfunction