summaryrefslogtreecommitdiffstats
path: root/src/tag.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-01-02 14:02:16 +0100
committerBram Moolenaar <Bram@vim.org>2020-01-02 14:02:16 +0100
commit271fa08a35b8d320d3a40db4ddae83b698fdd4fb (patch)
tree4c20c4317f691299e8364f415204e00a85e710c4 /src/tag.c
parent955f4e6f36ea009b90803d12a62108c94f446778 (diff)
patch 8.2.0077: settagstack() cannot truncate at current indexv8.2.0077
Problem: settagstack() cannot truncate at current index. Solution: Add the "t" action. (Yegappan Lakshmanan, closes #5417)
Diffstat (limited to 'src/tag.c')
-rw-r--r--src/tag.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/src/tag.c b/src/tag.c
index c00f5fb723..4f897fa607 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -4224,13 +4224,16 @@ tagstack_set_curidx(win_T *wp, int curidx)
/*
* Set the tag stack entries of the specified window.
- * 'action' is set to either 'a' for append or 'r' for replace.
+ * 'action' is set to one of:
+ * 'a' for append
+ * 'r' for replace
+ * 't' for truncate
*/
int
set_tagstack(win_T *wp, dict_T *d, int action)
{
dictitem_T *di;
- list_T *l;
+ list_T *l = NULL;
#ifdef FEAT_EVAL
// not allowed to alter the tag stack entries from inside tagfunc
@@ -4249,16 +4252,32 @@ set_tagstack(win_T *wp, dict_T *d, int action)
return FAIL;
}
l = di->di_tv.vval.v_list;
+ }
- if (action == 'r')
+ if ((di = dict_find(d, (char_u *)"curidx", -1)) != NULL)
+ tagstack_set_curidx(wp, (int)tv_get_number(&di->di_tv) - 1);
+
+ if (action == 't') // truncate the stack
+ {
+ taggy_T *tagstack = wp->w_tagstack;
+ int tagstackidx = wp->w_tagstackidx;
+ int tagstacklen = wp->w_tagstacklen;
+ // delete all the tag stack entries above the current entry
+ while (tagstackidx < tagstacklen)
+ tagstack_clear_entry(&tagstack[--tagstacklen]);
+ wp->w_tagstacklen = tagstacklen;
+ }
+
+ if (l != NULL)
+ {
+ if (action == 'r') // replace the stack
tagstack_clear(wp);
tagstack_push_items(wp, l);
+ // set the current index after the last entry
+ wp->w_tagstackidx = wp->w_tagstacklen;
}
- if ((di = dict_find(d, (char_u *)"curidx", -1)) != NULL)
- tagstack_set_curidx(wp, (int)tv_get_number(&di->di_tv) - 1);
-
return OK;
}
#endif