From ca1a00edd6d6345b848a28d077d6a192528f811e Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Tue, 14 Jan 2020 12:45:09 +0100 Subject: extmarks/bufhl: reimplement using new marktree data structure Add new "splice" interface for tracking buffer changes at the byte level. This will later be reused for byte-resolution buffer updates. (Implementation has been started, but using undocumented "_on_bytes" option now as interface hasn't been finalized). Use this interface to improve many edge cases of extmark adjustment. Changed tests indicate previously incorrect behavior. Adding tests for more edge cases will be follow-up work (overlaps on_bytes tests) Don't consider creation/deletion of marks an undoable event by itself. This behavior was never documented, and imposes complexity for little gain. Add nvim__buf_add_decoration temporary API for direct access to the new implementation. This should be refactored into a proper API for decorations, probably involving a huge dict. fixes #11598 --- src/nvim/indent.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/nvim/indent.c') diff --git a/src/nvim/indent.c b/src/nvim/indent.c index efbfea33aa..2c5fdd8ea6 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -13,6 +13,7 @@ #include "nvim/charset.h" #include "nvim/cursor.h" #include "nvim/mark.h" +#include "nvim/mark_extended.h" #include "nvim/memline.h" #include "nvim/memory.h" #include "nvim/misc1.h" @@ -88,6 +89,7 @@ int get_indent_str(char_u *ptr, int ts, int list) // SIN_CHANGED: call changed_bytes() if the line was changed. // SIN_INSERT: insert the indent in front of the line. // SIN_UNDO: save line for undo before changing it. +// SIN_NOMARK: don't move extmarks (because just after ml_append or something) // @param size measured in spaces // Returns true if the line was changed. int set_indent(int size, int flags) @@ -205,6 +207,7 @@ int set_indent(int size, int flags) // If 'preserveindent' and 'expandtab' are both set keep the original // characters and allocate accordingly. We will fill the rest with spaces // after the if (!curbuf->b_p_et) below. + int skipcols = 0; // number of columns (in bytes) that were presved if (orig_char_len != -1) { int newline_size; // = orig_char_len + size - ind_done + line_len STRICT_ADD(orig_char_len, size, &newline_size, int); @@ -219,6 +222,7 @@ int set_indent(int size, int flags) ind_len = orig_char_len + todo; p = oldline; s = newline; + skipcols = orig_char_len; while (orig_char_len > 0) { *s++ = *p++; @@ -263,6 +267,7 @@ int set_indent(int size, int flags) ind_done++; } *s++ = *p++; + skipcols++; } // Fill to next tabstop with a tab, if possible. @@ -290,6 +295,13 @@ int set_indent(int size, int flags) // Replace the line (unless undo fails). if (!(flags & SIN_UNDO) || (u_savesub(curwin->w_cursor.lnum) == OK)) { ml_replace(curwin->w_cursor.lnum, newline, false); + if (!(flags & SIN_NOMARK)) { + extmark_splice(curbuf, + (int)curwin->w_cursor.lnum-1, skipcols, + 0, (int)(p-oldline) - skipcols, + 0, (int)(s-newline) - skipcols, + kExtmarkUndo); + } if (flags & SIN_CHANGED) { changed_bytes(curwin->w_cursor.lnum, 0); -- cgit From 48a869dc6d29514e943070da9f22f702f5179826 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Mon, 20 Jan 2020 19:29:12 +0100 Subject: shed biking: it's always extmarks, never marks extended --- src/nvim/indent.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/indent.c') diff --git a/src/nvim/indent.c b/src/nvim/indent.c index 2c5fdd8ea6..f8018c039d 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -13,7 +13,7 @@ #include "nvim/charset.h" #include "nvim/cursor.h" #include "nvim/mark.h" -#include "nvim/mark_extended.h" +#include "nvim/extmark.h" #include "nvim/memline.h" #include "nvim/memory.h" #include "nvim/misc1.h" -- cgit From 0f18c718cd91056d6eef5618fbb356b6c8ba1aa8 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Tue, 24 Mar 2020 22:59:28 -0400 Subject: vim-patch:8.2.0027: still some /* */ comments Problem: Still some /* */ comments. Solution: Convert to // comments. https://github.com/vim/vim/commit/aa2f0ee639d3b59e4402261ebee27bf545a62d8b --- src/nvim/indent.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'src/nvim/indent.c') diff --git a/src/nvim/indent.c b/src/nvim/indent.c index f8018c039d..7f17fb0035 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -56,7 +56,8 @@ int get_indent_buf(buf_T *buf, linenr_T lnum) // Count the size (in window cells) of the indent in line "ptr", with // 'tabstop' at "ts". // If @param list is TRUE, count only screen size for tabs. -int get_indent_str(char_u *ptr, int ts, int list) +int get_indent_str(const char_u *ptr, int ts, int list) + FUNC_ATTR_NONNULL_ALL { int count = 0; @@ -375,12 +376,12 @@ int get_number_indent(linenr_T lnum) * parameters into account. Window must be specified, since it is not * necessarily always the current one. */ -int get_breakindent_win(win_T *wp, char_u *line) - FUNC_ATTR_NONNULL_ARG(1) +int get_breakindent_win(win_T *wp, const char_u *line) + FUNC_ATTR_NONNULL_ALL { static int prev_indent = 0; // Cached indent value. static long prev_ts = 0; // Cached tabstop value. - static char_u *prev_line = NULL; // cached pointer to line. + static const char_u *prev_line = NULL; // cached pointer to line. static varnumber_T prev_tick = 0; // Changedtick of cached value. int bri = 0; // window width minus window margin space, i.e. what rests for text @@ -389,7 +390,7 @@ int get_breakindent_win(win_T *wp, char_u *line) && (vim_strchr(p_cpo, CPO_NUMCOL) == NULL) ? number_width(wp) + 1 : 0); - /* used cached indent, unless pointer or 'tabstop' changed */ + // used cached indent, unless pointer or 'tabstop' changed if (prev_line != line || prev_ts != wp->w_buffer->b_p_ts || prev_tick != buf_get_changedtick(wp->w_buffer)) { prev_line = line; @@ -399,21 +400,22 @@ int get_breakindent_win(win_T *wp, char_u *line) } bri = prev_indent + wp->w_p_brishift; - /* indent minus the length of the showbreak string */ - if (wp->w_p_brisbr) + // indent minus the length of the showbreak string + if (wp->w_p_brisbr) { bri -= vim_strsize(p_sbr); - - /* Add offset for number column, if 'n' is in 'cpoptions' */ + } + // Add offset for number column, if 'n' is in 'cpoptions' bri += win_col_off2(wp); - /* never indent past left window margin */ - if (bri < 0) + // never indent past left window margin + if (bri < 0) { bri = 0; - /* always leave at least bri_min characters on the left, - * if text width is sufficient */ - else if (bri > eff_wwidth - wp->w_p_brimin) + } else if (bri > eff_wwidth - wp->w_p_brimin) { + // always leave at least bri_min characters on the left, + // if text width is sufficient bri = (eff_wwidth - wp->w_p_brimin < 0) ? 0 : eff_wwidth - wp->w_p_brimin; + } return bri; } -- cgit From adcabb73bc48732df420e9de7b067ebba2f25f55 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 10 May 2020 23:36:05 -0400 Subject: vim-patch:8.2.0309: window-local values have confusing name Problem: Window-local values have confusing name. Solution: Rename w_p_bri* to w_briopt_*. https://github.com/vim/vim/commit/b81f56fb57c87a7490dd79908c257437d1958447 --- src/nvim/indent.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/nvim/indent.c') diff --git a/src/nvim/indent.c b/src/nvim/indent.c index 7f17fb0035..fb277b25fd 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -398,10 +398,10 @@ int get_breakindent_win(win_T *wp, const char_u *line) prev_tick = buf_get_changedtick(wp->w_buffer); prev_indent = get_indent_str(line, (int)wp->w_buffer->b_p_ts, wp->w_p_list); } - bri = prev_indent + wp->w_p_brishift; + bri = prev_indent + wp->w_briopt_shift; // indent minus the length of the showbreak string - if (wp->w_p_brisbr) { + if (wp->w_briopt_sbr) { bri -= vim_strsize(p_sbr); } // Add offset for number column, if 'n' is in 'cpoptions' @@ -410,11 +410,11 @@ int get_breakindent_win(win_T *wp, const char_u *line) // never indent past left window margin if (bri < 0) { bri = 0; - } else if (bri > eff_wwidth - wp->w_p_brimin) { + } else if (bri > eff_wwidth - wp->w_briopt_min) { // always leave at least bri_min characters on the left, // if text width is sufficient - bri = (eff_wwidth - wp->w_p_brimin < 0) - ? 0 : eff_wwidth - wp->w_p_brimin; + bri = (eff_wwidth - wp->w_briopt_min < 0) + ? 0 : eff_wwidth - wp->w_briopt_min; } return bri; -- cgit