From 2b6a3819e5d0135102e0a771be9272e73ea88389 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 28 Apr 2017 02:20:40 +0200 Subject: build_stl_str_hl: Array name should be plural. --- src/nvim/buffer.c | 149 +++++++++++++++++++++++++++--------------------------- 1 file changed, 74 insertions(+), 75 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 46f2cdac79..e0812b4aed 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -3060,7 +3060,7 @@ int build_stl_str_hl( StlClickRecord *tabtab ) { - int groupitem[STL_MAX_ITEM]; + int groupitems[STL_MAX_ITEM]; struct stl_item { // Where the item starts in the status line output buffer char_u *start; @@ -3080,7 +3080,7 @@ int build_stl_str_hl( ClickFunc, Trunc } type; - } item[STL_MAX_ITEM]; + } items[STL_MAX_ITEM]; #define TMPLEN 70 char_u tmp[TMPLEN]; char_u *usefmt = fmt; @@ -3182,16 +3182,16 @@ int build_stl_str_hl( if (groupdepth > 0) { continue; } - item[curitem].type = Separate; - item[curitem++].start = out_p; + items[curitem].type = Separate; + items[curitem++].start = out_p; continue; } // STL_TRUNCMARK: Where to begin truncating if the statusline is too long. if (*fmt_p == STL_TRUNCMARK) { fmt_p++; - item[curitem].type = Trunc; - item[curitem++].start = out_p; + items[curitem].type = Trunc; + items[curitem++].start = out_p; continue; } @@ -3207,7 +3207,7 @@ int build_stl_str_hl( // Determine how long the group is. // Note: We set the current output position to null // so `vim_strsize` will work. - char_u *t = item[groupitem[groupdepth]].start; + char_u *t = items[groupitems[groupdepth]].start; *out_p = NUL; long group_len = vim_strsize(t); @@ -3217,11 +3217,11 @@ int build_stl_str_hl( // move the output pointer back to where the group started. // Note: This erases any non-item characters that were in the group. // Otherwise there would be no reason to do this step. - if (curitem > groupitem[groupdepth] + 1 - && item[groupitem[groupdepth]].minwid == 0) { + if (curitem > groupitems[groupdepth] + 1 + && items[groupitems[groupdepth]].minwid == 0) { bool has_normal_items = false; - for (long n = groupitem[groupdepth] + 1; n < curitem; n++) { - if (item[n].type == Normal || item[n].type == Highlight) { + for (long n = groupitems[groupdepth] + 1; n < curitem; n++) { + if (items[n].type == Normal || items[n].type == Highlight) { has_normal_items = true; break; } @@ -3235,18 +3235,18 @@ int build_stl_str_hl( // If the group is longer than it is allowed to be // truncate by removing bytes from the start of the group text. - if (group_len > item[groupitem[groupdepth]].maxwid) { + if (group_len > items[groupitems[groupdepth]].maxwid) { // { Determine the number of bytes to remove long n; if (has_mbyte) { /* Find the first character that should be included. */ n = 0; - while (group_len >= item[groupitem[groupdepth]].maxwid) { + while (group_len >= items[groupitems[groupdepth]].maxwid) { group_len -= ptr2cells(t + n); n += (*mb_ptr2len)(t + n); } } else { - n = (long)(out_p - t) - item[groupitem[groupdepth]].maxwid + 1; + n = (long)(out_p - t) - items[groupitems[groupdepth]].maxwid + 1; } // } @@ -3257,24 +3257,24 @@ int build_stl_str_hl( memmove(t + 1, t + n, (size_t)(out_p - (t + n))); out_p = out_p - n + 1; /* Fill up space left over by half a double-wide char. */ - while (++group_len < item[groupitem[groupdepth]].minwid) + while (++group_len < items[groupitems[groupdepth]].minwid) *out_p++ = fillchar; // } /* correct the start of the items for the truncation */ - for (int idx = groupitem[groupdepth] + 1; idx < curitem; idx++) { + for (int idx = groupitems[groupdepth] + 1; idx < curitem; idx++) { // Shift everything back by the number of removed bytes - item[idx].start -= n; + items[idx].start -= n; // If the item was partially or completely truncated, set its // start to the start of the group - if (item[idx].start < t) { - item[idx].start = t; + if (items[idx].start < t) { + items[idx].start = t; } } // If the group is shorter than the minimum width, add padding characters. - } else if (abs(item[groupitem[groupdepth]].minwid) > group_len) { - long min_group_width = item[groupitem[groupdepth]].minwid; + } else if (abs(items[groupitems[groupdepth]].minwid) > group_len) { + long min_group_width = items[groupitems[groupdepth]].minwid; // If the group is left-aligned, add characters to the right. if (min_group_width < 0) { min_group_width = 0 - min_group_width; @@ -3293,8 +3293,8 @@ int build_stl_str_hl( // } // Adjust item start positions - for (int n = groupitem[groupdepth] + 1; n < curitem; n++) { - item[n].start += group_len; + for (int n = groupitems[groupdepth] + 1; n < curitem; n++) { + items[n].start += group_len; } // Prepend the fill characters @@ -3332,9 +3332,9 @@ int build_stl_str_hl( // User highlight groups override the min width field // to denote the styling to use. if (*fmt_p == STL_USER_HL) { - item[curitem].type = Highlight; - item[curitem].start = out_p; - item[curitem].minwid = minwid > 9 ? 1 : minwid; + items[curitem].type = Highlight; + items[curitem].start = out_p; + items[curitem].minwid = minwid > 9 ? 1 : minwid; fmt_p++; curitem++; continue; @@ -3369,17 +3369,17 @@ int build_stl_str_hl( /* %X ends the close label, go back to the previously * define tab label nr. */ for (long n = curitem - 1; n >= 0; --n) - if (item[n].type == TabPage && item[n].minwid >= 0) { - minwid = item[n].minwid; + if (items[n].type == TabPage && items[n].minwid >= 0) { + minwid = items[n].minwid; break; } } else /* close nrs are stored as negative values */ minwid = -minwid; } - item[curitem].type = TabPage; - item[curitem].start = out_p; - item[curitem].minwid = minwid; + items[curitem].type = TabPage; + items[curitem].start = out_p; + items[curitem].minwid = minwid; fmt_p++; curitem++; continue; @@ -3394,10 +3394,10 @@ int build_stl_str_hl( if (*fmt_p != STL_CLICK_FUNC) { break; } - item[curitem].type = ClickFunc; - item[curitem].start = out_p; - item[curitem].cmd = xmemdupz(t, (size_t) (((char *) fmt_p - t))); - item[curitem].minwid = minwid; + items[curitem].type = ClickFunc; + items[curitem].start = out_p; + items[curitem].cmd = xmemdupz(t, (size_t) (((char *) fmt_p - t))); + items[curitem].minwid = minwid; fmt_p++; curitem++; continue; @@ -3420,11 +3420,11 @@ int build_stl_str_hl( // Denotes the start of a new group if (*fmt_p == '(') { - groupitem[groupdepth++] = curitem; - item[curitem].type = Group; - item[curitem].start = out_p; - item[curitem].minwid = minwid; - item[curitem].maxwid = maxwid; + groupitems[groupdepth++] = curitem; + items[curitem].type = Group; + items[curitem].start = out_p; + items[curitem].minwid = minwid; + items[curitem].maxwid = maxwid; fmt_p++; curitem++; continue; @@ -3451,7 +3451,7 @@ int build_stl_str_hl( case STL_FULLPATH: case STL_FILENAME: { - // Set fillable to false to that ' ' in the filename will not + // Set fillable to false so that ' ' in the filename will not // get replaced with the fillchar fillable = false; if (buf_spname(wp->w_buffer) != NULL) { @@ -3703,9 +3703,9 @@ int build_stl_str_hl( // Create a highlight item based on the name if (*fmt_p == '#') { - item[curitem].type = Highlight; - item[curitem].start = out_p; - item[curitem].minwid = -syn_namen2id(t, (int)(fmt_p - t)); + items[curitem].type = Highlight; + items[curitem].start = out_p; + items[curitem].minwid = -syn_namen2id(t, (int)(fmt_p - t)); curitem++; fmt_p++; } @@ -3716,8 +3716,8 @@ int build_stl_str_hl( // If we made it this far, the item is normal and starts at // our current position in the output buffer. // Non-normal items would have `continued`. - item[curitem].start = out_p; - item[curitem].type = Normal; + items[curitem].start = out_p; + items[curitem].type = Normal; // Copy the item string into the output buffer if (str != NULL && *str) { @@ -3874,7 +3874,7 @@ int build_stl_str_hl( // Otherwise, there was nothing to print so mark the item as empty } else { - item[curitem].type = Empty; + items[curitem].type = Empty; } // Only free the string buffer if we allocated it. @@ -3899,8 +3899,7 @@ int build_stl_str_hl( } // We have now processed the entire statusline format string. - // What follows is post-processing to handle alignment and - // highlighting factors. + // What follows is post-processing to handle alignment and highlighting. int width = vim_strsize(out); if (maxwidth > 0 && width > maxwidth) { @@ -3915,13 +3914,13 @@ int build_stl_str_hl( // Otherwise, look for the truncation item } else { // Default to truncating at the first item - trunc_p = item[0].start; + trunc_p = items[0].start; item_idx = 0; for (int i = 0; i < itemcnt; i++) - if (item[i].type == Trunc) { - // Truncate at %< item. - trunc_p = item[i].start; + if (items[i].type == Trunc) { + // Truncate at %< items. + trunc_p = items[i].start; item_idx = i; break; } @@ -3954,7 +3953,7 @@ int build_stl_str_hl( // Ignore any items in the statusline that occur after // the truncation point for (int i = 0; i < itemcnt; i++) { - if (item[i].start > trunc_p) { + if (items[i].start > trunc_p) { itemcnt = i; break; } @@ -4009,12 +4008,12 @@ int build_stl_str_hl( for (int i = item_idx; i < itemcnt; i++) { // Items starting at or after the end of the truncated section need // to be moved backwards. - if (item[i].start >= trunc_end_p) { - item[i].start -= item_offset; + if (items[i].start >= trunc_end_p) { + items[i].start -= item_offset; // Anything inside the truncated area is set to start // at the `<` truncation character. } else { - item[i].start = trunc_p; + items[i].start = trunc_p; } } // } @@ -4030,7 +4029,7 @@ int build_stl_str_hl( // figuring out how many groups there are. int num_separators = 0; for (int i = 0; i < itemcnt; i++) { - if (item[i].type == Separate) { + if (items[i].type == Separate) { num_separators++; } } @@ -4042,7 +4041,7 @@ int build_stl_str_hl( int separator_locations[STL_MAX_ITEM]; int index = 0; for (int i = 0; i < itemcnt; i++) { - if (item[i].type == Separate) { + if (items[i].type == Separate) { separator_locations[index] = i; index++; } @@ -4055,16 +4054,16 @@ int build_stl_str_hl( for (int i = 0; i < num_separators; i++) { int dislocation = (i == (num_separators - 1)) ? final_spaces : standard_spaces; - char_u *sep_loc = item[separator_locations[i]].start + dislocation; - STRMOVE(sep_loc, item[separator_locations[i]].start); - for (char_u *s = item[separator_locations[i]].start; s < sep_loc; s++) { + char_u *sep_loc = items[separator_locations[i]].start + dislocation; + STRMOVE(sep_loc, items[separator_locations[i]].start); + for (char_u *s = items[separator_locations[i]].start; s < sep_loc; s++) { *s = fillchar; } for (int item_idx = separator_locations[i] + 1; item_idx < itemcnt; item_idx++) { - item[item_idx].start += dislocation; + items[item_idx].start += dislocation; } } @@ -4076,9 +4075,9 @@ int build_stl_str_hl( if (hltab != NULL) { struct stl_hlrec *sp = hltab; for (long l = 0; l < itemcnt; l++) { - if (item[l].type == Highlight) { - sp->start = item[l].start; - sp->userhl = item[l].minwid; + if (items[l].type == Highlight) { + sp->start = items[l].start; + sp->userhl = items[l].minwid; sp++; } } @@ -4090,14 +4089,14 @@ int build_stl_str_hl( if (tabtab != NULL) { StlClickRecord *cur_tab_rec = tabtab; for (long l = 0; l < itemcnt; l++) { - if (item[l].type == TabPage) { - cur_tab_rec->start = (char *) item[l].start; - if (item[l].minwid == 0) { + if (items[l].type == TabPage) { + cur_tab_rec->start = (char *) items[l].start; + if (items[l].minwid == 0) { cur_tab_rec->def.type = kStlClickDisabled; cur_tab_rec->def.tabnr = 0; } else { - int tabnr = item[l].minwid; - if (item[l].minwid > 0) { + int tabnr = items[l].minwid; + if (items[l].minwid > 0) { cur_tab_rec->def.type = kStlClickTabSwitch; } else { cur_tab_rec->def.type = kStlClickTabClose; @@ -4107,11 +4106,11 @@ int build_stl_str_hl( } cur_tab_rec->def.func = NULL; cur_tab_rec++; - } else if (item[l].type == ClickFunc) { - cur_tab_rec->start = (char *) item[l].start; + } else if (items[l].type == ClickFunc) { + cur_tab_rec->start = (char *) items[l].start; cur_tab_rec->def.type = kStlClickFuncRun; - cur_tab_rec->def.tabnr = item[l].minwid; - cur_tab_rec->def.func = item[l].cmd; + cur_tab_rec->def.tabnr = items[l].minwid; + cur_tab_rec->def.func = items[l].cmd; cur_tab_rec++; } } -- cgit From 0ddebbc354273ada61734e5d35517ac49362c2d9 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 28 Apr 2017 05:27:47 +0200 Subject: lint --- src/nvim/buffer.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index e0812b4aed..7477118d6f 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -3256,12 +3256,13 @@ int build_stl_str_hl( // { Move the truncated output memmove(t + 1, t + n, (size_t)(out_p - (t + n))); out_p = out_p - n + 1; - /* Fill up space left over by half a double-wide char. */ - while (++group_len < items[groupitems[groupdepth]].minwid) + // Fill up space left over by half a double-wide char. + while (++group_len < items[groupitems[groupdepth]].minwid) { *out_p++ = fillchar; + } // } - /* correct the start of the items for the truncation */ + // correct the start of the items for the truncation for (int idx = groupitems[groupdepth] + 1; idx < curitem; idx++) { // Shift everything back by the number of removed bytes items[idx].start -= n; @@ -3366,16 +3367,17 @@ int build_stl_str_hl( if (*fmt_p == STL_TABPAGENR || *fmt_p == STL_TABCLOSENR) { if (*fmt_p == STL_TABCLOSENR) { if (minwid == 0) { - /* %X ends the close label, go back to the previously - * define tab label nr. */ - for (long n = curitem - 1; n >= 0; --n) + // %X ends the close label, go back to the previous tab label nr. + for (long n = curitem - 1; n >= 0; n--) { if (items[n].type == TabPage && items[n].minwid >= 0) { minwid = items[n].minwid; break; } - } else - /* close nrs are stored as negative values */ + } + } else { + // close nrs are stored as negative values minwid = -minwid; + } } items[curitem].type = TabPage; items[curitem].start = out_p; @@ -3396,7 +3398,7 @@ int build_stl_str_hl( } items[curitem].type = ClickFunc; items[curitem].start = out_p; - items[curitem].cmd = xmemdupz(t, (size_t) (((char *) fmt_p - t))); + items[curitem].cmd = xmemdupz(t, (size_t)(((char *)fmt_p - t))); items[curitem].minwid = minwid; fmt_p++; curitem++; @@ -3917,13 +3919,14 @@ int build_stl_str_hl( trunc_p = items[0].start; item_idx = 0; - for (int i = 0; i < itemcnt; i++) + for (int i = 0; i < itemcnt; i++) { if (items[i].type == Trunc) { // Truncate at %< items. trunc_p = items[i].start; item_idx = i; break; } + } } // If the truncation point we found is beyond the maximum @@ -4052,11 +4055,11 @@ int build_stl_str_hl( standard_spaces * (num_separators - 1); for (int i = 0; i < num_separators; i++) { - int dislocation = (i == (num_separators - 1)) ? - final_spaces : standard_spaces; - char_u *sep_loc = items[separator_locations[i]].start + dislocation; - STRMOVE(sep_loc, items[separator_locations[i]].start); - for (char_u *s = items[separator_locations[i]].start; s < sep_loc; s++) { + int dislocation = (i == (num_separators - 1)) + ? final_spaces : standard_spaces; + char_u *seploc = items[separator_locations[i]].start + dislocation; + STRMOVE(seploc, items[separator_locations[i]].start); + for (char_u *s = items[separator_locations[i]].start; s < seploc; s++) { *s = fillchar; } @@ -4090,7 +4093,7 @@ int build_stl_str_hl( StlClickRecord *cur_tab_rec = tabtab; for (long l = 0; l < itemcnt; l++) { if (items[l].type == TabPage) { - cur_tab_rec->start = (char *) items[l].start; + cur_tab_rec->start = (char *)items[l].start; if (items[l].minwid == 0) { cur_tab_rec->def.type = kStlClickDisabled; cur_tab_rec->def.tabnr = 0; @@ -4107,7 +4110,7 @@ int build_stl_str_hl( cur_tab_rec->def.func = NULL; cur_tab_rec++; } else if (items[l].type == ClickFunc) { - cur_tab_rec->start = (char *) items[l].start; + cur_tab_rec->start = (char *)items[l].start; cur_tab_rec->def.type = kStlClickFuncRun; cur_tab_rec->def.tabnr = items[l].minwid; cur_tab_rec->def.func = items[l].cmd; -- cgit From f477c23c6282bffb8908f53592923e81443bac24 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Sat, 29 Apr 2017 21:22:22 -0400 Subject: vim-patch:7.4.2245 Problem: Filter test fails. Solution: Include missing changes. https://github.com/vim/vim/commit/77401add71853d7a3da7ccc489f2a1bca58551ec --- src/nvim/buffer.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 7477118d6f..5007cb5015 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -2365,12 +2365,16 @@ void buflist_list(exarg_T *eap) && (buf == curbuf || curwin->w_alt_fnum != buf->b_fnum))) { continue; } - msg_putchar('\n'); if (buf_spname(buf) != NULL) STRLCPY(NameBuff, buf_spname(buf), MAXPATHL); else home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, TRUE); + if (message_filtered(NameBuff)) { + continue; + } + + msg_putchar('\n'); len = vim_snprintf((char *)IObuff, IOSIZE - 20, "%3d%c%c%c%c%c \"%s\"", buf->b_fnum, buf->b_p_bl ? ' ' : 'u', -- cgit From 2b191ac5b9a18f31eadb4f14ed8a220d0c03ebdc Mon Sep 17 00:00:00 2001 From: James McCoy Date: Sat, 29 Apr 2017 22:09:09 -0400 Subject: lint --- src/nvim/buffer.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 5007cb5015..7def8c1684 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -2365,10 +2365,11 @@ void buflist_list(exarg_T *eap) && (buf == curbuf || curwin->w_alt_fnum != buf->b_fnum))) { continue; } - if (buf_spname(buf) != NULL) + if (buf_spname(buf) != NULL) { STRLCPY(NameBuff, buf_spname(buf), MAXPATHL); - else - home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, TRUE); + } else { + home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, true); + } if (message_filtered(NameBuff)) { continue; -- cgit From 443399c27d63fea7b837af700a6f3142e96adb22 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Fri, 5 May 2017 10:40:32 +0200 Subject: options: consolidate updates for window string options affected by copy_winopt update note at options.c head about window options --- src/nvim/buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 7def8c1684..ebe50c6d31 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -2316,7 +2316,7 @@ void get_winopts(buf_T *buf) /* Set 'foldlevel' to 'foldlevelstart' if it's not negative. */ if (p_fdls >= 0) curwin->w_p_fdl = p_fdls; - check_colorcolumn(curwin); + didset_window_options(curwin); } /* -- cgit From a6f74debc01b1d76713b392819d429de7d92f875 Mon Sep 17 00:00:00 2001 From: Richard Adenling Date: Sat, 6 Aug 2016 13:23:52 +0200 Subject: terminal: refresh before on_exit. #5217 References #3030 References https://github.com/radenling/vim-dispatch-neovim/issues/6 The terminal is updated by a timer, but on_exit needs the final state. Before this change, on_exit callback could see a stale terminal buffer. Helped-by: oni-link --- src/nvim/buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 7def8c1684..fe80f7f62e 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -449,7 +449,7 @@ void close_buffer(win_T *win, buf_T *buf, int action, int abort_if_last) if (buf->terminal) { terminal_close(buf->terminal, NULL); - } + } /* Always remove the buffer when there is no file name. */ if (buf->b_ffname == NULL) -- cgit From 7d6af9985c057eef8f6bb2a625744df1b4ad0a72 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Wed, 10 May 2017 09:54:54 +0200 Subject: ui: cleanup UI_CALL wrappers remove pointless control chars in the text stream --- src/nvim/buffer.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 4ed75d8a2d..f54979eb1e 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -24,6 +24,7 @@ #include #include "nvim/api/private/handle.h" +#include "nvim/api/private/helpers.h" #include "nvim/ascii.h" #include "nvim/assert.h" #include "nvim/vim.h" @@ -3001,13 +3002,13 @@ static bool ti_change(char_u *str, char_u **last) return false; } -/* - * Put current window title back (used after calling a shell) - */ + +/// Set current window title void resettitle(void) { - ui_set_title((char *)lasttitle); - ui_set_icon((char *)lasticon); + ui_call_set_title(cstr_as_string((char *)lasttitle)); + ui_call_set_icon(cstr_as_string((char *)lasticon)); + ui_flush(); } # if defined(EXITFREE) -- cgit From 0ff959329bb8a8ae22856a65b5289b41bdae433a Mon Sep 17 00:00:00 2001 From: James McCoy Date: Thu, 20 Apr 2017 01:17:42 -0400 Subject: *: Comment intentional fallthroughs Falling through a switch case should be commented so it's clear that behavior is intentional. --- src/nvim/buffer.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index f54979eb1e..e3897e3929 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -3607,6 +3607,7 @@ int build_stl_str_hl( case STL_OFFSET_X: base = kNumBaseHexadecimal; + // fallthrough case STL_OFFSET: { long l = ml_find_line_or_offset(wp->w_buffer, wp->w_cursor.lnum, NULL); @@ -3617,6 +3618,7 @@ int build_stl_str_hl( } case STL_BYTEVAL_X: base = kNumBaseHexadecimal; + // fallthrough case STL_BYTEVAL: num = byteval; if (num == NL) -- cgit From a914029278ef1920833423e04a89b07339c1354f Mon Sep 17 00:00:00 2001 From: ZyX Date: Sat, 20 May 2017 03:28:44 +0300 Subject: buffer: Silence V519 --- src/nvim/buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index e3897e3929..6abd505ead 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -828,7 +828,7 @@ void handle_swap_exists(bufref_T *old_curbuf) * new aborting error, interrupt, or uncaught exception. */ leave_cleanup(&cs); } - swap_exists_action = SEA_NONE; + swap_exists_action = SEA_NONE; // -V519 } /* -- cgit From d0ff2000b2a639f3bb0f70e37104b561dab05562 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 11 Jun 2017 15:03:02 +0200 Subject: vim-patch:8.0.0607 (#6879) Problem: When creating a bufref, then using :bwipe and :new it might get the same memory and bufref_valid() returns true. Solution: Add br_fnum to check the buffer number didn't change. https://github.com/vim/vim/commit/45e5fd135da5710f24a1acc142692f120f8b0b78 --- src/nvim/buffer.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 6abd505ead..0d7df7ef77 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -281,19 +281,22 @@ open_buffer ( void set_bufref(bufref_T *bufref, buf_T *buf) { bufref->br_buf = buf; + bufref->br_fnum = buf->b_fnum; bufref->br_buf_free_count = buf_free_count; } -/// Check if "bufref" points to a valid buffer. -/// +/// Return true if "bufref->br_buf" points to the same buffer as when +/// set_bufref() was called and it is a valid buffer. /// Only goes through the buffer list if buf_free_count changed. +/// Also checks if b_fnum is still the same, a :bwipe followed by :new might get +/// the same allocated memory, but it's a different buffer. /// /// @param bufref Buffer reference to check for. bool bufref_valid(bufref_T *bufref) { return bufref->br_buf_free_count == buf_free_count ? true - : buf_valid(bufref->br_buf); + : buf_valid(bufref->br_buf) && bufref->br_fnum == bufref->br_buf->b_fnum; } /// Check that "buf" points to a valid buffer in the buffer list. @@ -1753,16 +1756,15 @@ void free_buf_options(buf_T *buf, int free_p_ff) clear_string_option(&buf->b_p_bkc); } -/* - * get alternate file n - * set linenr to lnum or altfpos.lnum if lnum == 0 - * also set cursor column to altfpos.col if 'startofline' is not set. - * if (options & GETF_SETMARK) call setpcmark() - * if (options & GETF_ALT) we are jumping to an alternate file. - * if (options & GETF_SWITCH) respect 'switchbuf' settings when jumping - * - * return FAIL for failure, OK for success - */ + +/// Get alternate file "n". +/// Set linenr to "lnum" or altfpos.lnum if "lnum" == 0. +/// Also set cursor column to altfpos.col if 'startofline' is not set. +/// if (options & GETF_SETMARK) call setpcmark() +/// if (options & GETF_ALT) we are jumping to an alternate file. +/// if (options & GETF_SWITCH) respect 'switchbuf' settings when jumping +/// +/// Return FAIL for failure, OK for success. int buflist_getfile(int n, linenr_T lnum, int options, int forceit) { buf_T *buf; -- cgit From 1eff241ec68ebec76ef1e3e5c6d68bfb64602cf5 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Thu, 28 Jul 2016 22:42:22 +0200 Subject: bufhl: use kbtree for bufhl --- src/nvim/buffer.c | 114 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 74 insertions(+), 40 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 0d7df7ef77..8491e77e73 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -5138,6 +5138,26 @@ void sign_mark_adjust(linenr_T line1, linenr_T line2, long amount, long amount_a // bufhl: plugin highlights associated with a buffer +/// Get reference to line in kbtree_t, allocating it if neccessary. +BufhlLine *bufhl_tree_ref(kbtree_t(bufhl) *b, linenr_T line, bool put) { + BufhlLine t, *p, **pp; + t.line = line; + + // put() only works if key is absent + pp = kb_get(bufhl, b, &t); + if (pp) { + return *pp; + } else if (!put) { + return NULL; + } + + p = xcalloc(sizeof(*p), 1); + p->line = line; + // p->items zero initialized + kb_put(bufhl, b, p); + return p; +} + /// Adds a highlight to buffer. /// /// Unlike matchaddpos() highlights follow changes to line numbering (as lines @@ -5176,12 +5196,12 @@ int bufhl_add_hl(buf_T *buf, return src_id; } if (!buf->b_bufhl_info) { - buf->b_bufhl_info = map_new(linenr_T, bufhl_vec_T)(); + buf->b_bufhl_info = kb_init(bufhl, KB_DEFAULT_SIZE); } - bufhl_vec_T* lineinfo = map_ref(linenr_T, bufhl_vec_T)(buf->b_bufhl_info, - lnum, true); - bufhl_hl_item_T *hlentry = kv_pushp(*lineinfo); + BufhlLine *lineinfo = bufhl_tree_ref(buf->b_bufhl_info, lnum, true); + + bufhl_hl_item_T *hlentry = kv_pushp(lineinfo->items); hlentry->src_id = src_id; hlentry->hl_id = hl_id; hlentry->start = col_start; @@ -5207,14 +5227,20 @@ void bufhl_clear_line_range(buf_T *buf, if (!buf->b_bufhl_info) { return; } - linenr_T line; linenr_T first_changed = MAXLNUM, last_changed = -1; - // In the case line_start - line_end << bufhl_info->size - // it might be better to reverse this, i e loop over the lines - // to clear on. - bufhl_vec_T unused; - map_foreach(buf->b_bufhl_info, line, unused, { - (void)unused; + // TODO: implement kb_itr_interval and jump directly to the first line + kbitr_t itr; + BufhlLine *l; + for (kb_itr_first(bufhl, buf->b_bufhl_info, &itr); + kb_itr_valid(&itr); + kb_itr_next(bufhl, buf->b_bufhl_info, &itr)) { + l = kb_itr_key(BufhlLine *, &itr); + linenr_T line = l->line; + if (line < line_start) { + continue; + } else if (line > line_end) { + break; + } if (line_start <= line && line <= line_end) { if (bufhl_clear_line(buf->b_bufhl_info, src_id, line)) { if (line > last_changed) { @@ -5225,7 +5251,7 @@ void bufhl_clear_line_range(buf_T *buf, } } } - }) + } if (last_changed != -1) { changed_lines_buf(buf, first_changed, last_changed+1, 0); @@ -5241,38 +5267,38 @@ void bufhl_clear_line_range(buf_T *buf, static bool bufhl_clear_line(bufhl_info_T *bufhl_info, int src_id, linenr_T lnum) { - bufhl_vec_T *lineinfo = map_ref(linenr_T, bufhl_vec_T)(bufhl_info, - lnum, false); - size_t oldsize = kv_size(*lineinfo); + BufhlLine *lineinfo = bufhl_tree_ref(bufhl_info, lnum, false); + size_t oldsize = kv_size(lineinfo->items); if (src_id < 0) { - kv_size(*lineinfo) = 0; + kv_size(lineinfo->items) = 0; } else { size_t newind = 0; - for (size_t i = 0; i < kv_size(*lineinfo); i++) { - if (kv_A(*lineinfo, i).src_id != src_id) { + for (size_t i = 0; i < kv_size(lineinfo->items); i++) { + if (kv_A(lineinfo->items, i).src_id != src_id) { if (i != newind) { - kv_A(*lineinfo, newind) = kv_A(*lineinfo, i); + kv_A(lineinfo->items, newind) = kv_A(lineinfo->items, i); } newind++; } } - kv_size(*lineinfo) = newind; + kv_size(lineinfo->items) = newind; } - if (kv_size(*lineinfo) == 0) { - kv_destroy(*lineinfo); - map_del(linenr_T, bufhl_vec_T)(bufhl_info, lnum); + if (kv_size(lineinfo->items) == 0) { + kv_destroy(lineinfo->items); + kb_del(bufhl, bufhl_info, lineinfo); } - return kv_size(*lineinfo) != oldsize; + return kv_size(lineinfo->items) != oldsize; } /// Remove all highlights and free the highlight data -void bufhl_clear_all(buf_T* buf) { +void bufhl_clear_all(buf_T *buf) +{ if (!buf->b_bufhl_info) { return; } bufhl_clear_line_range(buf, -1, 1, MAXLNUM); - map_free(linenr_T, bufhl_vec_T)(buf->b_bufhl_info); + kb_destroy(bufhl, buf->b_bufhl_info); buf->b_bufhl_info = NULL; } @@ -5285,25 +5311,29 @@ void bufhl_mark_adjust(buf_T* buf, if (!buf->b_bufhl_info) { return; } + // XXX: does not support move + // we need to detect this case and - bufhl_info_T *newmap = map_new(linenr_T, bufhl_vec_T)(); - linenr_T line; - bufhl_vec_T lineinfo; - map_foreach(buf->b_bufhl_info, line, lineinfo, { - if (line >= line1 && line <= line2) { + kbitr_t itr; + BufhlLine *l; + for (kb_itr_first(bufhl, buf->b_bufhl_info, &itr); + kb_itr_valid(&itr); + kb_itr_next(bufhl, buf->b_bufhl_info, &itr)) { + l = kb_itr_key(BufhlLine *, &itr); + if (l->line >= line1 && l->line <= line2) { if (amount == MAXLNUM) { - bufhl_clear_line(buf->b_bufhl_info, -1, line); + bufhl_clear_line(buf->b_bufhl_info, -1, l->line); continue; } else { - line += amount; + l->line += amount; + } + } else if (l->line > line2) { + if (amount_after == 0) { + break; } - } else if (line > line2) { - line += amount_after; + l->line += amount_after; } - map_put(linenr_T, bufhl_vec_T)(newmap, line, lineinfo); - }); - map_free(linenr_T, bufhl_vec_T)(buf->b_bufhl_info); - buf->b_bufhl_info = newmap; + } } @@ -5318,8 +5348,12 @@ bool bufhl_start_line(buf_T *buf, linenr_T lnum, bufhl_lineinfo_T *info) { return false; } + BufhlLine *lineinfo = bufhl_tree_ref(buf->b_bufhl_info, lnum, false); + if (!lineinfo) { + return false; + } info->valid_to = -1; - info->entries = map_get(linenr_T, bufhl_vec_T)(buf->b_bufhl_info, lnum); + info->entries = lineinfo->items; return kv_size(info->entries) > 0; } -- cgit From 6712e08bba2d50899853bf98b786bdf48c3c79be Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Fri, 29 Jul 2016 20:27:50 +0200 Subject: kbtree: allow iterators to start at arbitrary position --- src/nvim/buffer.c | 51 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 19 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 8491e77e73..580eb07d6b 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -74,6 +74,12 @@ #include "nvim/os/time.h" #include "nvim/os/input.h" +typedef enum { + kBLSUnchanged = 0, + kBLSChanged = 1, + kBLSDeleted = 2, +} BufhlLineStatus; + #ifdef INCLUDE_GENERATED_DECLARATIONS # include "buffer.c.generated.h" #endif @@ -5228,21 +5234,21 @@ void bufhl_clear_line_range(buf_T *buf, return; } linenr_T first_changed = MAXLNUM, last_changed = -1; - // TODO: implement kb_itr_interval and jump directly to the first line + kbitr_t itr; - BufhlLine *l; - for (kb_itr_first(bufhl, buf->b_bufhl_info, &itr); - kb_itr_valid(&itr); - kb_itr_next(bufhl, buf->b_bufhl_info, &itr)) { + BufhlLine *l, t = {line_start}; + if (!kb_itr_get(bufhl, buf->b_bufhl_info, &t, &itr)) { + kb_itr_next(bufhl, buf->b_bufhl_info, &itr); + } + for (; kb_itr_valid(&itr); kb_itr_next(bufhl, buf->b_bufhl_info, &itr)) { l = kb_itr_key(BufhlLine *, &itr); linenr_T line = l->line; - if (line < line_start) { - continue; - } else if (line > line_end) { + if (line > line_end) { break; } if (line_start <= line && line <= line_end) { - if (bufhl_clear_line(buf->b_bufhl_info, src_id, line)) { + BufhlLineStatus status = bufhl_clear_line(buf->b_bufhl_info, src_id, line); + if (status != kBLSUnchanged) { if (line > last_changed) { last_changed = line; } @@ -5250,6 +5256,9 @@ void bufhl_clear_line_range(buf_T *buf, first_changed = line; } } + if (status == kBLSDeleted) { + kb_del_itr(bufhl, buf->b_bufhl_info, &itr); + } } } @@ -5264,8 +5273,8 @@ void bufhl_clear_line_range(buf_T *buf, /// @param bufhl_info The highlight info for the buffer /// @param src_id Highlight source group to clear, or -1 to clear all groups. /// @param lnum Linenr where the highlight should be cleared -static bool bufhl_clear_line(bufhl_info_T *bufhl_info, int src_id, - linenr_T lnum) +static BufhlLineStatus bufhl_clear_line(bufhl_info_T *bufhl_info, int src_id, + linenr_T lnum) { BufhlLine *lineinfo = bufhl_tree_ref(bufhl_info, lnum, false); size_t oldsize = kv_size(lineinfo->items); @@ -5286,9 +5295,9 @@ static bool bufhl_clear_line(bufhl_info_T *bufhl_info, int src_id, if (kv_size(lineinfo->items) == 0) { kv_destroy(lineinfo->items); - kb_del(bufhl, bufhl_info, lineinfo); + return kBLSDeleted; } - return kv_size(lineinfo->items) != oldsize; + return kv_size(lineinfo->items) != oldsize ? kBLSChanged : kBLSUnchanged; } /// Remove all highlights and free the highlight data @@ -5315,15 +5324,19 @@ void bufhl_mark_adjust(buf_T* buf, // we need to detect this case and kbitr_t itr; - BufhlLine *l; - for (kb_itr_first(bufhl, buf->b_bufhl_info, &itr); - kb_itr_valid(&itr); - kb_itr_next(bufhl, buf->b_bufhl_info, &itr)) { + BufhlLine *l, t = {line1}; + if (!kb_itr_get(bufhl, buf->b_bufhl_info, &t, &itr)) { + kb_itr_next(bufhl, buf->b_bufhl_info, &itr); + } + for (; kb_itr_valid(&itr); kb_itr_next(bufhl, buf->b_bufhl_info, &itr)) { l = kb_itr_key(BufhlLine *, &itr); if (l->line >= line1 && l->line <= line2) { if (amount == MAXLNUM) { - bufhl_clear_line(buf->b_bufhl_info, -1, l->line); - continue; + if (bufhl_clear_line(buf->b_bufhl_info, -1, l->line) == kBLSDeleted) { + kb_del_itr(bufhl, buf->b_bufhl_info, &itr); + } else { + assert(false); + } } else { l->line += amount; } -- cgit From 53cf88c27bcea1099d48a1ca6dc0a4d7c44e0a98 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sat, 6 Aug 2016 09:15:43 +0200 Subject: kbtree: use proper structs --- src/nvim/buffer.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 580eb07d6b..26dc07e4bc 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -5202,7 +5202,7 @@ int bufhl_add_hl(buf_T *buf, return src_id; } if (!buf->b_bufhl_info) { - buf->b_bufhl_info = kb_init(bufhl, KB_DEFAULT_SIZE); + buf->b_bufhl_info = kb_init(bufhl); } BufhlLine *lineinfo = bufhl_tree_ref(buf->b_bufhl_info, lnum, true); @@ -5235,13 +5235,13 @@ void bufhl_clear_line_range(buf_T *buf, } linenr_T first_changed = MAXLNUM, last_changed = -1; - kbitr_t itr; + kbitr_t(bufhl) itr; BufhlLine *l, t = {line_start}; if (!kb_itr_get(bufhl, buf->b_bufhl_info, &t, &itr)) { kb_itr_next(bufhl, buf->b_bufhl_info, &itr); } for (; kb_itr_valid(&itr); kb_itr_next(bufhl, buf->b_bufhl_info, &itr)) { - l = kb_itr_key(BufhlLine *, &itr); + l = kb_itr_key(&itr); linenr_T line = l->line; if (line > line_end) { break; @@ -5323,13 +5323,13 @@ void bufhl_mark_adjust(buf_T* buf, // XXX: does not support move // we need to detect this case and - kbitr_t itr; + kbitr_t(bufhl) itr; BufhlLine *l, t = {line1}; if (!kb_itr_get(bufhl, buf->b_bufhl_info, &t, &itr)) { kb_itr_next(bufhl, buf->b_bufhl_info, &itr); } for (; kb_itr_valid(&itr); kb_itr_next(bufhl, buf->b_bufhl_info, &itr)) { - l = kb_itr_key(BufhlLine *, &itr); + l = kb_itr_key(&itr); if (l->line >= line1 && l->line <= line2) { if (amount == MAXLNUM) { if (bufhl_clear_line(buf->b_bufhl_info, -1, l->line) == kBLSDeleted) { -- cgit From 14e19b8aaf458270ec94deb941be8ee78706851a Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sun, 28 Aug 2016 13:01:33 +0200 Subject: kbtree: eliminate unneccesary heap allocation --- src/nvim/buffer.c | 57 +++++++++++++++++++++---------------------------------- 1 file changed, 22 insertions(+), 35 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 26dc07e4bc..fc28b0de70 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -5201,11 +5201,8 @@ int bufhl_add_hl(buf_T *buf, // no highlight group or invalid line, just return src_id return src_id; } - if (!buf->b_bufhl_info) { - buf->b_bufhl_info = kb_init(bufhl); - } - BufhlLine *lineinfo = bufhl_tree_ref(buf->b_bufhl_info, lnum, true); + BufhlLine *lineinfo = bufhl_tree_ref(&buf->b_bufhl_info, lnum, true); bufhl_hl_item_T *hlentry = kv_pushp(lineinfo->items); hlentry->src_id = src_id; @@ -5229,25 +5226,23 @@ int bufhl_add_hl(buf_T *buf, void bufhl_clear_line_range(buf_T *buf, int src_id, linenr_T line_start, - linenr_T line_end) { - if (!buf->b_bufhl_info) { - return; - } + linenr_T line_end) +{ linenr_T first_changed = MAXLNUM, last_changed = -1; kbitr_t(bufhl) itr; BufhlLine *l, t = {line_start}; - if (!kb_itr_get(bufhl, buf->b_bufhl_info, &t, &itr)) { - kb_itr_next(bufhl, buf->b_bufhl_info, &itr); + if (!kb_itr_get(bufhl, &buf->b_bufhl_info, &t, &itr)) { + kb_itr_next(bufhl, &buf->b_bufhl_info, &itr); } - for (; kb_itr_valid(&itr); kb_itr_next(bufhl, buf->b_bufhl_info, &itr)) { + for (; kb_itr_valid(&itr); kb_itr_next(bufhl, &buf->b_bufhl_info, &itr)) { l = kb_itr_key(&itr); linenr_T line = l->line; if (line > line_end) { break; } if (line_start <= line && line <= line_end) { - BufhlLineStatus status = bufhl_clear_line(buf->b_bufhl_info, src_id, line); + BufhlLineStatus status = bufhl_clear_line(l, src_id, line); if (status != kBLSUnchanged) { if (line > last_changed) { last_changed = line; @@ -5257,7 +5252,8 @@ void bufhl_clear_line_range(buf_T *buf, } } if (status == kBLSDeleted) { - kb_del_itr(bufhl, buf->b_bufhl_info, &itr); + kb_del_itr(bufhl, &buf->b_bufhl_info, &itr); + xfree(l); } } } @@ -5273,10 +5269,9 @@ void bufhl_clear_line_range(buf_T *buf, /// @param bufhl_info The highlight info for the buffer /// @param src_id Highlight source group to clear, or -1 to clear all groups. /// @param lnum Linenr where the highlight should be cleared -static BufhlLineStatus bufhl_clear_line(bufhl_info_T *bufhl_info, int src_id, +static BufhlLineStatus bufhl_clear_line(BufhlLine *lineinfo, int src_id, linenr_T lnum) { - BufhlLine *lineinfo = bufhl_tree_ref(bufhl_info, lnum, false); size_t oldsize = kv_size(lineinfo->items); if (src_id < 0) { kv_size(lineinfo->items) = 0; @@ -5303,12 +5298,8 @@ static BufhlLineStatus bufhl_clear_line(bufhl_info_T *bufhl_info, int src_id, /// Remove all highlights and free the highlight data void bufhl_clear_all(buf_T *buf) { - if (!buf->b_bufhl_info) { - return; - } bufhl_clear_line_range(buf, -1, 1, MAXLNUM); - kb_destroy(bufhl, buf->b_bufhl_info); - buf->b_bufhl_info = NULL; + kb_destroy(bufhl, (&buf->b_bufhl_info)); } /// Adjust a placed highlight for inserted/deleted lines. @@ -5316,24 +5307,23 @@ void bufhl_mark_adjust(buf_T* buf, linenr_T line1, linenr_T line2, long amount, - long amount_after) { - if (!buf->b_bufhl_info) { - return; - } + long amount_after) +{ // XXX: does not support move // we need to detect this case and kbitr_t(bufhl) itr; BufhlLine *l, t = {line1}; - if (!kb_itr_get(bufhl, buf->b_bufhl_info, &t, &itr)) { - kb_itr_next(bufhl, buf->b_bufhl_info, &itr); + if (!kb_itr_get(bufhl, &buf->b_bufhl_info, &t, &itr)) { + kb_itr_next(bufhl, &buf->b_bufhl_info, &itr); } - for (; kb_itr_valid(&itr); kb_itr_next(bufhl, buf->b_bufhl_info, &itr)) { + for (; kb_itr_valid(&itr); kb_itr_next(bufhl, &buf->b_bufhl_info, &itr)) { l = kb_itr_key(&itr); if (l->line >= line1 && l->line <= line2) { if (amount == MAXLNUM) { - if (bufhl_clear_line(buf->b_bufhl_info, -1, l->line) == kBLSDeleted) { - kb_del_itr(bufhl, buf->b_bufhl_info, &itr); + if (bufhl_clear_line(l, -1, l->line) == kBLSDeleted) { + kb_del_itr(bufhl, &buf->b_bufhl_info, &itr); + xfree(l); } else { assert(false); } @@ -5356,12 +5346,9 @@ void bufhl_mark_adjust(buf_T* buf, /// @param lnum The line number /// @param[out] info The highligts for the line /// @return true if there was highlights to display -bool bufhl_start_line(buf_T *buf, linenr_T lnum, bufhl_lineinfo_T *info) { - if (!buf->b_bufhl_info) { - return false; - } - - BufhlLine *lineinfo = bufhl_tree_ref(buf->b_bufhl_info, lnum, false); +bool bufhl_start_line(buf_T *buf, linenr_T lnum, bufhl_lineinfo_T *info) +{ + BufhlLine *lineinfo = bufhl_tree_ref(&buf->b_bufhl_info, lnum, false); if (!lineinfo) { return false; } -- cgit From 28a549d597a286330ba87ff4fffe1e2d09e0f611 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sun, 28 Aug 2016 13:26:01 +0200 Subject: kbtree: make warning free and delete deprecated macros --- src/nvim/buffer.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index fc28b0de70..39014d903a 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -5144,22 +5144,25 @@ void sign_mark_adjust(linenr_T line1, linenr_T line2, long amount, long amount_a // bufhl: plugin highlights associated with a buffer -/// Get reference to line in kbtree_t, allocating it if neccessary. +/// Get reference to line in kbtree_t +/// +/// @param b the three +/// @param line the linenumber to lookup +/// @param put if true, put a new line when not found +/// if false, return NULL when not found BufhlLine *bufhl_tree_ref(kbtree_t(bufhl) *b, linenr_T line, bool put) { - BufhlLine t, *p, **pp; - t.line = line; + BufhlLine t = BUFHLLINE_INIT(line); - // put() only works if key is absent - pp = kb_get(bufhl, b, &t); + // kp_put() only works if key is absent, try get first + BufhlLine **pp = kb_get(bufhl, b, &t); if (pp) { return *pp; } else if (!put) { return NULL; } - p = xcalloc(sizeof(*p), 1); - p->line = line; - // p->items zero initialized + BufhlLine *p = xmalloc(sizeof(*p)); + *p = (BufhlLine)BUFHLLINE_INIT(line); kb_put(bufhl, b, p); return p; } @@ -5231,7 +5234,7 @@ void bufhl_clear_line_range(buf_T *buf, linenr_T first_changed = MAXLNUM, last_changed = -1; kbitr_t(bufhl) itr; - BufhlLine *l, t = {line_start}; + BufhlLine *l, t = BUFHLLINE_INIT(line_start); if (!kb_itr_get(bufhl, &buf->b_bufhl_info, &t, &itr)) { kb_itr_next(bufhl, &buf->b_bufhl_info, &itr); } @@ -5313,7 +5316,7 @@ void bufhl_mark_adjust(buf_T* buf, // we need to detect this case and kbitr_t(bufhl) itr; - BufhlLine *l, t = {line1}; + BufhlLine *l, t = BUFHLLINE_INIT(line1); if (!kb_itr_get(bufhl, &buf->b_bufhl_info, &t, &itr)) { kb_itr_next(bufhl, &buf->b_bufhl_info, &itr); } -- cgit From 7873660e1ebbb6350609f4200296fc2ac4bf3035 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sun, 28 Aug 2016 13:32:48 +0200 Subject: bufhl: some style cleanup --- src/nvim/buffer.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 39014d903a..ebb38fe709 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -5150,7 +5150,8 @@ void sign_mark_adjust(linenr_T line1, linenr_T line2, long amount, long amount_a /// @param line the linenumber to lookup /// @param put if true, put a new line when not found /// if false, return NULL when not found -BufhlLine *bufhl_tree_ref(kbtree_t(bufhl) *b, linenr_T line, bool put) { +BufhlLine *bufhl_tree_ref(BufhlInfo *b, linenr_T line, bool put) +{ BufhlLine t = BUFHLLINE_INIT(line); // kp_put() only works if key is absent, try get first @@ -5207,7 +5208,7 @@ int bufhl_add_hl(buf_T *buf, BufhlLine *lineinfo = bufhl_tree_ref(&buf->b_bufhl_info, lnum, true); - bufhl_hl_item_T *hlentry = kv_pushp(lineinfo->items); + BufhlItem *hlentry = kv_pushp(lineinfo->items); hlentry->src_id = src_id; hlentry->hl_id = hl_id; hlentry->start = col_start; @@ -5279,16 +5280,16 @@ static BufhlLineStatus bufhl_clear_line(BufhlLine *lineinfo, int src_id, if (src_id < 0) { kv_size(lineinfo->items) = 0; } else { - size_t newind = 0; + size_t newidx = 0; for (size_t i = 0; i < kv_size(lineinfo->items); i++) { if (kv_A(lineinfo->items, i).src_id != src_id) { - if (i != newind) { - kv_A(lineinfo->items, newind) = kv_A(lineinfo->items, i); + if (i != newidx) { + kv_A(lineinfo->items, newidx) = kv_A(lineinfo->items, i); } - newind++; + newidx++; } } - kv_size(lineinfo->items) = newind; + kv_size(lineinfo->items) = newidx; } if (kv_size(lineinfo->items) == 0) { @@ -5349,7 +5350,7 @@ void bufhl_mark_adjust(buf_T* buf, /// @param lnum The line number /// @param[out] info The highligts for the line /// @return true if there was highlights to display -bool bufhl_start_line(buf_T *buf, linenr_T lnum, bufhl_lineinfo_T *info) +bool bufhl_start_line(buf_T *buf, linenr_T lnum, BufhlLineInfo *info) { BufhlLine *lineinfo = bufhl_tree_ref(&buf->b_bufhl_info, lnum, false); if (!lineinfo) { @@ -5370,14 +5371,14 @@ bool bufhl_start_line(buf_T *buf, linenr_T lnum, bufhl_lineinfo_T *info) /// @param info The info returned by bufhl_start_line /// @param col The column to get the attr for /// @return The highilight attr to display at the column -int bufhl_get_attr(bufhl_lineinfo_T *info, colnr_T col) { +int bufhl_get_attr(BufhlLineInfo *info, colnr_T col) { if (col <= info->valid_to) { return info->current; } int attr = 0; info->valid_to = MAXCOL; for (size_t i = 0; i < kv_size(info->entries); i++) { - bufhl_hl_item_T entry = kv_A(info->entries, i); + BufhlItem entry = kv_A(info->entries, i); if (entry.start <= col && col <= entry.stop) { int entry_attr = syn_id2attr(entry.hl_id); attr = hl_combine_attr(attr, entry_attr); -- cgit From 8b375cf471359ad7632af7fa6a2298c9b7596691 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sun, 28 Aug 2016 15:36:18 +0200 Subject: bufhl: fix move --- src/nvim/buffer.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'src/nvim/buffer.c') diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index ebb38fe709..b5ca6543c5 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -5304,6 +5304,9 @@ void bufhl_clear_all(buf_T *buf) { bufhl_clear_line_range(buf, -1, 1, MAXLNUM); kb_destroy(bufhl, (&buf->b_bufhl_info)); + kb_init(&buf->b_bufhl_info); + kv_destroy(buf->b_bufhl_move_space); + kv_init(buf->b_bufhl_move_space); } /// Adjust a placed highlight for inserted/deleted lines. @@ -5311,19 +5314,32 @@ void bufhl_mark_adjust(buf_T* buf, linenr_T line1, linenr_T line2, long amount, - long amount_after) + long amount_after, + bool end_temp) { - // XXX: does not support move - // we need to detect this case and - kbitr_t(bufhl) itr; BufhlLine *l, t = BUFHLLINE_INIT(line1); + if (end_temp && amount < 0) { + // Move all items from b_bufhl_move_space to the btree. + for (size_t i = 0; i < kv_size(buf->b_bufhl_move_space); i++) { + l = kv_A(buf->b_bufhl_move_space, i); + l->line += amount; + kb_put(bufhl, &buf->b_bufhl_info, l); + } + kv_size(buf->b_bufhl_move_space) = 0; + return; + } + if (!kb_itr_get(bufhl, &buf->b_bufhl_info, &t, &itr)) { kb_itr_next(bufhl, &buf->b_bufhl_info, &itr); } for (; kb_itr_valid(&itr); kb_itr_next(bufhl, &buf->b_bufhl_info, &itr)) { l = kb_itr_key(&itr); if (l->line >= line1 && l->line <= line2) { + if (end_temp && amount > 0) { + kb_del_itr(bufhl, &buf->b_bufhl_info, &itr); + kv_push(buf->b_bufhl_move_space, l); + } if (amount == MAXLNUM) { if (bufhl_clear_line(l, -1, l->line) == kBLSDeleted) { kb_del_itr(bufhl, &buf->b_bufhl_info, &itr); @@ -5371,7 +5387,8 @@ bool bufhl_start_line(buf_T *buf, linenr_T lnum, BufhlLineInfo *info) /// @param info The info returned by bufhl_start_line /// @param col The column to get the attr for /// @return The highilight attr to display at the column -int bufhl_get_attr(BufhlLineInfo *info, colnr_T col) { +int bufhl_get_attr(BufhlLineInfo *info, colnr_T col) +{ if (col <= info->valid_to) { return info->current; } -- cgit