blob: 6ab59eabdb7e08d430e2b60822bdebbb0dc11a0d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
" Version number specifier format
if exists('g:perl#version#bump#pattern')
let s:pattern = g:perl#version#bump#pattern
else
let s:pattern = '\m\C^'
\ . '\(our\s\+\$VERSION\s*=\D*\)'
\ . '\(\d\+\)\.\(\d\+\)'
\ . '\(.*\)'
endif
" Helper function to format a number without decreasing its digit count
function! s:Format(old, new) abort
return repeat('0', strlen(a:old) - strlen(a:new)).a:new
endfunction
" Version number bumper
function! s:Bump(major) abort
let l:view = winsaveview()
let l:li = search(s:pattern)
if !l:li
echomsg 'No version number declaration found'
return
endif
let l:matches = matchlist(getline(l:li), s:pattern)
let [l:lvalue, l:major, l:minor, l:rest]
\ = matchlist(getline(l:li), s:pattern)[1:4]
if a:major
let l:major = s:Format(l:major, l:major + 1)
let l:minor = s:Format(l:minor, 0)
else
let l:minor = s:Format(l:minor, l:minor + 1)
endif
let l:version = l:major.'.'.l:minor
call setline(l:li, l:lvalue.l:version.l:rest)
if a:major
echomsg 'Bumped major $VERSION: '.l:version
else
echomsg 'Bumped minor $VERSION: '.l:version
endif
call winrestview(l:view)
endfunction
" Autoloaded interface functions
function! perl#version#bump#Major() abort
call s:Bump(1)
endfunction
function! perl#version#bump#Minor() abort
call s:Bump(0)
endfunction
|