aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-07-13 22:25:17 +1200
committerTom Ryder <tom@sanctum.geek.nz>2018-07-13 22:25:17 +1200
commit20d1d12f9be57e60e4998f3680716afdb7b435e6 (patch)
tree620d6ea1c6afd47142a38f1b30c4a617eb648544
parentMerge branch 'hotfix/v1.0.1' into develop (diff)
downloadvim-put-blank-lines-20d1d12f9be57e60e4998f3680716afdb7b435e6.tar.gz
vim-put-blank-lines-20d1d12f9be57e60e4998f3680716afdb7b435e6.zip
Refactor to use 'operatorfunc' with autoload
This removes the repeat.vim dependency for repeats.
-rw-r--r--README.md11
-rw-r--r--autoload/put_blank_lines.vim19
-rw-r--r--doc/put_blank_lines.txt13
-rw-r--r--plugin/put_blank_lines.vim34
4 files changed, 36 insertions, 41 deletions
diff --git a/README.md b/README.md
index 993e93b..1533438 100644
--- a/README.md
+++ b/README.md
@@ -2,13 +2,12 @@ put\_blank\_lines.vim
=====================
This plugin provides mapping targets for inserting blank lines above or below
-the current line without going into insert mode. The applicable code is lifted
-from [unimpaired.vim][1]. It still works with [repeat.vim][2], if that's
-installed, to make the mappings repeatable.
+the current line without going into insert mode, including count prefixes and
+repeating with the dot command.
-I wrote this because I used these mappings from the original plugin frequently,
-but (almost) nothing else from it. The only functional difference is that the
-number of added lines is not reported, via a `:silent` suppression.
+The idea and insert method is lifted from the same mappings for
+[unimpaired.vim][1], but called with `'operatorfunc'` to allow counts and
+repeating without requiring [repeat.vim][2].
Configuration
-------------
diff --git a/autoload/put_blank_lines.vim b/autoload/put_blank_lines.vim
new file mode 100644
index 0000000..c0c835d
--- /dev/null
+++ b/autoload/put_blank_lines.vim
@@ -0,0 +1,19 @@
+function! put_blank_lines#Above(count)
+ set operatorfunc=put_blank_lines#AboveOpfunc
+ call feedkeys(a:count.'g@l', 'n')
+endfunction
+
+function! put_blank_lines#Below(count)
+ set operatorfunc=put_blank_lines#BelowOpfunc
+ call feedkeys(a:count.'g@l', 'n')
+endfunction
+
+function! put_blank_lines#AboveOpfunc(type)
+ silent put! =repeat(nr2char(10), v:count1)
+ ']+1
+endfunction
+
+function! put_blank_lines#BelowOpfunc(type)
+ silent put =repeat(nr2char(10), v:count1)
+ '[-1
+endfunction
diff --git a/doc/put_blank_lines.txt b/doc/put_blank_lines.txt
index b50fd18..38c6b7a 100644
--- a/doc/put_blank_lines.txt
+++ b/doc/put_blank_lines.txt
@@ -1,15 +1,14 @@
-*put_blank_lines.txt* For Vim version 6.0 Last change: 2018 June 17
+*put_blank_lines.txt* For Vim version 7.0 Last change: 2018 July 13
DESCRIPTION *put_blank_lines*
This plugin provides mapping targets for inserting blank lines above or below
-the current line without going into insert mode. The applicable code is lifted
-from unimpaired.vim. It still works with repeat.vim, if that's installed, to
-make the mappings repeatable.
+the current line without going into insert mode, including count prefixes and
+repeating with the dot command.
-I wrote this because I used these mappings from the original plugin frequently,
-but (almost) nothing else from it. The only functional difference is that the
-number of added lines is not reported, via a `:silent` suppression.
+The idea and insert method is lifted from the same mappings for
+unimpaired.vim, but called with `'operatorfunc'` to allow counts and repeating
+without requiring repeat.vim.
CONFIGURATION *put_blank_lines-configuration*
diff --git a/plugin/put_blank_lines.vim b/plugin/put_blank_lines.vim
index b64fb0b..ede964a 100644
--- a/plugin/put_blank_lines.vim
+++ b/plugin/put_blank_lines.vim
@@ -1,7 +1,6 @@
"
" put_blank_lines.vim: Provide plugin maps to put blank lines above or below
-" the current line. The guts of this is backported from Tim Pope's
-" unimpaired.vim plugin, and still uses repeat.vim if it can find it.
+" the current line.
"
" Author: Tom Ryder <tom@sanctum.geek.nz>
" License: Same as Vim itself
@@ -9,35 +8,14 @@
if exists('g:loaded_put_blank_lines') || &compatible
finish
endif
-if v:version < 600
+if v:version < 700
finish
endif
let g:loaded_put_blank_lines = 1
-function! s:PutBlankLinesAbove(count)
- let l:i = 0
- while l:i < a:count
- silent put! =nr2char(10)
- let l:i = l:i + 1
- ']+1
- endwhile
- silent! call repeat#set("\<Plug>(PutBlankLinesAbove)", a:count)
-endfunction
-
-function! s:PutBlankLinesBelow(count)
- let l:i = 0
- while l:i < a:count
- silent put =nr2char(10)
- let l:i = l:i + 1
- '[-1
- endwhile
- silent! call repeat#set("\<Plug>(PutBlankLinesBelow)", a:count)
-endfunction
-
-nnoremap <silent> <unique>
- \ <Plug>(PutBlankLinesAbove)
- \ :<C-U>call <SID>PutBlankLinesAbove(v:count1)<CR>
-
nnoremap <silent> <unique>
\ <Plug>(PutBlankLinesBelow)
- \ :<C-U>call <SID>PutBlankLinesBelow(v:count1)<CR>
+ \ :<C-U>call put_blank_lines#Below(v:count1)<CR>
+nnoremap <silent> <unique>
+ \ <Plug>(PutBlankLinesAbove)
+ \ :<C-U>call put_blank_lines#Above(v:count1)<CR>