From 43d2bcbf6aeb1f4fa3201f004bf66488275843ac Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 4 Jun 2019 01:05:58 +1200 Subject: Add command example --- doc/keep_position.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/doc/keep_position.txt b/doc/keep_position.txt index 6f1d516..25de36f 100644 --- a/doc/keep_position.txt +++ b/doc/keep_position.txt @@ -15,8 +15,11 @@ COMMANDS *keep_position-commands* *:KeepPosition* Run the given command while preserving the cursor position and window view. -Works rather like |:keepalt| or |:keepjumps|. - +Works rather like |:keepalt| or |:keepjumps|. It's good for filters, +especially ones that work on the entire buffer: +> + :KeepPosition %!tidy +< AUTHOR *keep_position-author* Written and maintained by Tom Ryder . -- cgit v1.2.3 From 90e5acaf0add1d5caf78417ff544ea1b2d74c0ac Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 4 Jun 2019 01:06:10 +1200 Subject: Add ranges support --- autoload/keep_position.vim | 6 ++++-- doc/keep_position.txt | 11 +++++++++++ plugin/keep_position.vim | 4 ++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/autoload/keep_position.vim b/autoload/keep_position.vim index a2f2ed4..7ff0228 100644 --- a/autoload/keep_position.vim +++ b/autoload/keep_position.vim @@ -1,5 +1,7 @@ -function! keep_position#(command) abort +function! keep_position#(command, range, start, end) abort let view = winsaveview() execute a:command - call winrestview(view) + if !a:range || (a:start >= line("'[") && a:end <= line("']")) + call winrestview(view) + endif endfunction diff --git a/doc/keep_position.txt b/doc/keep_position.txt index 25de36f..05f69bc 100644 --- a/doc/keep_position.txt +++ b/doc/keep_position.txt @@ -20,6 +20,17 @@ especially ones that work on the entire buffer: > :KeepPosition %!tidy < +You will generally want to use this command as above, without a range. +However, if you do specify a range, it will only preserve the view if the last +change to the buffer--presumably made by your nominated command--entirely +encompassed the given range. This is checked with the |'[| and |']| marks. + +The author uses the range functionality to make a "conditional jump"; only +jump to the changes the given command makes if it didn't affect the entire +buffer, e.g.: +> + :nnoremap u :%KeepPosition undo +< AUTHOR *keep_position-author* Written and maintained by Tom Ryder . diff --git a/plugin/keep_position.vim b/plugin/keep_position.vim index 1389bcf..01227c3 100644 --- a/plugin/keep_position.vim +++ b/plugin/keep_position.vim @@ -11,5 +11,5 @@ endif let loaded_keep_position = 1 " User command definition refers to autoloaded function -command! -nargs=+ -complete=command KeepPosition - \ call keep_position#() +command! -nargs=+ -complete=command -range KeepPosition + \ call keep_position#(, , , ) -- cgit v1.2.3 From f7411cc571e98c0dfbf2765c0651f33893641158 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 4 Jun 2019 01:06:32 +1200 Subject: Bump VERSION --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 6e8bf73..0ea3a94 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.0 +0.2.0 -- cgit v1.2.3