aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2018-06-21 22:54:08 +0200
committerGitHub <noreply@github.com>2018-06-21 22:54:08 +0200
commitcf659a19260aea27816575d67a12139ebaada56f (patch)
tree699f705b09fc56af06ac155fb95e10675fefa526 /src
parent7ae7da8fb9ab2e23ffc19000798ae27a2dee4e87 (diff)
parent10083ec4cc6d8f03831445831a20c82fee87880b (diff)
downloadrneovim-cf659a19260aea27816575d67a12139ebaada56f.tar.gz
rneovim-cf659a19260aea27816575d67a12139ebaada56f.tar.bz2
rneovim-cf659a19260aea27816575d67a12139ebaada56f.zip
Merge #8612 from janlazo/vim-8.0.0621
Diffstat (limited to 'src')
-rw-r--r--src/nvim/buffer.c12
-rw-r--r--src/nvim/buffer.h9
-rw-r--r--src/nvim/buffer_defs.h1
-rw-r--r--src/nvim/ex_cmds.c29
-rw-r--r--src/nvim/search.c27
-rw-r--r--src/nvim/tag.c43
-rw-r--r--src/nvim/testdir/test_tagjump.vim42
7 files changed, 125 insertions, 38 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index eb781b1be0..ea2ae016b9 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;
}
@@ -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..d12862a0c6 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
diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h
index 50d8c822c1..4fce4ecd22 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)
/*
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index d58d006dd0..d8aac73b57 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:
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/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", "",