Hi,
First, my use case: I'd like to be able to invoke functions or commands
(particularly some which I didn't write, e.g. from other people
plug-ins/scripts) and not have them update the jump list. The "keepjumps"
command is not sufficient in this regard, because it does not act recursively.
For example, I have some code[1] which uses the matchit.vim plugin, which:
1) doesn't use keepjumps internally (this may be seen as a plugin bug, and I
sent a patch[2] to the author to do that).
2) calls m' on the starting position before jumping to its destination[3]. This
is not a bug and it's currently unavoidable.
My code calls "normal %" in the middle of some processing, and this inevitably
pollutes the jump list, so that using CTRL-O jumps to irrelevant places in the
file. Also, my code in turn sets jumps, and people might want to use it without
that being the case. You get the idea.
I know I should have tried not to introduce new options ;) but it seems to me
that having an option to lock the jump list (and restoring it afterwards) is
the simplest way to introduce a mechanism to avoid that behaviour. I mean not
only simple to implement, but also to document, understand, and maintain. My
patch adds such an option, called 'lockjumps' or 'lkj'. It's a window option
since the jumplist is also associated to the window.
I tested it and it works as intended, and valgrind passes. When I removed the
`FEAT_JUMPLIST` setting in features.h, it compiled and worked fine; two tests
failed (test49 and test_command_count) but this is unrelated to the patch since
they failed anyway with that setting disabled.
The patch is against the latest code downloaded today with mercurial
(ca3db36a6ed8).
I followed the instructions in option.c, but I never worked on the vim source
code before so please let me know if I should do something more, or if I
overlooked something etc.
Carlo
[1] example:
https://github.com/JuliaLang/julia-vim/blob/9bb84c2f3586c8d6f1263254ae21bb16a66abb4a/autoload/julia_blocks.vim#L319
[2] https://github.com/benjifisher/matchit.zip/pull/2
[3] example:
https://github.com/benjifisher/matchit.zip/blob/73f7f7051eca95ed90537f931e9a4559fb3a494b/plugin/matchit.vim#L277
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
diff --git a/runtime/doc/motion.txt b/runtime/doc/motion.txt
--- a/runtime/doc/motion.txt
+++ b/runtime/doc/motion.txt
@@ -1084,7 +1084,8 @@
only once.
When the |:keepjumps| command modifier is used, jumps are not stored in the
-jumplist. Jumps are also not stored in other cases, e.g., in a |:global|
+jumplist. When set, the |'lockjumps'| option also prevents jumps from being
+stored. Jumps are also not stored in other cases, e.g., in a |:global|
command. You can explicitly add a jump by setting the ' mark with "m'". Note
that calling setpos() does not do this.
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -4772,6 +4772,15 @@
Note that using the "-u NONE" and "--noplugin" command line arguments
reset this option. |-u| |--noplugin|
+ *'lockjumps'* *'lkj'* *'nolockjumps'* *'nolkj'*
+'lockjumps' 'lkj' boolean (default off)
+ local to window
+ {not in Vi}
+ {only available when compiled without the |+jumplist|
+ feature}
+ When this option is set, the jump list will not be updated by jump
+ commands. See |:jumps| and |jumplist|.
+
*'macatsui'* *'nomacatsui'*
'macatsui' boolean (default on)
global
diff --git a/runtime/doc/tags b/runtime/doc/tags
--- a/runtime/doc/tags
+++ b/runtime/doc/tags
@@ -404,10 +404,12 @@
'lispwords' options.txt /*'lispwords'*
'list' options.txt /*'list'*
'listchars' options.txt /*'listchars'*
+'lkj' options.txt /*'lkj'*
'lm' options.txt /*'lm'*
'lmap' options.txt /*'lmap'*
'lnr' options.txt /*'lnr'*
'loadplugins' options.txt /*'loadplugins'*
+'lockjumps' options.txt /*'lockjumps'*
'lpl' options.txt /*'lpl'*
'ls' options.txt /*'ls'*
'lsp' options.txt /*'lsp'*
@@ -574,7 +576,9 @@
'nolinebreak' options.txt /*'nolinebreak'*
'nolisp' options.txt /*'nolisp'*
'nolist' options.txt /*'nolist'*
+'nolkj' options.txt /*'nolkj'*
'noloadplugins' options.txt /*'noloadplugins'*
+'nolockjumps' options.txt /*'nolockjumps'*
'nolpl' options.txt /*'nolpl'*
'nolz' options.txt /*'nolz'*
'noma' options.txt /*'noma'*
@@ -6733,6 +6737,7 @@
lcs-extends options.txt /*lcs-extends*
lcs-nbsp options.txt /*lcs-nbsp*
lcs-precedes options.txt /*lcs-precedes*
+lcs-space options.txt /*lcs-space*
lcs-tab options.txt /*lcs-tab*
lcs-trail options.txt /*lcs-trail*
left-right-motions motion.txt /*left-right-motions*
diff --git a/runtime/optwin.vim b/runtime/optwin.vim
--- a/runtime/optwin.vim
+++ b/runtime/optwin.vim
@@ -239,6 +239,9 @@
call append("$", "startofline\tmany jump commands move the cursor to the first
non-blank")
call append("$", "\tcharacter of a line")
call <SID>BinOptionG("sol", &sol)
+call append("$", "lockjumps\tdon't record jumps in the jumplist")
+call append("$", "\t(local to window)")
+call <SID>BinOptionL("lkj")
call append("$", "paragraphs\tnroff macro names that separate paragraphs")
call <SID>OptionG("para", ¶)
call append("$", "sections\tnroff macro names that separate sections")
diff --git a/src/edit.c b/src/edit.c
--- a/src/edit.c
+++ b/src/edit.c
@@ -8439,7 +8439,11 @@
curwin->w_set_curswant = TRUE;
/* Remember the last Insert position in the '^ mark. */
- if (!cmdmod.keepjumps)
+ if (!cmdmod.keepjumps
+/*#ifdef FEAT_JUMPLIST
+ && !curwin->w_p_lkj
+#endif*/
+ )
curbuf->b_last_insert = curwin->w_cursor;
/*
diff --git a/src/mark.c b/src/mark.c
--- a/src/mark.c
+++ b/src/mark.c
@@ -149,7 +149,11 @@
#endif
/* for :global the mark is set only once */
- if (global_busy || listcmd_busy || cmdmod.keepjumps)
+ if (global_busy || listcmd_busy || cmdmod.keepjumps
+/*#ifdef FEAT_JUMPLIST
+ || curwin->w_p_lkj
+#endif*/
+ )
return;
curwin->w_prev_pcmark = curwin->w_pcmark;
diff --git a/src/misc1.c b/src/misc1.c
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -3032,7 +3032,11 @@
changed();
/* set the '. mark */
- if (!cmdmod.keepjumps)
+ if (!cmdmod.keepjumps
+/*#ifdef FEAT_JUMPLIST
+ && !curwin->w_p_lkj
+#endif*/
+ )
{
curbuf->b_last_change.lnum = lnum;
curbuf->b_last_change.col = col;
diff --git a/src/option.c b/src/option.c
--- a/src/option.c
+++ b/src/option.c
@@ -213,6 +213,9 @@
#ifdef FEAT_LINEBREAK
# define PV_LBR OPT_WIN(WV_LBR)
#endif
+#ifdef FEAT_JUMPLIST
+# define PV_LKJ OPT_WIN(WV_LKJ)
+#endif
#define PV_NU OPT_WIN(WV_NU)
#define PV_RNU OPT_WIN(WV_RNU)
#ifdef FEAT_LINEBREAK
@@ -1761,6 +1764,13 @@
{"loadplugins", "lpl", P_BOOL|P_VI_DEF,
(char_u *)&p_lpl, PV_NONE,
{(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
+ {"lockjumps", "lkj", P_BOOL|P_VI_DEF,
+#ifdef FEAT_JUMPLIST
+ (char_u *)VAR_WIN, PV_LKJ,
+#else
+ (char_u *)NULL, PV_NONE,
+#endif
+ {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
#ifdef FEAT_GUI_MAC
{"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
(char_u *)&p_macatsui, PV_NONE,
@@ -10113,6 +10123,9 @@
case PV_BRI: return (char_u *)&(curwin->w_p_bri);
case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
#endif
+#ifdef FEAT_JUMPLIST
+ case PV_LKJ: return (char_u *)&(curwin->w_p_lkj);
+#endif
#ifdef FEAT_SCROLLBIND
case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
#endif
@@ -10307,6 +10320,9 @@
to->wo_bri = from->wo_bri;
to->wo_briopt = vim_strsave(from->wo_briopt);
#endif
+#ifdef FEAT_JUMPLIST
+ to->wo_lkj = from->wo_lkj;
+#endif
#ifdef FEAT_SCROLLBIND
to->wo_scb = from->wo_scb;
to->wo_scb_save = from->wo_scb_save;
diff --git a/src/option.h b/src/option.h
--- a/src/option.h
+++ b/src/option.h
@@ -1083,6 +1083,9 @@
#ifdef FEAT_LINEBREAK
, WV_LBR
#endif
+#ifdef FEAT_JUMPLIST
+ , WV_LKJ
+#endif
, WV_NU
, WV_RNU
#ifdef FEAT_LINEBREAK
diff --git a/src/structs.h b/src/structs.h
--- a/src/structs.h
+++ b/src/structs.h
@@ -180,6 +180,10 @@
int wo_lbr;
# define w_p_lbr w_onebuf_opt.wo_lbr /* 'linebreak' */
#endif
+#ifdef FEAT_JUMPLIST
+ int wo_lkj;
+# define w_p_lkj w_onebuf_opt.wo_lkj /* 'linebreak' */
+#endif
int wo_list;
#define w_p_list w_onebuf_opt.wo_list /* 'list' */
int wo_nu;