aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2019-06-04 01:06:45 +1200
committerTom Ryder <tom@sanctum.geek.nz>2019-06-04 01:06:45 +1200
commit2bb4902d546efc814150134f3900b7860bac9b84 (patch)
treec6eb6f4e62d1c21da38dff198f0d4be4da2cf862
parentMerge branch 'release/v0.1.0' (diff)
parentBump VERSION (diff)
downloadvim-keep-position-2bb4902d546efc814150134f3900b7860bac9b84.tar.gz
vim-keep-position-2bb4902d546efc814150134f3900b7860bac9b84.zip
Merge branch 'release/v0.2.0'v0.2.0
* release/v0.2.0: Add ranges support Add command example
-rw-r--r--VERSION2
-rw-r--r--autoload/keep_position.vim6
-rw-r--r--doc/keep_position.txt18
-rw-r--r--plugin/keep_position.vim4
4 files changed, 23 insertions, 7 deletions
diff --git a/VERSION b/VERSION
index 6e8bf73..0ea3a94 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.1.0
+0.2.0
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 6f1d516..05f69bc 100644
--- a/doc/keep_position.txt
+++ b/doc/keep_position.txt
@@ -15,8 +15,22 @@ 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
+<
+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 :<C-U>%KeepPosition undo<CR>
+<
AUTHOR *keep_position-author*
Written and maintained by Tom Ryder <tom@sanctum.geek.nz>.
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#(<q-args>)
+command! -nargs=+ -complete=command -range KeepPosition
+ \ call keep_position#(<q-args>, <range>, <line1>, <line2>)