diff options
Diffstat (limited to 'src/nvim/mark.c')
-rw-r--r-- | src/nvim/mark.c | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/src/nvim/mark.c b/src/nvim/mark.c index 6ce42bb7fe..a09ade2b03 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -14,6 +14,7 @@ #include "nvim/cursor.h" #include "nvim/diff.h" #include "nvim/edit.h" +#include "nvim/errors.h" #include "nvim/eval/typval.h" #include "nvim/eval/typval_defs.h" #include "nvim/ex_cmds_defs.h" @@ -42,6 +43,7 @@ #include "nvim/pos_defs.h" #include "nvim/quickfix.h" #include "nvim/strings.h" +#include "nvim/tag.h" #include "nvim/textobject.h" #include "nvim/types_defs.h" #include "nvim/vim_defs.h" @@ -69,7 +71,7 @@ int setmark(int c) /// Free fmark_T item void free_fmark(fmark_T fm) { - tv_dict_unref(fm.additional_data); + xfree(fm.additional_data); } /// Free xfmark_T item @@ -164,6 +166,56 @@ int setmark_pos(int c, pos_T *pos, int fnum, fmarkv_T *view_pt) return FAIL; } +/// Remove every jump list entry referring to a given buffer. +/// This function will also adjust the current jump list index. +void mark_jumplist_forget_file(win_T *wp, int fnum) +{ + // Remove all jump list entries that match the deleted buffer. + for (int i = wp->w_jumplistlen - 1; i >= 0; i--) { + if (wp->w_jumplist[i].fmark.fnum == fnum) { + // Found an entry that we want to delete. + free_xfmark(wp->w_jumplist[i]); + + // If the current jump list index is behind the entry we want to delete, + // move it back by one. + if (wp->w_jumplistidx > i) { + wp->w_jumplistidx--; + } + + // Actually remove the entry from the jump list. + wp->w_jumplistlen--; + memmove(&wp->w_jumplist[i], &wp->w_jumplist[i + 1], + (size_t)(wp->w_jumplistlen - i) * sizeof(wp->w_jumplist[i])); + } + } +} + +/// Delete every entry referring to file "fnum" from both the jumplist and the +/// tag stack. +void mark_forget_file(win_T *wp, int fnum) +{ + mark_jumplist_forget_file(wp, fnum); + + // Remove all tag stack entries that match the deleted buffer. + for (int i = wp->w_tagstacklen - 1; i >= 0; i--) { + if (wp->w_tagstack[i].fmark.fnum == fnum) { + // Found an entry that we want to delete. + tagstack_clear_entry(&wp->w_tagstack[i]); + + // If the current tag stack index is behind the entry we want to delete, + // move it back by one. + if (wp->w_tagstackidx > i) { + wp->w_tagstackidx--; + } + + // Actually remove the entry from the tag stack. + wp->w_tagstacklen--; + memmove(&wp->w_tagstack[i], &wp->w_tagstack[i + 1], + (size_t)(wp->w_tagstacklen - i) * sizeof(wp->w_tagstack[i])); + } + } +} + // Set the previous context mark to the current position and add it to the // jump list. void setpcmark(void) |