From d6d9596b38f544faa23d2c831aa84a5d15ffa972 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 19 May 2019 08:22:05 -0400 Subject: vim-patch:8.0.1498: getjumplist() returns duplicate entries Problem: Getjumplist() returns duplicate entries. (lacygoill) Solution: Call cleanup_jumplist(). (Yegappan Lakshmanan) https://github.com/vim/vim/commit/a7e18d237f817637815f0de44b08df1e0ca0f4f9 --- src/nvim/mark.c | 58 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 28 insertions(+), 30 deletions(-) (limited to 'src/nvim/mark.c') diff --git a/src/nvim/mark.c b/src/nvim/mark.c index ecd1f098ca..64b7b2e002 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -214,7 +214,7 @@ pos_T *movemark(int count) pos_T *pos; xfmark_T *jmp; - cleanup_jumplist(); + cleanup_jumplist(curwin); if (curwin->w_jumplistlen == 0) /* nothing to jump to */ return (pos_T *)NULL; @@ -463,7 +463,7 @@ getnextmark ( * This is used for marks obtained from the .shada file. It's postponed * until the mark is used to avoid a long startup delay. */ -static void fname2fnum(xfmark_T *fm) +void fname2fnum(xfmark_T *fm) { char_u *p; @@ -781,7 +781,7 @@ void ex_jumps(exarg_T *eap) int i; char_u *name; - cleanup_jumplist(); + cleanup_jumplist(curwin); /* Highlight title */ MSG_PUTS_TITLE(_("\n jump line col file/text")); for (i = 0; i < curwin->w_jumplistlen && !got_int; ++i) { @@ -1156,53 +1156,51 @@ void mark_col_adjust( } } -/* - * When deleting lines, this may create duplicate marks in the - * jumplist. They will be removed here for the current window. - */ -void cleanup_jumplist(void) +// When deleting lines, this may create duplicate marks in the +// jumplist. They will be removed here for the specified window. +void cleanup_jumplist(win_T *wp) { int i; int from, to; to = 0; - for (from = 0; from < curwin->w_jumplistlen; ++from) { - if (curwin->w_jumplistidx == from) - curwin->w_jumplistidx = to; - for (i = from + 1; i < curwin->w_jumplistlen; ++i) - if (curwin->w_jumplist[i].fmark.fnum - == curwin->w_jumplist[from].fmark.fnum - && curwin->w_jumplist[from].fmark.fnum != 0 - && curwin->w_jumplist[i].fmark.mark.lnum - == curwin->w_jumplist[from].fmark.mark.lnum) + for (from = 0; from < wp->w_jumplistlen; ++from) { + if (wp->w_jumplistidx == from) + wp->w_jumplistidx = to; + for (i = from + 1; i < wp->w_jumplistlen; ++i) + if (wp->w_jumplist[i].fmark.fnum + == wp->w_jumplist[from].fmark.fnum + && wp->w_jumplist[from].fmark.fnum != 0 + && wp->w_jumplist[i].fmark.mark.lnum + == wp->w_jumplist[from].fmark.mark.lnum) break; - if (i >= curwin->w_jumplistlen) { // no duplicate + if (i >= wp->w_jumplistlen) { // no duplicate if (to != from) { - // Not using curwin->w_jumplist[to++] = curwin->w_jumplist[from] because + // Not using wp->w_jumplist[to++] = wp->w_jumplist[from] because // this way valgrind complains about overlapping source and destination // in memcpy() call. (clang-3.6.0, debug build with -DEXITFREE). - curwin->w_jumplist[to] = curwin->w_jumplist[from]; + wp->w_jumplist[to] = wp->w_jumplist[from]; } to++; } else { - xfree(curwin->w_jumplist[from].fname); + xfree(wp->w_jumplist[from].fname); } } - if (curwin->w_jumplistidx == curwin->w_jumplistlen) { - curwin->w_jumplistidx = to; + if (wp->w_jumplistidx == wp->w_jumplistlen) { + wp->w_jumplistidx = to; } - curwin->w_jumplistlen = to; + wp->w_jumplistlen = to; // When pointer is below last jump, remove the jump if it matches the current // line. This avoids useless/phantom jumps. #9805 - if (curwin->w_jumplistlen - && curwin->w_jumplistidx == curwin->w_jumplistlen) { - const xfmark_T *fm_last = &curwin->w_jumplist[curwin->w_jumplistlen - 1]; + if (wp->w_jumplistlen + && wp->w_jumplistidx == wp->w_jumplistlen) { + const xfmark_T *fm_last = &wp->w_jumplist[wp->w_jumplistlen - 1]; if (fm_last->fmark.fnum == curbuf->b_fnum - && fm_last->fmark.mark.lnum == curwin->w_cursor.lnum) { + && fm_last->fmark.mark.lnum == wp->w_cursor.lnum) { xfree(fm_last->fname); - curwin->w_jumplistlen--; - curwin->w_jumplistidx--; + wp->w_jumplistlen--; + wp->w_jumplistidx--; } } } -- cgit From 4aad4c053366592f9604ecc6d3a1348005bf2ce7 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 19 May 2019 08:34:04 -0400 Subject: vim-patch:8.0.1513: the jumplist is not always properly cleaned up Problem: The jumplist is not always properly cleaned up. Solution: Call fname2fnum() before cleanup_jumplist(). (Yegappan Lakshmanan) https://github.com/vim/vim/commit/486797413791f6be12dcec6e5faf4f952e4647ae --- src/nvim/mark.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'src/nvim/mark.c') diff --git a/src/nvim/mark.c b/src/nvim/mark.c index 64b7b2e002..907cfe4833 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -214,7 +214,7 @@ pos_T *movemark(int count) pos_T *pos; xfmark_T *jmp; - cleanup_jumplist(curwin); + cleanup_jumplist(curwin, true); if (curwin->w_jumplistlen == 0) /* nothing to jump to */ return (pos_T *)NULL; @@ -463,7 +463,7 @@ getnextmark ( * This is used for marks obtained from the .shada file. It's postponed * until the mark is used to avoid a long startup delay. */ -void fname2fnum(xfmark_T *fm) +static void fname2fnum(xfmark_T *fm) { char_u *p; @@ -781,13 +781,11 @@ void ex_jumps(exarg_T *eap) int i; char_u *name; - cleanup_jumplist(curwin); + cleanup_jumplist(curwin, true); /* Highlight title */ MSG_PUTS_TITLE(_("\n jump line col file/text")); for (i = 0; i < curwin->w_jumplistlen && !got_int; ++i) { if (curwin->w_jumplist[i].fmark.mark.lnum != 0) { - if (curwin->w_jumplist[i].fmark.fnum == 0) - fname2fnum(&curwin->w_jumplist[i]); name = fm_getname(&curwin->w_jumplist[i].fmark, 16); if (name == NULL) /* file name not available */ continue; @@ -1158,11 +1156,25 @@ void mark_col_adjust( // When deleting lines, this may create duplicate marks in the // jumplist. They will be removed here for the specified window. -void cleanup_jumplist(win_T *wp) +// When "loadfiles" is true first ensure entries have the "fnum" field set +// (this may be a bit slow). +void cleanup_jumplist(win_T *wp, bool loadfiles) { int i; int from, to; + if (loadfiles) { + // If specified, load all the files from the jump list. This is + // needed to properly clean up duplicate entries, but will take some + // time. + for (i = 0; i < wp->w_jumplistlen; i++) { + if ((wp->w_jumplist[i].fmark.fnum == 0) + && (wp->w_jumplist[i].fmark.mark.lnum != 0)) { + fname2fnum(&wp->w_jumplist[i]); + } + } + } + to = 0; for (from = 0; from < wp->w_jumplistlen; ++from) { if (wp->w_jumplistidx == from) -- cgit From bd885d878fdc33ac5dc1674d5977b4f96aae5507 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 19 May 2019 08:57:10 -0400 Subject: lint --- src/nvim/mark.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/nvim/mark.c') diff --git a/src/nvim/mark.c b/src/nvim/mark.c index 907cfe4833..5c9367ab01 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -782,7 +782,7 @@ void ex_jumps(exarg_T *eap) char_u *name; cleanup_jumplist(curwin, true); - /* Highlight title */ + // Highlight title MSG_PUTS_TITLE(_("\n jump line col file/text")); for (i = 0; i < curwin->w_jumplistlen && !got_int; ++i) { if (curwin->w_jumplist[i].fmark.mark.lnum != 0) { @@ -1161,7 +1161,6 @@ void mark_col_adjust( void cleanup_jumplist(win_T *wp, bool loadfiles) { int i; - int from, to; if (loadfiles) { // If specified, load all the files from the jump list. This is @@ -1175,17 +1174,20 @@ void cleanup_jumplist(win_T *wp, bool loadfiles) } } - to = 0; - for (from = 0; from < wp->w_jumplistlen; ++from) { - if (wp->w_jumplistidx == from) + int to = 0; + for (int from = 0; from < wp->w_jumplistlen; from++) { + if (wp->w_jumplistidx == from) { wp->w_jumplistidx = to; - for (i = from + 1; i < wp->w_jumplistlen; ++i) + } + for (i = from + 1; i < wp->w_jumplistlen; i++) { if (wp->w_jumplist[i].fmark.fnum == wp->w_jumplist[from].fmark.fnum && wp->w_jumplist[from].fmark.fnum != 0 && wp->w_jumplist[i].fmark.mark.lnum - == wp->w_jumplist[from].fmark.mark.lnum) + == wp->w_jumplist[from].fmark.mark.lnum) { break; + } + } if (i >= wp->w_jumplistlen) { // no duplicate if (to != from) { // Not using wp->w_jumplist[to++] = wp->w_jumplist[from] because -- cgit