mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge #8612 from janlazo/vim-8.0.0621
This commit is contained in:
commit
cf659a1926
@ -343,7 +343,7 @@ open_buffer (
|
|||||||
void set_bufref(bufref_T *bufref, buf_T *buf)
|
void set_bufref(bufref_T *bufref, buf_T *buf)
|
||||||
{
|
{
|
||||||
bufref->br_buf = 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;
|
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;
|
RedrawingDisabled++;
|
||||||
if (getfile(buf->b_fnum, NULL, NULL, (options & GETF_SETMARK),
|
if (GETFILE_SUCCESS(getfile(buf->b_fnum, NULL, NULL,
|
||||||
lnum, forceit) <= 0) {
|
(options & GETF_SETMARK), lnum, forceit))) {
|
||||||
--RedrawingDisabled;
|
RedrawingDisabled--;
|
||||||
|
|
||||||
/* cursor is at to BOL and w_cursor.lnum is checked due to getfile() */
|
/* cursor is at to BOL and w_cursor.lnum is checked due to getfile() */
|
||||||
if (!p_sol && col != 0) {
|
if (!p_sol && col != 0) {
|
||||||
@ -1915,7 +1915,7 @@ int buflist_getfile(int n, linenr_T lnum, int options, int forceit)
|
|||||||
}
|
}
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
--RedrawingDisabled;
|
RedrawingDisabled--;
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,15 @@ enum getf_values {
|
|||||||
GETF_SWITCH = 0x04, // respect 'switchbuf' settings when jumping
|
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
|
// Values for buflist_new() flags
|
||||||
enum bln_values {
|
enum bln_values {
|
||||||
BLN_CURBUF = 1, // May re-use curbuf for new buffer
|
BLN_CURBUF = 1, // May re-use curbuf for new buffer
|
||||||
|
@ -41,6 +41,7 @@ typedef struct {
|
|||||||
// for kvec
|
// for kvec
|
||||||
#include "nvim/lib/kvec.h"
|
#include "nvim/lib/kvec.h"
|
||||||
|
|
||||||
|
#define GETFILE_SUCCESS(x) ((x) <= 0)
|
||||||
#define MODIFIABLE(buf) (buf->b_p_ma)
|
#define MODIFIABLE(buf) (buf->b_p_ma)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -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.
|
* 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
|
* Return:
|
||||||
* -1 for successfully opening another file.
|
* GETFILE_ERROR for "normal" error,
|
||||||
* 'lnum' is the line number for the cursor in the new file (if non-zero).
|
* 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)
|
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;
|
int retval;
|
||||||
char_u *free_me = NULL;
|
char_u *free_me = NULL;
|
||||||
|
|
||||||
if (text_locked())
|
if (text_locked()) {
|
||||||
return 1;
|
return GETFILE_ERROR;
|
||||||
if (curbuf_locked())
|
}
|
||||||
return 1;
|
if (curbuf_locked()) {
|
||||||
|
return GETFILE_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
if (fnum == 0) {
|
if (fnum == 0) {
|
||||||
/* make ffname full path, set sfname */
|
/* 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()) {
|
if (curbufIsChanged()) {
|
||||||
no_wait_return--;
|
no_wait_return--;
|
||||||
EMSG(_(e_nowrtmsg));
|
EMSG(_(e_nowrtmsg));
|
||||||
retval = 2; // File has been changed.
|
retval = GETFILE_NOT_WRITTEN; // File has been changed.
|
||||||
goto theend;
|
goto theend;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2056,13 +2061,13 @@ int getfile(int fnum, char_u *ffname, char_u *sfname, int setpm, linenr_T lnum,
|
|||||||
}
|
}
|
||||||
check_cursor_lnum();
|
check_cursor_lnum();
|
||||||
beginline(BL_SOL | BL_FIX);
|
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,
|
} else if (do_ecmd(fnum, ffname, sfname, NULL, lnum,
|
||||||
(buf_hide(curbuf) ? ECMD_HIDE : 0)
|
(buf_hide(curbuf) ? ECMD_HIDE : 0)
|
||||||
+ (forceit ? ECMD_FORCEIT : 0), curwin) == OK) {
|
+ (forceit ? ECMD_FORCEIT : 0), curwin) == OK) {
|
||||||
retval = -1; // opened another file
|
retval = GETFILE_OPEN_OTHER; // opened another file
|
||||||
} else {
|
} else {
|
||||||
retval = 1; // error encountered
|
retval = GETFILE_ERROR; // error encountered
|
||||||
}
|
}
|
||||||
|
|
||||||
theend:
|
theend:
|
||||||
|
@ -1288,9 +1288,9 @@ end_do_search:
|
|||||||
* search_for_exact_line(buf, pos, dir, pat)
|
* search_for_exact_line(buf, pos, dir, pat)
|
||||||
*
|
*
|
||||||
* Search for a line starting with the given pattern (ignoring leading
|
* 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
|
* 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.
|
* 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)
|
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);
|
RESET_BINDING(curwin);
|
||||||
}
|
}
|
||||||
if (depth == -1) {
|
if (depth == -1) {
|
||||||
/* match in current file */
|
// match in current file
|
||||||
if (l_g_do_tagpreview != 0) {
|
if (l_g_do_tagpreview != 0) {
|
||||||
if (getfile(0, curwin_save->w_buffer->b_fname,
|
if (!GETFILE_SUCCESS(getfile(0, curwin_save->w_buffer->b_fname,
|
||||||
NULL, TRUE, lnum, FALSE) > 0)
|
NULL, true, lnum, false))) {
|
||||||
break; /* failed to jump to file */
|
break; // failed to jump to file
|
||||||
} else
|
}
|
||||||
|
} else {
|
||||||
setpcmark();
|
setpcmark();
|
||||||
|
}
|
||||||
curwin->w_cursor.lnum = lnum;
|
curwin->w_cursor.lnum = lnum;
|
||||||
} else {
|
} else {
|
||||||
if (getfile(0, files[depth].name, NULL, TRUE,
|
if (!GETFILE_SUCCESS(getfile(0, files[depth].name, NULL, true,
|
||||||
files[depth].lnum, FALSE) > 0)
|
files[depth].lnum, false))) {
|
||||||
break; /* failed to jump to file */
|
break; // failed to jump to file
|
||||||
/* autocommands may have changed the lnum, we don't
|
}
|
||||||
* want that here */
|
// autocommands may have changed the lnum, we don't
|
||||||
|
// want that here
|
||||||
curwin->w_cursor.lnum = files[depth].lnum;
|
curwin->w_cursor.lnum = files[depth].lnum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2320,7 +2320,7 @@ jumpto_tag (
|
|||||||
char_u *fname;
|
char_u *fname;
|
||||||
tagptrs_T tagp;
|
tagptrs_T tagp;
|
||||||
int retval = FAIL;
|
int retval = FAIL;
|
||||||
int getfile_result;
|
int getfile_result = GETFILE_UNUSED;
|
||||||
int search_options;
|
int search_options;
|
||||||
int save_no_hlsearch;
|
int save_no_hlsearch;
|
||||||
win_T *curwin_save = NULL;
|
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"
|
// If it was a CTRL-W CTRL-] command split window now. For ":tab tag"
|
||||||
// open a new tab page.
|
// 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,
|
if (win_split(postponed_split > 0 ? postponed_split : 0,
|
||||||
postponed_split_flags) == FAIL) {
|
postponed_split_flags) == FAIL) {
|
||||||
RedrawingDisabled--;
|
RedrawingDisabled--;
|
||||||
@ -2423,11 +2447,13 @@ jumpto_tag (
|
|||||||
else
|
else
|
||||||
keep_help_flag = curbuf->b_help;
|
keep_help_flag = curbuf->b_help;
|
||||||
}
|
}
|
||||||
getfile_result = getfile(0, fname, NULL, TRUE, (linenr_T)0, forceit);
|
if (getfile_result == GETFILE_UNUSED) {
|
||||||
keep_help_flag = FALSE;
|
getfile_result = getfile(0, fname, NULL, true, (linenr_T)0, forceit);
|
||||||
|
}
|
||||||
|
keep_help_flag = false;
|
||||||
|
|
||||||
if (getfile_result <= 0) { /* got to the right file */
|
if (GETFILE_SUCCESS(getfile_result)) { // got to the right file
|
||||||
curwin->w_set_curswant = TRUE;
|
curwin->w_set_curswant = true;
|
||||||
postponed_split = 0;
|
postponed_split = 0;
|
||||||
|
|
||||||
save_secure = secure;
|
save_secure = secure;
|
||||||
@ -2545,9 +2571,10 @@ jumpto_tag (
|
|||||||
SET_NO_HLSEARCH(save_no_hlsearch);
|
SET_NO_HLSEARCH(save_no_hlsearch);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return OK if jumped to another file (at least we found the file!). */
|
// Return OK if jumped to another file (at least we found the file!).
|
||||||
if (getfile_result == -1)
|
if (getfile_result == GETFILE_OPEN_OTHER) {
|
||||||
retval = OK;
|
retval = OK;
|
||||||
|
}
|
||||||
|
|
||||||
if (retval == OK) {
|
if (retval == OK) {
|
||||||
/*
|
/*
|
||||||
|
@ -65,6 +65,48 @@ func Test_duplicate_tagjump()
|
|||||||
call delete('Xfile1')
|
call delete('Xfile1')
|
||||||
endfunc
|
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
|
" Tests for [ CTRL-I and CTRL-W CTRL-I commands
|
||||||
function Test_keyword_jump()
|
function Test_keyword_jump()
|
||||||
call writefile(["#include Xinclude", "",
|
call writefile(["#include Xinclude", "",
|
||||||
|
Loading…
Reference in New Issue
Block a user