aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/doc/options.txt2
-rw-r--r--runtime/doc/vim_diff.txt1
-rw-r--r--src/nvim/api/buffer.c2
-rw-r--r--src/nvim/buffer.c14
-rw-r--r--src/nvim/buffer.h42
-rw-r--r--src/nvim/buffer_defs.h13
-rw-r--r--src/nvim/buffer_updates.c7
-rw-r--r--src/nvim/edit.c12
-rw-r--r--src/nvim/eval.c6
-rw-r--r--src/nvim/ex_cmds.c33
-rw-r--r--src/nvim/ex_docmd.c16
-rw-r--r--src/nvim/fileio.c14
-rw-r--r--src/nvim/indent.c20
-rw-r--r--src/nvim/main.c2
-rw-r--r--src/nvim/memline.c4
-rw-r--r--src/nvim/misc1.c8
-rw-r--r--src/nvim/normal.c6
-rw-r--r--src/nvim/options.lua2
-rw-r--r--src/nvim/search.c27
-rw-r--r--src/nvim/syntax.c5
-rw-r--r--src/nvim/tag.c43
-rw-r--r--src/nvim/testdir/test_tagjump.vim42
-rw-r--r--src/nvim/undo.c2
-rw-r--r--test/functional/ex_cmds/drop_spec.lua3
-rw-r--r--test/functional/legacy/108_backtrace_debug_commands_spec.lua2
-rw-r--r--test/functional/options/shortmess_spec.lua2
-rw-r--r--test/functional/ui/input_spec.lua2
27 files changed, 230 insertions, 102 deletions
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
index f924003e1f..81726ca46b 100644
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -5293,7 +5293,7 @@ A jump table for the options with a short description can be found at |Q_op|.
function to get the effective shiftwidth value.
*'shortmess'* *'shm'*
-'shortmess' 'shm' string (Vim default "filnxtToO", Vi default: "")
+'shortmess' 'shm' string (Vim default "filnxtToOF", Vi default: "")
global
This option helps to avoid all the |hit-enter| prompts caused by file
messages, for example with CTRL-G, and to avoid some other messages.
diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt
index 0035e15be1..52f6b3d918 100644
--- a/runtime/doc/vim_diff.txt
+++ b/runtime/doc/vim_diff.txt
@@ -49,6 +49,7 @@ a complete and centralized reference of those differences.
- 'nrformats' defaults to "bin,hex"
- 'ruler' is set by default
- 'sessionoptions' doesn't include "options"
+- 'shortmess' sets "F" flag
- 'showcmd' is set by default
- 'sidescroll' defaults to 1
- 'smarttab' is set by default
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c
index e1fe7617ff..b5dd72c513 100644
--- a/src/nvim/api/buffer.c
+++ b/src/nvim/api/buffer.c
@@ -496,7 +496,7 @@ Integer nvim_buf_get_changedtick(Buffer buffer, Error *err)
return -1;
}
- return buf->b_changedtick;
+ return buf_get_changedtick(buf);
}
/// Gets a list of buffer-local |mapping| definitions.
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index b1f44277c7..19c17a9d68 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -343,7 +343,7 @@ open_buffer (
void set_bufref(bufref_T *bufref, buf_T *buf)
{
bufref->br_buf = buf;
- bufref->br_fnum = buf->b_fnum;
+ bufref->br_fnum = buf == NULL ? 0 : buf->b_fnum;
bufref->br_buf_free_count = buf_free_count;
}
@@ -1555,7 +1555,7 @@ static inline void buf_init_changedtick(buf_T *const buf)
.di_tv = (typval_T) {
.v_type = VAR_NUMBER,
.v_lock = VAR_FIXED,
- .vval.v_number = buf->b_changedtick,
+ .vval.v_number = buf_get_changedtick(buf),
},
.di_key = "changedtick",
};
@@ -1901,10 +1901,10 @@ int buflist_getfile(int n, linenr_T lnum, int options, int forceit)
}
}
- ++RedrawingDisabled;
- if (getfile(buf->b_fnum, NULL, NULL, (options & GETF_SETMARK),
- lnum, forceit) <= 0) {
- --RedrawingDisabled;
+ RedrawingDisabled++;
+ if (GETFILE_SUCCESS(getfile(buf->b_fnum, NULL, NULL,
+ (options & GETF_SETMARK), lnum, forceit))) {
+ RedrawingDisabled--;
/* cursor is at to BOL and w_cursor.lnum is checked due to getfile() */
if (!p_sol && col != 0) {
@@ -1915,7 +1915,7 @@ int buflist_getfile(int n, linenr_T lnum, int options, int forceit)
}
return OK;
}
- --RedrawingDisabled;
+ RedrawingDisabled--;
return FAIL;
}
diff --git a/src/nvim/buffer.h b/src/nvim/buffer.h
index faeeed121c..e61c312fb1 100644
--- a/src/nvim/buffer.h
+++ b/src/nvim/buffer.h
@@ -17,6 +17,15 @@ enum getf_values {
GETF_SWITCH = 0x04, // respect 'switchbuf' settings when jumping
};
+// Return values of getfile()
+enum getf_retvalues {
+ GETFILE_ERROR = 1, // normal error
+ GETFILE_NOT_WRITTEN = 2, // "not written" error
+ GETFILE_SAME_FILE = 0, // success, same file
+ GETFILE_OPEN_OTHER = -1, // success, opened another file
+ GETFILE_UNUSED = 8
+};
+
// Values for buflist_new() flags
enum bln_values {
BLN_CURBUF = 1, // May re-use curbuf for new buffer
@@ -87,7 +96,7 @@ static inline void buf_set_changedtick(buf_T *const buf,
const varnumber_T changedtick)
REAL_FATTR_NONNULL_ALL REAL_FATTR_ALWAYS_INLINE;
-/// Set b_changedtick and corresponding variable
+/// Set b:changedtick, also checking b: for consistency in debug build
///
/// @param[out] buf Buffer to set changedtick in.
/// @param[in] changedtick New value.
@@ -105,10 +114,35 @@ static inline void buf_set_changedtick(buf_T *const buf,
assert(changedtick_di->di_flags == (DI_FLAGS_RO|DI_FLAGS_FIX));
# endif
assert(changedtick_di == (dictitem_T *)&buf->changedtick_di);
- assert(&buf->b_changedtick // -V501
- == &buf->changedtick_di.di_tv.vval.v_number);
#endif
- buf->b_changedtick = changedtick;
+ buf->changedtick_di.di_tv.vval.v_number = changedtick;
+}
+
+static inline varnumber_T buf_get_changedtick(const buf_T *const buf)
+ REAL_FATTR_NONNULL_ALL REAL_FATTR_ALWAYS_INLINE REAL_FATTR_PURE
+ REAL_FATTR_WARN_UNUSED_RESULT;
+
+/// Get b:changedtick value
+///
+/// Faster then querying b:.
+///
+/// @param[in] buf Buffer to get b:changedtick from.
+static inline varnumber_T buf_get_changedtick(const buf_T *const buf)
+{
+ return buf->changedtick_di.di_tv.vval.v_number;
+}
+
+static inline void buf_inc_changedtick(buf_T *const buf)
+ REAL_FATTR_NONNULL_ALL REAL_FATTR_ALWAYS_INLINE;
+
+/// Increment b:changedtick value
+///
+/// Also checks b: for consistency in case of debug build.
+///
+/// @param[in,out] buf Buffer to increment value in.
+static inline void buf_inc_changedtick(buf_T *const buf)
+{
+ buf_set_changedtick(buf, buf_get_changedtick(buf) + 1);
}
#define WITH_BUFFER(b, code) \
diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h
index 50d8c822c1..97e443547c 100644
--- a/src/nvim/buffer_defs.h
+++ b/src/nvim/buffer_defs.h
@@ -41,6 +41,7 @@ typedef struct {
// for kvec
#include "nvim/lib/kvec.h"
+#define GETFILE_SUCCESS(x) ((x) <= 0)
#define MODIFIABLE(buf) (buf->b_p_ma)
/*
@@ -482,9 +483,11 @@ struct file_buffer {
int b_changed; // 'modified': Set to true if something in the
// file has been changed and not written out.
-/// Change identifier incremented for each change, including undo
-#define b_changedtick changedtick_di.di_tv.vval.v_number
- ChangedtickDictItem changedtick_di; // b:changedtick dictionary item.
+
+ /// Change identifier incremented for each change, including undo
+ ///
+ /// This is a dictionary item used to store in b:changedtick.
+ ChangedtickDictItem changedtick_di;
varnumber_T b_last_changedtick; // b:changedtick when TextChanged or
// TextChangedI was last triggered.
@@ -1194,4 +1197,8 @@ static inline int win_hl_attr(win_T *wp, int hlf)
return wp->w_hl_attrs[hlf];
}
+/// Macros defined in Vim, but not in Neovim
+#define CHANGEDTICK(buf) \
+ (=== Include buffer.h & use buf_(get|set|inc)_changedtick ===)
+
#endif // NVIM_BUFFER_DEFS_H
diff --git a/src/nvim/buffer_updates.c b/src/nvim/buffer_updates.c
index c1b2828666..18b53a0685 100644
--- a/src/nvim/buffer_updates.c
+++ b/src/nvim/buffer_updates.c
@@ -6,6 +6,7 @@
#include "nvim/api/private/helpers.h"
#include "nvim/msgpack_rpc/channel.h"
#include "nvim/assert.h"
+#include "nvim/buffer.h"
// Register a channel. Return True if the channel was added, or already added.
// Return False if the channel couldn't be added because the buffer is
@@ -38,7 +39,7 @@ bool buf_updates_register(buf_T *buf, uint64_t channel_id, bool send_buffer)
// the first argument is always the buffer handle
args.items[0] = BUFFER_OBJ(buf->handle);
- args.items[1] = INTEGER_OBJ(buf->b_changedtick);
+ args.items[1] = INTEGER_OBJ(buf_get_changedtick(buf));
// the first line that changed (zero-indexed)
args.items[2] = INTEGER_OBJ(0);
// the last line that was changed
@@ -148,7 +149,7 @@ void buf_updates_send_changes(buf_T *buf,
args.items[0] = BUFFER_OBJ(buf->handle);
// next argument is b:changedtick
- args.items[1] = send_tick ? INTEGER_OBJ(buf->b_changedtick) : NIL;
+ args.items[1] = send_tick ? INTEGER_OBJ(buf_get_changedtick(buf)) : NIL;
// the first line that changed (zero-indexed)
args.items[2] = INTEGER_OBJ(firstline - 1);
@@ -203,7 +204,7 @@ void buf_updates_changedtick_single(buf_T *buf, uint64_t channel_id)
args.items[0] = BUFFER_OBJ(buf->handle);
// next argument is b:changedtick
- args.items[1] = INTEGER_OBJ(buf->b_changedtick);
+ args.items[1] = INTEGER_OBJ(buf_get_changedtick(buf));
// don't try and clean up dead channels here
rpc_send_event(channel_id, "nvim_buf_changedtick_event", args);
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index d4075fc197..bf80f12bd0 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -1386,22 +1386,22 @@ ins_redraw (
last_cursormoved = curwin->w_cursor;
}
- // Trigger TextChangedI if b_changedtick differs.
+ // Trigger TextChangedI if changedtick differs.
if (ready && has_event(EVENT_TEXTCHANGEDI)
- && curbuf->b_last_changedtick != curbuf->b_changedtick
+ && curbuf->b_last_changedtick != buf_get_changedtick(curbuf)
&& !pum_visible()) {
apply_autocmds(EVENT_TEXTCHANGEDI, NULL, NULL, false, curbuf);
- curbuf->b_last_changedtick = curbuf->b_changedtick;
+ curbuf->b_last_changedtick = buf_get_changedtick(curbuf);
}
- // Trigger TextChangedP if b_changedtick differs. When the popupmenu closes
+ // Trigger TextChangedP if changedtick differs. When the popupmenu closes
// TextChangedI will need to trigger for backwards compatibility, thus use
// different b_last_changedtick* variables.
if (ready && has_event(EVENT_TEXTCHANGEDP)
- && curbuf->b_last_changedtick_pum != curbuf->b_changedtick
+ && curbuf->b_last_changedtick_pum != buf_get_changedtick(curbuf)
&& pum_visible()) {
apply_autocmds(EVENT_TEXTCHANGEDP, NULL, NULL, false, curbuf);
- curbuf->b_last_changedtick_pum = curbuf->b_changedtick;
+ curbuf->b_last_changedtick_pum = buf_get_changedtick(curbuf);
}
if (must_redraw)
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 5505f5f102..b517169e08 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -7906,7 +7906,7 @@ static void f_diff_hlID(typval_T *argvars, typval_T *rettv, FunPtr fptr)
if (lnum < 0) /* ignore type error in {lnum} arg */
lnum = 0;
if (lnum != prev_lnum
- || changedtick != curbuf->b_changedtick
+ || changedtick != buf_get_changedtick(curbuf)
|| fnum != curbuf->b_fnum) {
/* New line, buffer, change: need to get the values. */
filler_lines = diff_check(curwin, lnum);
@@ -7923,7 +7923,7 @@ static void f_diff_hlID(typval_T *argvars, typval_T *rettv, FunPtr fptr)
} else
hlID = (hlf_T)0;
prev_lnum = lnum;
- changedtick = curbuf->b_changedtick;
+ changedtick = buf_get_changedtick(curbuf);
fnum = curbuf->b_fnum;
}
@@ -9172,7 +9172,7 @@ static dict_T *get_buffer_info(buf_T *buf)
tv_dict_add_nr(dict, S_LEN("loaded"), buf->b_ml.ml_mfp != NULL);
tv_dict_add_nr(dict, S_LEN("listed"), buf->b_p_bl);
tv_dict_add_nr(dict, S_LEN("changed"), bufIsChanged(buf));
- tv_dict_add_nr(dict, S_LEN("changedtick"), buf->b_changedtick);
+ tv_dict_add_nr(dict, S_LEN("changedtick"), buf_get_changedtick(buf));
tv_dict_add_nr(dict, S_LEN("hidden"),
buf->b_ml.ml_mfp != NULL && buf->b_nwindows == 0);
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index d58d006dd0..dbf11514cf 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -2006,11 +2006,14 @@ static int check_readonly(int *forceit, buf_T *buf)
/*
* Try to abandon current file and edit a new or existing file.
- * 'fnum' is the number of the file, if zero use ffname/sfname.
+ * "fnum" is the number of the file, if zero use ffname/sfname.
+ * "lnum" is the line number for the cursor in the new file (if non-zero).
*
- * Return 1 for "normal" error, 2 for "not written" error, 0 for success
- * -1 for successfully opening another file.
- * 'lnum' is the line number for the cursor in the new file (if non-zero).
+ * Return:
+ * GETFILE_ERROR for "normal" error,
+ * GETFILE_NOT_WRITTEN for "not written" error,
+ * GETFILE_SAME_FILE for success
+ * GETFILE_OPEN_OTHER for successfully opening another file.
*/
int getfile(int fnum, char_u *ffname, char_u *sfname, int setpm, linenr_T lnum, int forceit)
{
@@ -2018,10 +2021,12 @@ int getfile(int fnum, char_u *ffname, char_u *sfname, int setpm, linenr_T lnum,
int retval;
char_u *free_me = NULL;
- if (text_locked())
- return 1;
- if (curbuf_locked())
- return 1;
+ if (text_locked()) {
+ return GETFILE_ERROR;
+ }
+ if (curbuf_locked()) {
+ return GETFILE_ERROR;
+ }
if (fnum == 0) {
/* make ffname full path, set sfname */
@@ -2042,7 +2047,7 @@ int getfile(int fnum, char_u *ffname, char_u *sfname, int setpm, linenr_T lnum,
if (curbufIsChanged()) {
no_wait_return--;
EMSG(_(e_nowrtmsg));
- retval = 2; // File has been changed.
+ retval = GETFILE_NOT_WRITTEN; // File has been changed.
goto theend;
}
}
@@ -2056,13 +2061,13 @@ int getfile(int fnum, char_u *ffname, char_u *sfname, int setpm, linenr_T lnum,
}
check_cursor_lnum();
beginline(BL_SOL | BL_FIX);
- retval = 0; // it's in the same file
+ retval = GETFILE_SAME_FILE; // it's in the same file
} else if (do_ecmd(fnum, ffname, sfname, NULL, lnum,
(buf_hide(curbuf) ? ECMD_HIDE : 0)
+ (forceit ? ECMD_FORCEIT : 0), curwin) == OK) {
- retval = -1; // opened another file
+ retval = GETFILE_OPEN_OTHER; // opened another file
} else {
- retval = 1; // error encountered
+ retval = GETFILE_ERROR; // error encountered
}
theend:
@@ -6288,7 +6293,7 @@ void ex_substitute(exarg_T *eap)
garray_T save_view;
win_size_save(&save_view); // Save current window sizes.
save_search_patterns();
- int save_changedtick = curbuf->b_changedtick;
+ int save_changedtick = buf_get_changedtick(curbuf);
time_t save_b_u_time_cur = curbuf->b_u_time_cur;
u_header_T *save_b_u_newhead = curbuf->b_u_newhead;
long save_b_p_ul = curbuf->b_p_ul;
@@ -6305,7 +6310,7 @@ void ex_substitute(exarg_T *eap)
buf_T *preview_buf = do_sub(eap, profile_setlimit(p_rdt), false);
p_hls = save_hls;
- if (save_changedtick != curbuf->b_changedtick) {
+ if (save_changedtick != buf_get_changedtick(curbuf)) {
// Undo invisibly. This also moves the cursor!
if (!u_undo_and_forget(1)) { abort(); }
// Restore newhead. It is meaningless when curhead is valid, but we must
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index f0e4883fdd..c1b9eff697 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -218,11 +218,11 @@ void do_exmode(int improved)
exmode_active = FALSE;
break;
}
- msg_scroll = TRUE;
- need_wait_return = FALSE;
- ex_pressedreturn = FALSE;
- ex_no_reprint = FALSE;
- changedtick = curbuf->b_changedtick;
+ msg_scroll = true;
+ need_wait_return = false;
+ ex_pressedreturn = false;
+ ex_no_reprint = false;
+ changedtick = buf_get_changedtick(curbuf);
prev_msg_row = msg_row;
prev_line = curwin->w_cursor.lnum;
cmdline_row = msg_row;
@@ -230,10 +230,10 @@ void do_exmode(int improved)
lines_left = Rows - 1;
if ((prev_line != curwin->w_cursor.lnum
- || changedtick != curbuf->b_changedtick) && !ex_no_reprint) {
- if (curbuf->b_ml.ml_flags & ML_EMPTY)
+ || changedtick != buf_get_changedtick(curbuf)) && !ex_no_reprint) {
+ if (curbuf->b_ml.ml_flags & ML_EMPTY) {
EMSG(_(e_emptybuf));
- else {
+ } else {
if (ex_pressedreturn) {
/* go up one line, to overwrite the ":<CR>" line, so the
* output doesn't contain empty lines. */
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index 3b6a3a7995..5ddb3952de 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -3566,13 +3566,13 @@ restore_backup:
* writing to the original file and '+' is not in 'cpoptions'. */
if (reset_changed && whole && !append
&& !write_info.bw_conv_error
- && (overwriting || vim_strchr(p_cpo, CPO_PLUS) != NULL)
- ) {
- unchanged(buf, TRUE);
- /* buf->b_changedtick is always incremented in unchanged() but that
- * should not trigger a TextChanged event. */
- if (buf->b_last_changedtick + 1 == buf->b_changedtick) {
- buf->b_last_changedtick = buf->b_changedtick;
+ && (overwriting || vim_strchr(p_cpo, CPO_PLUS) != NULL)) {
+ unchanged(buf, true);
+ const varnumber_T changedtick = buf_get_changedtick(buf);
+ if (buf->b_last_changedtick + 1 == changedtick) {
+ // changedtick is always incremented in unchanged() but that
+ // should not trigger a TextChanged event.
+ buf->b_last_changedtick = changedtick;
}
u_unchanged(buf);
u_update_save_nr(buf);
diff --git a/src/nvim/indent.c b/src/nvim/indent.c
index c94186a1f2..3cc64e0033 100644
--- a/src/nvim/indent.c
+++ b/src/nvim/indent.c
@@ -21,6 +21,7 @@
#include "nvim/search.h"
#include "nvim/strings.h"
#include "nvim/undo.h"
+#include "nvim/buffer.h"
#ifdef INCLUDE_GENERATED_DECLARATIONS
@@ -454,11 +455,13 @@ 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) {
- 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 int prev_tick = 0; // changedtick of cached value
+int get_breakindent_win(win_T *wp, char_u *line)
+ FUNC_ATTR_NONNULL_ARG(1)
+{
+ 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 varnumber_T prev_tick = 0; // Changedtick of cached value.
int bri = 0;
/* window width minus window margin space, i.e. what rests for text */
const int eff_wwidth = wp->w_width
@@ -468,12 +471,11 @@ int get_breakindent_win(win_T *wp, char_u *line) {
/* used cached indent, unless pointer or 'tabstop' changed */
if (prev_line != line || prev_ts != wp->w_buffer->b_p_ts
- || prev_tick != wp->w_buffer->b_changedtick) {
+ || prev_tick != buf_get_changedtick(wp->w_buffer)) {
prev_line = line;
prev_ts = wp->w_buffer->b_p_ts;
- prev_tick = (int)wp->w_buffer->b_changedtick;
- prev_indent = get_indent_str(line,
- (int)wp->w_buffer->b_p_ts, wp->w_p_list);
+ 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;
diff --git a/src/nvim/main.c b/src/nvim/main.c
index 6aed84aba5..ac740eb1f1 100644
--- a/src/nvim/main.c
+++ b/src/nvim/main.c
@@ -603,7 +603,7 @@ void getout(int exitval)
}
buf_T *buf = wp->w_buffer;
- if (buf->b_changedtick != -1) {
+ if (buf_get_changedtick(buf) != -1) {
apply_autocmds(EVENT_BUFWINLEAVE, buf->b_fname,
buf->b_fname, false, buf);
buf_set_changedtick(buf, -1); // note that we did it already
diff --git a/src/nvim/memline.c b/src/nvim/memline.c
index b156f2c513..fc9a1e8271 100644
--- a/src/nvim/memline.c
+++ b/src/nvim/memline.c
@@ -1171,7 +1171,7 @@ void ml_recover(void)
* empty. Don't set the modified flag then. */
if (!(curbuf->b_ml.ml_line_count == 2 && *ml_get(1) == NUL)) {
changed_int();
- buf_set_changedtick(curbuf, curbuf->b_changedtick + 1);
+ buf_inc_changedtick(curbuf);
}
} else {
for (idx = 1; idx <= lnum; ++idx) {
@@ -1181,7 +1181,7 @@ void ml_recover(void)
xfree(p);
if (i != 0) {
changed_int();
- buf_set_changedtick(curbuf, curbuf->b_changedtick + 1);
+ buf_inc_changedtick(curbuf);
break;
}
}
diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c
index 5678360ef0..3d7399f151 100644
--- a/src/nvim/misc1.c
+++ b/src/nvim/misc1.c
@@ -1795,7 +1795,7 @@ void changed(void)
}
changed_int();
}
- buf_set_changedtick(curbuf, curbuf->b_changedtick + 1);
+ buf_inc_changedtick(curbuf);
}
/*
@@ -1922,9 +1922,9 @@ changed_lines(
linenr_T lnume, // line below last changed line
long xtra, // number of extra lines (negative when deleting)
bool do_buf_event // some callers like undo/redo call changed_lines()
- // and then increment b_changedtick *again*. This flag
+ // and then increment changedtick *again*. This flag
// allows these callers to send the nvim_buf_lines_event
- // events after they're done modifying b_changedtick.
+ // events after they're done modifying changedtick.
)
{
changed_lines_buf(curbuf, lnum, lnume, xtra);
@@ -2168,7 +2168,7 @@ unchanged (
redraw_tabline = TRUE;
need_maketitle = TRUE; /* set window title later */
}
- buf_set_changedtick(buf, buf->b_changedtick + 1);
+ buf_inc_changedtick(buf);
}
/*
diff --git a/src/nvim/normal.c b/src/nvim/normal.c
index a649777ddd..570368991a 100644
--- a/src/nvim/normal.c
+++ b/src/nvim/normal.c
@@ -1213,11 +1213,11 @@ static void normal_check_cursor_moved(NormalState *s)
static void normal_check_text_changed(NormalState *s)
{
- // Trigger TextChanged if b_changedtick differs.
+ // Trigger TextChanged if changedtick differs.
if (!finish_op && has_event(EVENT_TEXTCHANGED)
- && curbuf->b_last_changedtick != curbuf->b_changedtick) {
+ && curbuf->b_last_changedtick != buf_get_changedtick(curbuf)) {
apply_autocmds(EVENT_TEXTCHANGED, NULL, NULL, false, curbuf);
- curbuf->b_last_changedtick = curbuf->b_changedtick;
+ curbuf->b_last_changedtick = buf_get_changedtick(curbuf);
}
}
diff --git a/src/nvim/options.lua b/src/nvim/options.lua
index 30ddb977bb..5ae306e00e 100644
--- a/src/nvim/options.lua
+++ b/src/nvim/options.lua
@@ -2123,7 +2123,7 @@ return {
type='string', list='flags', scope={'global'},
vim=true,
varname='p_shm',
- defaults={if_true={vi="", vim="filnxtToO"}}
+ defaults={if_true={vi="", vim="filnxtToOF"}}
},
{
full_name='showbreak', abbreviation='sbr',
diff --git a/src/nvim/search.c b/src/nvim/search.c
index 6c974850ac..27f4389683 100644
--- a/src/nvim/search.c
+++ b/src/nvim/search.c
@@ -1288,9 +1288,9 @@ end_do_search:
* search_for_exact_line(buf, pos, dir, pat)
*
* Search for a line starting with the given pattern (ignoring leading
- * white-space), starting from pos and going in direction dir. pos will
+ * white-space), starting from pos and going in direction "dir". "pos" will
* contain the position of the match found. Blank lines match only if
- * ADDING is set. if p_ic is set then the pattern must be in lowercase.
+ * ADDING is set. If p_ic is set then the pattern must be in lowercase.
* Return OK for success, or FAIL if no line found.
*/
int search_for_exact_line(buf_T *buf, pos_T *pos, int dir, char_u *pat)
@@ -4595,20 +4595,23 @@ search_line:
RESET_BINDING(curwin);
}
if (depth == -1) {
- /* match in current file */
+ // match in current file
if (l_g_do_tagpreview != 0) {
- if (getfile(0, curwin_save->w_buffer->b_fname,
- NULL, TRUE, lnum, FALSE) > 0)
- break; /* failed to jump to file */
- } else
+ if (!GETFILE_SUCCESS(getfile(0, curwin_save->w_buffer->b_fname,
+ NULL, true, lnum, false))) {
+ break; // failed to jump to file
+ }
+ } else {
setpcmark();
+ }
curwin->w_cursor.lnum = lnum;
} else {
- if (getfile(0, files[depth].name, NULL, TRUE,
- files[depth].lnum, FALSE) > 0)
- break; /* failed to jump to file */
- /* autocommands may have changed the lnum, we don't
- * want that here */
+ if (!GETFILE_SUCCESS(getfile(0, files[depth].name, NULL, true,
+ files[depth].lnum, false))) {
+ break; // failed to jump to file
+ }
+ // autocommands may have changed the lnum, we don't
+ // want that here
curwin->w_cursor.lnum = files[depth].lnum;
}
}
diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c
index 45f40e8592..53bfd161ca 100644
--- a/src/nvim/syntax.c
+++ b/src/nvim/syntax.c
@@ -43,6 +43,7 @@
#include "nvim/os/os.h"
#include "nvim/os/time.h"
#include "nvim/api/private/helpers.h"
+#include "nvim/buffer.h"
static bool did_syntax_onoff = false;
@@ -406,12 +407,12 @@ void syntax_start(win_T *wp, linenr_T lnum)
*/
if (syn_block != wp->w_s
|| syn_buf != wp->w_buffer
- || changedtick != syn_buf->b_changedtick) {
+ || changedtick != buf_get_changedtick(syn_buf)) {
invalidate_current_state();
syn_buf = wp->w_buffer;
syn_block = wp->w_s;
}
- changedtick = syn_buf->b_changedtick;
+ changedtick = buf_get_changedtick(syn_buf);
syn_win = wp;
/*
diff --git a/src/nvim/tag.c b/src/nvim/tag.c
index 473381a13c..beff89d191 100644
--- a/src/nvim/tag.c
+++ b/src/nvim/tag.c
@@ -2320,7 +2320,7 @@ jumpto_tag (
char_u *fname;
tagptrs_T tagp;
int retval = FAIL;
- int getfile_result;
+ int getfile_result = GETFILE_UNUSED;
int search_options;
int save_no_hlsearch;
win_T *curwin_save = NULL;
@@ -2406,7 +2406,31 @@ jumpto_tag (
// If it was a CTRL-W CTRL-] command split window now. For ":tab tag"
// open a new tab page.
- if (postponed_split || cmdmod.tab != 0) {
+ if (postponed_split && (swb_flags & (SWB_USEOPEN | SWB_USETAB))) {
+ buf_T *const existing_buf = buflist_findname_exp(fname);
+
+ if (existing_buf != NULL) {
+ const win_T *wp = NULL;
+
+ if (swb_flags & SWB_USEOPEN) {
+ wp = buf_jump_open_win(existing_buf);
+ }
+
+ // If 'switchbuf' contains "usetab": jump to first window in any tab
+ // page containing "existing_buf" if one exists
+ if (wp == NULL && (swb_flags & SWB_USETAB)) {
+ wp = buf_jump_open_tab(existing_buf);
+ }
+
+ // We've switched to the buffer, the usual loading of the file must
+ // be skipped.
+ if (wp != NULL) {
+ getfile_result = GETFILE_SAME_FILE;
+ }
+ }
+ }
+ if (getfile_result == GETFILE_UNUSED
+ && (postponed_split || cmdmod.tab != 0)) {
if (win_split(postponed_split > 0 ? postponed_split : 0,
postponed_split_flags) == FAIL) {
RedrawingDisabled--;
@@ -2423,11 +2447,13 @@ jumpto_tag (
else
keep_help_flag = curbuf->b_help;
}
- getfile_result = getfile(0, fname, NULL, TRUE, (linenr_T)0, forceit);
- keep_help_flag = FALSE;
+ if (getfile_result == GETFILE_UNUSED) {
+ getfile_result = getfile(0, fname, NULL, true, (linenr_T)0, forceit);
+ }
+ keep_help_flag = false;
- if (getfile_result <= 0) { /* got to the right file */
- curwin->w_set_curswant = TRUE;
+ if (GETFILE_SUCCESS(getfile_result)) { // got to the right file
+ curwin->w_set_curswant = true;
postponed_split = 0;
save_secure = secure;
@@ -2545,9 +2571,10 @@ jumpto_tag (
SET_NO_HLSEARCH(save_no_hlsearch);
}
- /* Return OK if jumped to another file (at least we found the file!). */
- if (getfile_result == -1)
+ // Return OK if jumped to another file (at least we found the file!).
+ if (getfile_result == GETFILE_OPEN_OTHER) {
retval = OK;
+ }
if (retval == OK) {
/*
diff --git a/src/nvim/testdir/test_tagjump.vim b/src/nvim/testdir/test_tagjump.vim
index d5ce193bc6..dbab8d9e26 100644
--- a/src/nvim/testdir/test_tagjump.vim
+++ b/src/nvim/testdir/test_tagjump.vim
@@ -65,6 +65,48 @@ func Test_duplicate_tagjump()
call delete('Xfile1')
endfunc
+func Test_tagjump_switchbuf()
+ set tags=Xtags
+ call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//",
+ \ "second\tXfile1\t2",
+ \ "third\tXfile1\t3",],
+ \ 'Xtags')
+ call writefile(['first', 'second', 'third'], 'Xfile1')
+
+ enew | only
+ set switchbuf=
+ stag second
+ call assert_equal(2, winnr('$'))
+ call assert_equal(2, line('.'))
+ stag third
+ call assert_equal(3, winnr('$'))
+ call assert_equal(3, line('.'))
+
+ enew | only
+ set switchbuf=useopen
+ stag second
+ call assert_equal(2, winnr('$'))
+ call assert_equal(2, line('.'))
+ stag third
+ call assert_equal(2, winnr('$'))
+ call assert_equal(3, line('.'))
+
+ enew | only
+ set switchbuf=usetab
+ tab stag second
+ call assert_equal(2, tabpagenr('$'))
+ call assert_equal(2, line('.'))
+ 1tabnext | stag third
+ call assert_equal(2, tabpagenr('$'))
+ call assert_equal(3, line('.'))
+
+ tabclose!
+ enew | only
+ call delete('Xfile1')
+ call delete('Xtags')
+ set switchbuf&vim
+endfunc
+
" Tests for [ CTRL-I and CTRL-W CTRL-I commands
function Test_keyword_jump()
call writefile(["#include Xinclude", "",
diff --git a/src/nvim/undo.c b/src/nvim/undo.c
index a6a3b2cc5f..2055b4879e 100644
--- a/src/nvim/undo.c
+++ b/src/nvim/undo.c
@@ -2289,7 +2289,7 @@ static void u_undoredo(int undo, bool do_buf_event)
unchanged(curbuf, FALSE);
}
- // because the calls to changed()/unchanged() above will bump b_changedtick
+ // because the calls to changed()/unchanged() above will bump changedtick
// again, we need to send a nvim_buf_lines_event with just the new value of
// b:changedtick
if (do_buf_event && kv_size(curbuf->update_channels)) {
diff --git a/test/functional/ex_cmds/drop_spec.lua b/test/functional/ex_cmds/drop_spec.lua
index 30dbd27d37..d6da0d8e88 100644
--- a/test/functional/ex_cmds/drop_spec.lua
+++ b/test/functional/ex_cmds/drop_spec.lua
@@ -1,4 +1,5 @@
local helpers = require('test.functional.helpers')(after_each)
+local command = helpers.command
local Screen = require('test.functional.ui.screen')
local clear, feed, feed_command = helpers.clear, helpers.feed, helpers.feed_command
@@ -15,7 +16,7 @@ describe(":drop", function()
[2] = {reverse = true},
[3] = {bold = true},
})
- feed_command("set laststatus=2")
+ command("set laststatus=2 shortmess-=F")
end)
after_each(function()
diff --git a/test/functional/legacy/108_backtrace_debug_commands_spec.lua b/test/functional/legacy/108_backtrace_debug_commands_spec.lua
index ff1917e90c..9ace4ef093 100644
--- a/test/functional/legacy/108_backtrace_debug_commands_spec.lua
+++ b/test/functional/legacy/108_backtrace_debug_commands_spec.lua
@@ -1,6 +1,7 @@
-- Tests for backtrace debug commands.
local helpers = require('test.functional.helpers')(after_each)
+local command = helpers.command
local feed, clear = helpers.feed, helpers.clear
local feed_command, expect = helpers.feed_command, helpers.expect
@@ -8,6 +9,7 @@ describe('108', function()
before_each(clear)
it('is working', function()
+ command("set shortmess-=F")
feed_command('lang mess C')
feed_command('function! Foo()')
feed_command(' let var1 = 1')
diff --git a/test/functional/options/shortmess_spec.lua b/test/functional/options/shortmess_spec.lua
index 99a574ec46..96823476de 100644
--- a/test/functional/options/shortmess_spec.lua
+++ b/test/functional/options/shortmess_spec.lua
@@ -1,5 +1,6 @@
local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
+local command = helpers.command
local clear, feed_command = helpers.clear, helpers.feed_command
if helpers.pending_win32(pending) then return end
@@ -19,6 +20,7 @@ describe("'shortmess'", function()
describe('"F" flag', function()
it('hides messages about the files read', function()
+ command("set shortmess-=F")
feed_command('e test')
screen:expect([[
^ |
diff --git a/test/functional/ui/input_spec.lua b/test/functional/ui/input_spec.lua
index 3dd9a2506e..7f9cd190ee 100644
--- a/test/functional/ui/input_spec.lua
+++ b/test/functional/ui/input_spec.lua
@@ -142,7 +142,7 @@ describe('input non-printable chars', function()
[3] = {bold = true, foreground = Screen.colors.SeaGreen4}
})
screen:attach()
- command("set display-=msgsep")
+ command("set display-=msgsep shortmess-=F")
feed_command("e Xtest-overwrite")
screen:expect([[