diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2018-07-04 13:03:51 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2018-07-04 13:03:51 +1200 |
commit | 80c98e8b11832cf78f2fc3ee43599749be8ee6a6 (patch) | |
tree | 98882e07722ac325579db50bd9ef42b957886827 | |
download | vim-perl-version-bump-80c98e8b11832cf78f2fc3ee43599749be8ee6a6.tar.gz vim-perl-version-bump-80c98e8b11832cf78f2fc3ee43599749be8ee6a6.zip |
First commitv0.1.0
-rw-r--r-- | README.md | 29 | ||||
-rw-r--r-- | VERSION | 1 | ||||
-rw-r--r-- | after/ftplugin/perl/version_bump.vim | 32 | ||||
-rw-r--r-- | autoload/perl/version/bump.vim | 49 | ||||
-rw-r--r-- | doc/perl_version_bump.txt | 47 |
5 files changed, 158 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..4975533 --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +perl\_version\_bump.vim +======================= + +This filetype plugin for Perl code ("perl" filetype) provides buffer-local +mapping targets for normal mode to increment either the major or minor version +number of a package-scoped `$VERSION` assignment. + +So with this format: + + our $VERSION => '1.23'; + +Keying a map to `<Plug>PerlVersionBumpMinor` would yield: + + our $VERSION => '1.24'; + +Keying a map to `<Plug>PerlVersionBumpMajor` would yield: + + our $VERSION => '2.00'; + +There is no support for development versions with underscore prefixes like +`1.23_001` (yet). + +License +------- + +Copyright (c) [Tom Ryder][1]. Distributed under the same terms as Vim itself. +See `:help license`. + +[1]: https://sanctum.geek.nz/ @@ -0,0 +1 @@ +0.1.0 diff --git a/after/ftplugin/perl/version_bump.vim b/after/ftplugin/perl/version_bump.vim new file mode 100644 index 0000000..271335f --- /dev/null +++ b/after/ftplugin/perl/version_bump.vim @@ -0,0 +1,32 @@ +" perl/version_bump.vim: Mapping targets to bump Perl package version numbers. + +" Don't load if running compatible or too old +if &compatible || v:version < 700 + finish +endif + +" Don't load if already loaded +if exists('b:did_ftplugin_perl_version_bump') + finish +endif + +" Stop here if the user doesn't want ftplugin mappings +if exists('g:no_plugin_maps') || exists('g:no_perl_maps') + finish +endif + +" Flag as loaded +let b:did_ftplugin_perl_version_bump = 1 +let b:undo_ftplugin = b:undo_ftplugin + \ . '|unlet b:did_ftplugin_perl_version_bump' + +" Bump version numbers +nnoremap <buffer> <silent> <unique> + \ <Plug>PerlVersionBumpMajor + \ :<C-U>call perl#version#bump#Major()<CR> +nnoremap <buffer> <silent> <unique> + \ <Plug>PerlVersionBumpMinor + \ :<C-U>call perl#version#bump#Minor()<CR> +let b:undo_ftplugin = b:undo_ftplugin + \ . '|nunmap <buffer> <Plug>PerlVersionBumpMajor' + \ . '|nunmap <buffer> <Plug>PerlVersionBumpMinor' diff --git a/autoload/perl/version/bump.vim b/autoload/perl/version/bump.vim new file mode 100644 index 0000000..6ab59ea --- /dev/null +++ b/autoload/perl/version/bump.vim @@ -0,0 +1,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 diff --git a/doc/perl_version_bump.txt b/doc/perl_version_bump.txt new file mode 100644 index 0000000..918166c --- /dev/null +++ b/doc/perl_version_bump.txt @@ -0,0 +1,47 @@ +*perl_version_bump.txt* For Vim version 7.0 Last change: 2018 June 29 + +DESCRIPTION *perl_version_bump* + +This filetype plugin for Perl code ("perl" filetype) provides buffer-local +mapping targets for normal mode to increment either the major or minor version +number of a package-scoped `$VERSION` assignment. + +So with this format: +> + our $VERSION => '1.23'; +< +Keying a map to `<Plug>PerlVersionBumpMinor` would yield: +> + our $VERSION => '1.24'; +< +Keying a map to `<Plug>PerlVersionBumpMajor` would yield: +> + our $VERSION => '2.00'; +< +There is no support for development versions with underscore prefixes like +`1.23_001` (yet). + +REQUIREMENTS *perl_version_bump-requirements* + +This plugin is only available if 'compatible' is not set. It requires Vim 7.0 +or newer. + +MAPPINGS *perl_version_bump-mappings* + + *<Plug>PerlVersionBumpMajor* +`<Plug>PerlVersionBumpMajor</Plug>` bumps the major (first) part of the version +number, and sets the minor (second) part to zero. + + *<Plug>PerlVersionBumpMinor* +`<Plug>PerlVersionBumpMinor</Plug>` bumps the minor (second) part of the +version number. + +AUTHOR *perl_version_bump-author* + +Written and maintained by Tom Ryder <tom@sanctum.geek.nz>. + +LICENSE *perl_version_bump-license* + +Licensed for distribution under the same terms as Vim itself (see |license|). + + vim:tw=78:ts=8:ft=help:norl: |