Merge #11087 from janlazo/vim-8.1.0010

vim-patch:8.1.{10,230,315,330,514,517,518,1327,1347,1758,2072,2074,2091,2095,2103}
This commit is contained in:
Justin M. Keyes 2019-10-02 22:43:59 -07:00 committed by GitHub
commit 30479417e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 613 additions and 289 deletions

View File

@ -201,9 +201,11 @@ CTRL-W CTRL_N *CTRL-W_CTRL-N*
|:find|. Doesn't split if {file} is not found. |:find|. Doesn't split if {file} is not found.
CTRL-W CTRL-^ *CTRL-W_CTRL-^* *CTRL-W_^* CTRL-W CTRL-^ *CTRL-W_CTRL-^* *CTRL-W_^*
CTRL-W ^ Does ":split #", split window in two and edit alternate file. CTRL-W ^ Split the current window in two and edit the alternate file.
When a count is given, it becomes ":split #N", split window When a count N is given, split the current window and edit
and edit buffer N. buffer N. Similar to ":sp #" and ":sp #N", but it allows the
other buffer to be unnamed. This command matches the behavior
of |CTRL-^|, except that it splits a window first.
CTRL-W ge *CTRL-W_ge* CTRL-W ge *CTRL-W_ge*
Detach the current window as an external window. Detach the current window as an external window.

View File

@ -67,8 +67,8 @@ command -nargs=* -complete=file -bang Termdebug call s:StartDebug(<bang>0, <f-ar
command -nargs=+ -complete=file -bang TermdebugCommand call s:StartDebugCommand(<bang>0, <f-args>) command -nargs=+ -complete=file -bang TermdebugCommand call s:StartDebugCommand(<bang>0, <f-args>)
" Name of the gdb command, defaults to "gdb". " Name of the gdb command, defaults to "gdb".
if !exists('termdebugger') if !exists('g:termdebugger')
let termdebugger = 'gdb' let g:termdebugger = 'gdb'
endif endif
let s:pc_id = 12 let s:pc_id = 12
@ -106,9 +106,14 @@ endfunc
func s:StartDebug_internal(dict) func s:StartDebug_internal(dict)
if exists('s:gdbwin') if exists('s:gdbwin')
echoerr 'Terminal debugger already running' echoerr 'Terminal debugger already running, cannot run two'
return return
endif endif
if !executable(g:termdebugger)
echoerr 'Cannot execute debugger program "' .. g:termdebugger .. '"'
return
endif
let s:ptywin = 0 let s:ptywin = 0
let s:pid = 0 let s:pid = 0

View File

@ -5179,6 +5179,13 @@ bool bt_help(const buf_T *const buf)
return buf != NULL && buf->b_help; return buf != NULL && buf->b_help;
} }
// Return true if "buf" is a normal buffer, 'buftype' is empty.
bool bt_normal(const buf_T *const buf)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{
return buf != NULL && buf->b_p_bt[0] == NUL;
}
// Return true if "buf" is the quickfix buffer. // Return true if "buf" is the quickfix buffer.
bool bt_quickfix(const buf_T *const buf) bool bt_quickfix(const buf_T *const buf)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT

View File

@ -5746,13 +5746,13 @@ static int dict_get_tv(char_u **arg, typval_T *rettv, int evaluate)
goto failret; goto failret;
} }
item = tv_dict_item_alloc((const char *)key); item = tv_dict_item_alloc((const char *)key);
tv_clear(&tvkey);
item->di_tv = tv; item->di_tv = tv;
item->di_tv.v_lock = 0; item->di_tv.v_lock = 0;
if (tv_dict_add(d, item) == FAIL) { if (tv_dict_add(d, item) == FAIL) {
tv_dict_item_free(item); tv_dict_item_free(item);
} }
} }
tv_clear(&tvkey);
if (**arg == '}') if (**arg == '}')
break; break;

View File

@ -9553,7 +9553,7 @@ put_view(
*/ */
if ((*flagp & SSOP_FOLDS) if ((*flagp & SSOP_FOLDS)
&& wp->w_buffer->b_ffname != NULL && wp->w_buffer->b_ffname != NULL
&& (*wp->w_buffer->b_p_bt == NUL || bt_help(wp->w_buffer)) && (bt_normal(wp->w_buffer) || bt_help(wp->w_buffer))
) { ) {
if (put_folds(fd, wp) == FAIL) if (put_folds(fd, wp) == FAIL)
return FAIL; return FAIL;

View File

@ -4834,7 +4834,7 @@ buf_check_timestamp(
if (buf->terminal if (buf->terminal
|| buf->b_ffname == NULL || buf->b_ffname == NULL
|| buf->b_ml.ml_mfp == NULL || buf->b_ml.ml_mfp == NULL
|| *buf->b_p_bt != NUL || !bt_normal(buf)
|| buf->b_saving || buf->b_saving
|| busy || busy
) )

View File

@ -1165,12 +1165,12 @@ void free_typebuf(void)
if (typebuf.tb_buf == typebuf_init) { if (typebuf.tb_buf == typebuf_init) {
internal_error("Free typebuf 1"); internal_error("Free typebuf 1");
} else { } else {
xfree(typebuf.tb_buf); XFREE_CLEAR(typebuf.tb_buf);
} }
if (typebuf.tb_noremap == noremapbuf_init) { if (typebuf.tb_noremap == noremapbuf_init) {
internal_error("Free typebuf 2"); internal_error("Free typebuf 2");
} else { } else {
xfree(typebuf.tb_noremap); XFREE_CLEAR(typebuf.tb_noremap);
} }
} }

View File

@ -3932,11 +3932,11 @@ static bool nv_screengo(oparg_T *oap, int dir, long dist)
while (dist--) { while (dist--) {
if (dir == BACKWARD) { if (dir == BACKWARD) {
if ((long)curwin->w_curswant >= width2) if (curwin->w_curswant > width2) {
/* move back within line */ // move back within line
curwin->w_curswant -= width2; curwin->w_curswant -= width2;
else { } else {
/* to previous line */ // to previous line
if (curwin->w_cursor.lnum == 1) { if (curwin->w_cursor.lnum == 1) {
retval = false; retval = false;
break; break;
@ -4680,9 +4680,8 @@ static void nv_ctrlo(cmdarg_T *cap)
} }
} }
/* // CTRL-^ command, short for ":e #". Works even when the alternate buffer is
* CTRL-^ command, short for ":e #" // not named.
*/
static void nv_hat(cmdarg_T *cap) static void nv_hat(cmdarg_T *cap)
{ {
if (!checkclearopq(cap->oap)) if (!checkclearopq(cap->oap))
@ -6795,10 +6794,14 @@ static void nv_g_cmd(cmdarg_T *cap)
} else if (nv_screengo(oap, FORWARD, cap->count1 - 1) == false) } else if (nv_screengo(oap, FORWARD, cap->count1 - 1) == false)
clearopbeep(oap); clearopbeep(oap);
} else { } else {
if (cap->count1 > 1) {
// if it fails, let the cursor still move to the last char
cursor_down(cap->count1 - 1, false);
}
i = curwin->w_leftcol + curwin->w_width_inner - col_off - 1; i = curwin->w_leftcol + curwin->w_width_inner - col_off - 1;
coladvance((colnr_T)i); coladvance((colnr_T)i);
/* Make sure we stick in this column. */ // Make sure we stick in this column.
validate_virtcol(); validate_virtcol();
curwin->w_curswant = curwin->w_virtcol; curwin->w_curswant = curwin->w_virtcol;
curwin->w_set_curswant = false; curwin->w_set_curswant = false;

View File

@ -264,42 +264,35 @@ static struct fmtpattern
{ 'o', ".\\+" } { 'o', ".\\+" }
}; };
// Converts a 'errorformat' string to regular expression pattern // Convert an errorformat pattern to a regular expression pattern.
static int efm_to_regpat(char_u *efm, int len, efm_T *fmt_ptr, // See fmt_pat definition above for the list of supported patterns.
char_u *regpat, char_u *errmsg) static char_u *fmtpat_to_regpat(
const char_u *efmp,
efm_T *fmt_ptr,
int idx,
int round,
char_u *ptr,
char_u *errmsg,
size_t errmsglen)
FUNC_ATTR_NONNULL_ALL
{ {
// Build regexp pattern from current 'errorformat' option
char_u *ptr = regpat;
*ptr++ = '^';
int round = 0;
for (char_u *efmp = efm; efmp < efm + len; efmp++) {
if (*efmp == '%') {
efmp++;
int idx;
for (idx = 0; idx < FMT_PATTERNS; idx++) {
if (fmt_pat[idx].convchar == *efmp) {
break;
}
}
if (idx < FMT_PATTERNS) {
if (fmt_ptr->addr[idx]) { if (fmt_ptr->addr[idx]) {
snprintf((char *)errmsg, CMDBUFFSIZE + 1, // Each errorformat pattern can occur only once
snprintf((char *)errmsg, errmsglen,
_("E372: Too many %%%c in format string"), *efmp); _("E372: Too many %%%c in format string"), *efmp);
EMSG(errmsg); EMSG(errmsg);
return -1; return NULL;
} }
if ((idx if ((idx && idx < 6
&& idx < 6
&& vim_strchr((char_u *)"DXOPQ", fmt_ptr->prefix) != NULL) && vim_strchr((char_u *)"DXOPQ", fmt_ptr->prefix) != NULL)
|| (idx == 6 || (idx == 6
&& vim_strchr((char_u *)"OPQ", fmt_ptr->prefix) == NULL)) { && vim_strchr((char_u *)"OPQ", fmt_ptr->prefix) == NULL)) {
snprintf((char *)errmsg, CMDBUFFSIZE + 1, snprintf((char *)errmsg, errmsglen,
_("E373: Unexpected %%%c in format string"), *efmp); _("E373: Unexpected %%%c in format string"), *efmp);
EMSG(errmsg); EMSG(errmsg);
return -1; return NULL;
} }
round++; fmt_ptr->addr[idx] = (char_u)++round;
fmt_ptr->addr[idx] = (char_u)round;
*ptr++ = '\\'; *ptr++ = '\\';
*ptr++ = '('; *ptr++ = '(';
#ifdef BACKSLASH_IN_FILENAME #ifdef BACKSLASH_IN_FILENAME
@ -334,37 +327,107 @@ static int efm_to_regpat(char_u *efm, int len, efm_T *fmt_ptr,
} }
*ptr++ = '\\'; *ptr++ = '\\';
*ptr++ = ')'; *ptr++ = ')';
} else if (*efmp == '*') {
return ptr;
}
// Convert a scanf like format in 'errorformat' to a regular expression.
static char_u *scanf_fmt_to_regpat(
const char_u *efm,
int len,
const char_u **pefmp,
char_u *ptr,
char_u *errmsg,
size_t errmsglen)
FUNC_ATTR_NONNULL_ALL
{
const char_u *efmp = *pefmp;
if (*++efmp == '[' || *efmp == '\\') { if (*++efmp == '[' || *efmp == '\\') {
if ((*ptr++ = *efmp) == '[') { // %*[^a-z0-9] etc. if ((*ptr++ = *efmp) == '[') { // %*[^a-z0-9] etc.
if (efmp[1] == '^') { if (efmp[1] == '^') {
*ptr++ = *++efmp; *ptr++ = *++efmp;
} }
if (efmp < efm + len) { if (efmp < efm + len) {
efmp++; *ptr++ = *++efmp; // could be ']'
*ptr++ = *efmp; // could be ']' while (efmp < efm + len && (*ptr++ = *++efmp) != ']') {
while (efmp < efm + len) {
efmp++;
if ((*ptr++ = *efmp) == ']') {
break;
}
} }
if (efmp == efm + len) { if (efmp == efm + len) {
EMSG(_("E374: Missing ] in format string")); EMSG(_("E374: Missing ] in format string"));
return -1; return NULL;
} }
} }
} else if (efmp < efm + len) { // %*\D, %*\s etc. } else if (efmp < efm + len) { // %*\D, %*\s etc.
efmp++; *ptr++ = *++efmp;
*ptr++ = *efmp;
} }
*ptr++ = '\\'; *ptr++ = '\\';
*ptr++ = '+'; *ptr++ = '+';
} else { } else {
// TODO(vim): scanf()-like: %*ud, %*3c, %*f, ... ? // TODO(vim): scanf()-like: %*ud, %*3c, %*f, ... ?
snprintf((char *)errmsg, CMDBUFFSIZE + 1, snprintf((char *)errmsg, errmsglen,
_("E375: Unsupported %%%c in format string"), *efmp); _("E375: Unsupported %%%c in format string"), *efmp);
EMSG(errmsg); EMSG(errmsg);
return NULL;
}
*pefmp = efmp;
return ptr;
}
// Analyze/parse an errorformat prefix.
static int efm_analyze_prefix(const char_u **pefmp, efm_T *fmt_ptr,
char_u *errmsg, size_t errmsglen)
FUNC_ATTR_NONNULL_ALL
{
const char_u *efmp = *pefmp;
if (vim_strchr((char_u *)"+-", *efmp) != NULL) {
fmt_ptr->flags = *efmp++;
}
if (vim_strchr((char_u *)"DXAEWICZGOPQ", *efmp) != NULL) {
fmt_ptr->prefix = *efmp;
} else {
snprintf((char *)errmsg, errmsglen,
_("E376: Invalid %%%c in format string prefix"), *efmp);
EMSG(errmsg);
return FAIL;
}
*pefmp = efmp;
return OK;
}
// Converts a 'errorformat' string to regular expression pattern
static int efm_to_regpat(const char_u *efm, int len, efm_T *fmt_ptr,
char_u *regpat, char_u *errmsg, size_t errmsglen)
FUNC_ATTR_NONNULL_ALL
{
// Build regexp pattern from current 'errorformat' option
char_u *ptr = regpat;
*ptr++ = '^';
int round = 0;
for (const char_u *efmp = efm; efmp < efm + len; efmp++) {
if (*efmp == '%') {
efmp++;
int idx;
for (idx = 0; idx < FMT_PATTERNS; idx++) {
if (fmt_pat[idx].convchar == *efmp) {
break;
}
}
if (idx < FMT_PATTERNS) {
ptr = fmtpat_to_regpat(efmp, fmt_ptr, idx, round, ptr,
errmsg, errmsglen);
if (ptr == NULL) {
return -1;
}
round++;
} else if (*efmp == '*') {
ptr = scanf_fmt_to_regpat(efm, len, &efmp, ptr, errmsg, errmsglen);
if (ptr == NULL) {
return -1; return -1;
} }
} else if (vim_strchr((char_u *)"%\\.^$~[", *efmp) != NULL) { } else if (vim_strchr((char_u *)"%\\.^$~[", *efmp) != NULL) {
@ -374,15 +437,7 @@ static int efm_to_regpat(char_u *efm, int len, efm_T *fmt_ptr,
} else if (*efmp == '>') { } else if (*efmp == '>') {
fmt_ptr->conthere = true; fmt_ptr->conthere = true;
} else if (efmp == efm + 1) { // analyse prefix } else if (efmp == efm + 1) { // analyse prefix
if (vim_strchr((char_u *)"+-", *efmp) != NULL) { if (efm_analyze_prefix(&efmp, fmt_ptr, errmsg, errmsglen) == FAIL) {
fmt_ptr->flags = *efmp++;
}
if (vim_strchr((char_u *)"DXAEWICZGOPQ", *efmp) != NULL) {
fmt_ptr->prefix = *efmp;
} else {
snprintf((char *)errmsg, CMDBUFFSIZE + 1,
_("E376: Invalid %%%c in format string prefix"), *efmp);
EMSG(errmsg);
return -1; return -1;
} }
} else { } else {
@ -461,7 +516,7 @@ static efm_T * parse_efm_option(char_u *efm)
} }
} }
if (efm_to_regpat(efm, len, fmt_ptr, fmtstr, errmsg) == -1) { if (efm_to_regpat(efm, len, fmt_ptr, fmtstr, errmsg, errmsglen) == -1) {
goto parse_efm_error; goto parse_efm_error;
} }
if ((fmt_ptr->prog = vim_regcomp(fmtstr, RE_MAGIC + RE_STRING)) == NULL) { if ((fmt_ptr->prog = vim_regcomp(fmtstr, RE_MAGIC + RE_STRING)) == NULL) {
@ -1499,6 +1554,7 @@ static int qf_add_entry(qf_info_T *qi, int qf_idx, char_u *dir, char_u *fname,
* Allocate a new location list * Allocate a new location list
*/ */
static qf_info_T *ll_new_list(void) static qf_info_T *ll_new_list(void)
FUNC_ATTR_NONNULL_RET
{ {
qf_info_T *qi = xcalloc(1, sizeof(qf_info_T)); qf_info_T *qi = xcalloc(1, sizeof(qf_info_T));
qi->qf_refcount++; qi->qf_refcount++;
@ -2084,7 +2140,7 @@ static win_T *qf_find_win_with_normal_buf(void)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{ {
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
if (wp->w_buffer->b_p_bt[0] == NUL) { if (bt_normal(wp->w_buffer)) {
return wp; return wp;
} }
} }
@ -2148,7 +2204,7 @@ static void qf_goto_win_with_ll_file(win_T *use_win, int qf_fnum,
// Find a previous usable window // Find a previous usable window
win = curwin; win = curwin;
do { do {
if (win->w_buffer->b_p_bt[0] == NUL) { if (bt_normal(win->w_buffer)) {
break; break;
} }
if (win->w_prev == NULL) { if (win->w_prev == NULL) {
@ -2202,7 +2258,7 @@ static void qf_goto_win_with_qfl_file(int qf_fnum)
// Remember a usable window. // Remember a usable window.
if (altwin == NULL if (altwin == NULL
&& !win->w_p_pvw && !win->w_p_pvw
&& win->w_buffer->b_p_bt[0] == NUL) { && bt_normal(win->w_buffer)) {
altwin = win; altwin = win;
} }
} }
@ -4412,7 +4468,7 @@ void ex_vimgrep(exarg_T *eap)
goto theend; goto theend;
} }
/* Jump to first match. */ // Jump to first match.
if (qi->qf_lists[qi->qf_curlist].qf_count > 0) { if (qi->qf_lists[qi->qf_curlist].qf_count > 0) {
if ((flags & VGR_NOJUMP) == 0) { if ((flags & VGR_NOJUMP) == 0) {
vgr_jump_to_match(qi, eap->forceit, &redraw_for_dummy, first_match_buf, vgr_jump_to_match(qi, eap->forceit, &redraw_for_dummy, first_match_buf,
@ -4974,15 +5030,86 @@ int qf_get_properties(win_T *wp, dict_T *what, dict_T *retdict)
return status; return status;
} }
// Add a new quickfix entry to list at 'qf_idx' in the stack 'qi' from the
// items in the dict 'd'.
static int qf_add_entry_from_dict(
qf_info_T *qi,
int qf_idx,
const dict_T *d,
bool first_entry)
FUNC_ATTR_NONNULL_ALL
{
static bool did_bufnr_emsg;
if (first_entry) {
did_bufnr_emsg = false;
}
char *const filename = tv_dict_get_string(d, "filename", true);
char *const module = tv_dict_get_string(d, "module", true);
int bufnum = (int)tv_dict_get_number(d, "bufnr");
const long lnum = (long)tv_dict_get_number(d, "lnum");
const int col = (int)tv_dict_get_number(d, "col");
const char_u vcol = (char_u)tv_dict_get_number(d, "vcol");
const int nr = (int)tv_dict_get_number(d, "nr");
const char *const type = tv_dict_get_string(d, "type", false);
char *const pattern = tv_dict_get_string(d, "pattern", true);
char *text = tv_dict_get_string(d, "text", true);
if (text == NULL) {
text = xcalloc(1, 1);
}
bool valid = true;
if ((filename == NULL && bufnum == 0)
|| (lnum == 0 && pattern == NULL)) {
valid = false;
}
// Mark entries with non-existing buffer number as not valid. Give the
// error message only once.
if (bufnum != 0 && (buflist_findnr(bufnum) == NULL)) {
if (!did_bufnr_emsg) {
did_bufnr_emsg = true;
EMSGN(_("E92: Buffer %" PRId64 " not found"), bufnum);
}
valid = false;
bufnum = 0;
}
// If the 'valid' field is present it overrules the detected value.
if (tv_dict_find(d, "valid", -1) != NULL) {
valid = tv_dict_get_number(d, "valid");
}
const int status = qf_add_entry(qi,
qf_idx,
NULL, // dir
(char_u *)filename,
(char_u *)module,
bufnum,
(char_u *)text,
lnum,
col,
vcol, // vis_col
(char_u *)pattern, // search pattern
nr,
(char_u)(type == NULL ? NUL : *type),
valid);
xfree(filename);
xfree(module);
xfree(pattern);
xfree(text);
return status;
}
/// Add list of entries to quickfix/location list. Each list entry is /// Add list of entries to quickfix/location list. Each list entry is
/// a dictionary with item information. /// a dictionary with item information.
static int qf_add_entries(qf_info_T *qi, int qf_idx, list_T *list, static int qf_add_entries(qf_info_T *qi, int qf_idx, list_T *list,
char_u *title, int action) char_u *title, int action)
{ {
dict_T *d;
qfline_T *old_last = NULL; qfline_T *old_last = NULL;
int retval = OK; int retval = OK;
bool did_bufnr_emsg = false;
if (action == ' ' || qf_idx == qi->qf_listcount) { if (action == ' ' || qf_idx == qi->qf_listcount) {
// make place for a new list // make place for a new list
@ -5001,68 +5128,13 @@ static int qf_add_entries(qf_info_T *qi, int qf_idx, list_T *list,
continue; // Skip non-dict items. continue; // Skip non-dict items.
} }
d = TV_LIST_ITEM_TV(li)->vval.v_dict; const dict_T *const d = TV_LIST_ITEM_TV(li)->vval.v_dict;
if (d == NULL) { if (d == NULL) {
continue; continue;
} }
char *const filename = tv_dict_get_string(d, "filename", true); retval = qf_add_entry_from_dict(qi, qf_idx, d, li == tv_list_first(list));
char *const module = tv_dict_get_string(d, "module", true); if (retval == FAIL) {
int bufnum = (int)tv_dict_get_number(d, "bufnr");
long lnum = (long)tv_dict_get_number(d, "lnum");
int col = (int)tv_dict_get_number(d, "col");
char_u vcol = (char_u)tv_dict_get_number(d, "vcol");
int nr = (int)tv_dict_get_number(d, "nr");
const char *type_str = tv_dict_get_string(d, "type", false);
const char_u type = (char_u)(uint8_t)(type_str == NULL ? NUL : *type_str);
char *const pattern = tv_dict_get_string(d, "pattern", true);
char *text = tv_dict_get_string(d, "text", true);
if (text == NULL) {
text = xcalloc(1, 1);
}
bool valid = true;
if ((filename == NULL && bufnum == 0) || (lnum == 0 && pattern == NULL)) {
valid = false;
}
/* Mark entries with non-existing buffer number as not valid. Give the
* error message only once. */
if (bufnum != 0 && (buflist_findnr(bufnum) == NULL)) {
if (!did_bufnr_emsg) {
did_bufnr_emsg = TRUE;
EMSGN(_("E92: Buffer %" PRId64 " not found"), bufnum);
}
valid = false;
bufnum = 0;
}
// If the 'valid' field is present it overrules the detected value.
if (tv_dict_find(d, "valid", -1) != NULL) {
valid = (int)tv_dict_get_number(d, "valid");
}
int status = qf_add_entry(qi,
qf_idx,
NULL, // dir
(char_u *)filename,
(char_u *)module,
bufnum,
(char_u *)text,
lnum,
col,
vcol, // vis_col
(char_u *)pattern, // search pattern
nr,
type,
valid);
xfree(filename);
xfree(module);
xfree(pattern);
xfree(text);
if (status == FAIL) {
retval = FAIL;
break; break;
} }
}); });
@ -5595,7 +5667,7 @@ void ex_cexpr(exarg_T *eap)
// Get the location list for ":lhelpgrep" // Get the location list for ":lhelpgrep"
static qf_info_T *hgr_get_ll(bool *new_ll) static qf_info_T *hgr_get_ll(bool *new_ll)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_RET
{ {
win_T *wp; win_T *wp;
qf_info_T *qi; qf_info_T *qi;
@ -5615,9 +5687,7 @@ static qf_info_T *hgr_get_ll(bool *new_ll)
} }
if (qi == NULL) { if (qi == NULL) {
// Allocate a new location list for help text matches // Allocate a new location list for help text matches
if ((qi = ll_new_list()) == NULL) { qi = ll_new_list();
return NULL;
}
*new_ll = true; *new_ll = true;
} }
@ -5713,14 +5783,14 @@ static void hgr_search_files_in_dir(
} }
} }
// Search for a pattern in all the help files in the 'runtimepath'. // Search for a pattern in all the help files in the 'runtimepath'
// and add the matches to a quickfix list.
// 'lang' is the language specifier. If supplied, then only matches in the
// specified language are found.
static void hgr_search_in_rtp(qf_info_T *qi, regmatch_T *p_regmatch, static void hgr_search_in_rtp(qf_info_T *qi, regmatch_T *p_regmatch,
char_u *arg) const char_u *lang)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ARG(1, 2)
{ {
// Check for a specified language
char_u *const lang = check_help_lang(arg);
// Go through all directories in 'runtimepath' // Go through all directories in 'runtimepath'
char_u *p = p_rtp; char_u *p = p_rtp;
while (*p != NUL && !got_int) { while (*p != NUL && !got_int) {
@ -5755,11 +5825,10 @@ void ex_helpgrep(exarg_T *eap)
if (eap->cmdidx == CMD_lhelpgrep) { if (eap->cmdidx == CMD_lhelpgrep) {
qi = hgr_get_ll(&new_qi); qi = hgr_get_ll(&new_qi);
if (qi == NULL) {
return;
}
} }
// Check for a specified language
char_u *const lang = check_help_lang(eap->arg);
regmatch_T regmatch = { regmatch_T regmatch = {
.regprog = vim_regcomp(eap->arg, RE_MAGIC + RE_STRING), .regprog = vim_regcomp(eap->arg, RE_MAGIC + RE_STRING),
.rm_ic = false, .rm_ic = false,
@ -5768,7 +5837,7 @@ void ex_helpgrep(exarg_T *eap)
// Create a new quickfix list. // Create a new quickfix list.
qf_new_list(qi, qf_cmdtitle(*eap->cmdlinep)); qf_new_list(qi, qf_cmdtitle(*eap->cmdlinep));
hgr_search_in_rtp(qi, &regmatch, eap->arg); hgr_search_in_rtp(qi, &regmatch, lang);
vim_regfree(regmatch.regprog); vim_regfree(regmatch.regprog);
@ -5778,11 +5847,12 @@ void ex_helpgrep(exarg_T *eap)
qi->qf_lists[qi->qf_curlist].qf_index = 1; qi->qf_lists[qi->qf_curlist].qf_index = 1;
} }
if (p_cpo == empty_option) if (p_cpo == empty_option) {
p_cpo = save_cpo; p_cpo = save_cpo;
else } else {
/* Darn, some plugin changed the value. */ // Darn, some plugin changed the value.
free_string_option(save_cpo); free_string_option(save_cpo);
}
qf_list_changed(qi, qi->qf_curlist); qf_list_changed(qi, qi->qf_curlist);
qf_update_buffer(qi, NULL); qf_update_buffer(qi, NULL);
@ -5803,8 +5873,8 @@ void ex_helpgrep(exarg_T *eap)
EMSG2(_(e_nomatch2), eap->arg); EMSG2(_(e_nomatch2), eap->arg);
if (eap->cmdidx == CMD_lhelpgrep) { if (eap->cmdidx == CMD_lhelpgrep) {
/* If the help window is not opened or if it already points to the // If the help window is not opened or if it already points to the
* correct location list, then free the new location list. */ // correct location list, then free the new location list.
if (!bt_help(curwin->w_buffer) || curwin->w_llist == qi) { if (!bt_help(curwin->w_buffer) || curwin->w_llist == qi) {
if (new_qi) { if (new_qi) {
ll_free_all(&qi); ll_free_all(&qi);

View File

@ -282,6 +282,7 @@ endif
" Names of flaky tests. " Names of flaky tests.
let s:flaky_tests = [ let s:flaky_tests = [
\ 'Test_autocmd_SafeState()',
\ 'Test_cursorhold_insert()', \ 'Test_cursorhold_insert()',
\ 'Test_exit_callback_interval()', \ 'Test_exit_callback_interval()',
\ 'Test_map_timeout_with_timer_interrupt()', \ 'Test_map_timeout_with_timer_interrupt()',

View File

@ -2,12 +2,12 @@
source shared.vim source shared.vim
func! Setup_NewWindow() func Setup_NewWindow()
10new 10new
call setline(1, range(1,100)) call setline(1, range(1,100))
endfunc endfunc
func! MyFormatExpr() func MyFormatExpr()
" Adds '->$' at lines having numbers followed by trailing whitespace " Adds '->$' at lines having numbers followed by trailing whitespace
for ln in range(v:lnum, v:lnum+v:count-1) for ln in range(v:lnum, v:lnum+v:count-1)
let line = getline(ln) let line = getline(ln)
@ -17,7 +17,7 @@ func! MyFormatExpr()
endfor endfor
endfunc endfunc
func! CountSpaces(type, ...) func CountSpaces(type, ...)
" for testing operatorfunc " for testing operatorfunc
" will count the number of spaces " will count the number of spaces
" and return the result in g:a " and return the result in g:a
@ -37,7 +37,7 @@ func! CountSpaces(type, ...)
let @@ = reg_save let @@ = reg_save
endfunc endfunc
func! OpfuncDummy(type, ...) func OpfuncDummy(type, ...)
" for testing operatorfunc " for testing operatorfunc
let g:opt=&linebreak let g:opt=&linebreak
@ -81,7 +81,7 @@ fun! Test_normal00_optrans()
bw! bw!
endfunc endfunc
func! Test_normal01_keymodel() func Test_normal01_keymodel()
call Setup_NewWindow() call Setup_NewWindow()
" Test 1: depending on 'keymodel' <s-down> does something different " Test 1: depending on 'keymodel' <s-down> does something different
50 50
@ -115,7 +115,7 @@ func! Test_normal01_keymodel()
bw! bw!
endfunc endfunc
func! Test_normal02_selectmode() func Test_normal02_selectmode()
" some basic select mode tests " some basic select mode tests
call Setup_NewWindow() call Setup_NewWindow()
50 50
@ -129,7 +129,7 @@ func! Test_normal02_selectmode()
bw! bw!
endfunc endfunc
func! Test_normal02_selectmode2() func Test_normal02_selectmode2()
" some basic select mode tests " some basic select mode tests
call Setup_NewWindow() call Setup_NewWindow()
50 50
@ -139,7 +139,7 @@ func! Test_normal02_selectmode2()
bw! bw!
endfunc endfunc
func! Test_normal03_join() func Test_normal03_join()
" basic join test " basic join test
call Setup_NewWindow() call Setup_NewWindow()
50 50
@ -159,7 +159,7 @@ func! Test_normal03_join()
bw! bw!
endfunc endfunc
func! Test_normal04_filter() func Test_normal04_filter()
" basic filter test " basic filter test
" only test on non windows platform " only test on non windows platform
if has('win32') if has('win32')
@ -185,7 +185,7 @@ func! Test_normal04_filter()
bw! bw!
endfunc endfunc
func! Test_normal05_formatexpr() func Test_normal05_formatexpr()
" basic formatexpr test " basic formatexpr test
call Setup_NewWindow() call Setup_NewWindow()
%d_ %d_
@ -222,7 +222,7 @@ func Test_normal05_formatexpr_setopt()
set formatexpr= set formatexpr=
endfunc endfunc
func! Test_normal06_formatprg() func Test_normal06_formatprg()
" basic test for formatprg " basic test for formatprg
" only test on non windows platform " only test on non windows platform
if has('win32') if has('win32')
@ -256,7 +256,7 @@ func! Test_normal06_formatprg()
call delete('Xsed_format.sh') call delete('Xsed_format.sh')
endfunc endfunc
func! Test_normal07_internalfmt() func Test_normal07_internalfmt()
" basic test for internal formmatter to textwidth of 12 " basic test for internal formmatter to textwidth of 12
let list=range(1,11) let list=range(1,11)
call map(list, 'v:val." "') call map(list, 'v:val." "')
@ -270,7 +270,7 @@ func! Test_normal07_internalfmt()
bw! bw!
endfunc endfunc
func! Test_normal08_fold() func Test_normal08_fold()
" basic tests for foldopen/folddelete " basic tests for foldopen/folddelete
if !has("folding") if !has("folding")
return return
@ -329,7 +329,7 @@ func! Test_normal08_fold()
bw! bw!
endfunc endfunc
func! Test_normal09_operatorfunc() func Test_normal09_operatorfunc()
" Test operatorfunc " Test operatorfunc
call Setup_NewWindow() call Setup_NewWindow()
" Add some spaces for counting " Add some spaces for counting
@ -359,7 +359,7 @@ func! Test_normal09_operatorfunc()
bw! bw!
endfunc endfunc
func! Test_normal09a_operatorfunc() func Test_normal09a_operatorfunc()
" Test operatorfunc " Test operatorfunc
call Setup_NewWindow() call Setup_NewWindow()
" Add some spaces for counting " Add some spaces for counting
@ -385,7 +385,7 @@ func! Test_normal09a_operatorfunc()
unlet! g:opt unlet! g:opt
endfunc endfunc
func! Test_normal10_expand() func Test_normal10_expand()
" Test for expand() " Test for expand()
10new 10new
call setline(1, ['1', 'ifooar,,cbar']) call setline(1, ['1', 'ifooar,,cbar'])
@ -420,7 +420,7 @@ func! Test_normal10_expand()
bw! bw!
endfunc endfunc
func! Test_normal11_showcmd() func Test_normal11_showcmd()
" test for 'showcmd' " test for 'showcmd'
10new 10new
exe "norm! ofoobar\<esc>" exe "norm! ofoobar\<esc>"
@ -435,7 +435,7 @@ func! Test_normal11_showcmd()
bw! bw!
endfunc endfunc
func! Test_normal12_nv_error() func Test_normal12_nv_error()
" Test for nv_error " Test for nv_error
10new 10new
call setline(1, range(1,5)) call setline(1, range(1,5))
@ -445,7 +445,7 @@ func! Test_normal12_nv_error()
bw! bw!
endfunc endfunc
func! Test_normal13_help() func Test_normal13_help()
" Test for F1 " Test for F1
call assert_equal(1, winnr()) call assert_equal(1, winnr())
call feedkeys("\<f1>", 'txi') call feedkeys("\<f1>", 'txi')
@ -454,7 +454,7 @@ func! Test_normal13_help()
bw! bw!
endfunc endfunc
func! Test_normal14_page() func Test_normal14_page()
" basic test for Ctrl-F and Ctrl-B " basic test for Ctrl-F and Ctrl-B
call Setup_NewWindow() call Setup_NewWindow()
exe "norm! \<c-f>" exe "norm! \<c-f>"
@ -488,7 +488,7 @@ func! Test_normal14_page()
bw! bw!
endfunc endfunc
func! Test_normal14_page_eol() func Test_normal14_page_eol()
10new 10new
norm oxxxxxxx norm oxxxxxxx
exe "norm 2\<c-f>" exe "norm 2\<c-f>"
@ -497,7 +497,7 @@ func! Test_normal14_page_eol()
bw! bw!
endfunc endfunc
func! Test_normal15_z_scroll_vert() func Test_normal15_z_scroll_vert()
" basic test for z commands that scroll the window " basic test for z commands that scroll the window
call Setup_NewWindow() call Setup_NewWindow()
100 100
@ -586,7 +586,7 @@ func! Test_normal15_z_scroll_vert()
bw! bw!
endfunc endfunc
func! Test_normal16_z_scroll_hor() func Test_normal16_z_scroll_hor()
" basic test for z commands that scroll the window " basic test for z commands that scroll the window
10new 10new
15vsp 15vsp
@ -652,7 +652,7 @@ func! Test_normal16_z_scroll_hor()
bw! bw!
endfunc endfunc
func! Test_normal17_z_scroll_hor2() func Test_normal17_z_scroll_hor2()
" basic test for z commands that scroll the window " basic test for z commands that scroll the window
" using 'sidescrolloff' setting " using 'sidescrolloff' setting
10new 10new
@ -719,7 +719,7 @@ func! Test_normal17_z_scroll_hor2()
bw! bw!
endfunc endfunc
func! Test_normal18_z_fold() func Test_normal18_z_fold()
" basic tests for foldopen/folddelete " basic tests for foldopen/folddelete
if !has("folding") if !has("folding")
return return
@ -1090,7 +1090,7 @@ func! Test_normal18_z_fold()
bw! bw!
endfunc endfunc
func! Test_normal19_z_spell() func Test_normal19_z_spell()
if !has("spell") || !has('syntax') if !has("spell") || !has('syntax')
return return
endif endif
@ -1245,7 +1245,7 @@ func! Test_normal19_z_spell()
bw! bw!
endfunc endfunc
func! Test_normal20_exmode() func Test_normal20_exmode()
if !has("unix") if !has("unix")
" Reading from redirected file doesn't work on MS-Windows " Reading from redirected file doesn't work on MS-Windows
return return
@ -1263,24 +1263,38 @@ func! Test_normal20_exmode()
bw! bw!
endfunc endfunc
func! Test_normal21_nv_hat() func Test_normal21_nv_hat()
set hidden
new " Edit a fresh file and wipe the buffer list so that there is no alternate
" to many buffers opened already, will not work " file present. Next, check for the expected command failures.
"call assert_fails(":b#", 'E23') edit Xfoo | %bw
"call assert_equal('', @#) call assert_fails(':buffer #', 'E86')
e Xfoobar call assert_fails(':execute "normal! \<C-^>"', 'E23')
e Xfile2
call feedkeys("\<c-^>", 't') " Test for the expected behavior when switching between two named buffers.
call assert_equal("Xfile2", fnamemodify(bufname('%'), ':t')) edit Xfoo | edit Xbar
call feedkeys("f\<c-^>", 't') call feedkeys("\<C-^>", 'tx')
call assert_equal("Xfile2", fnamemodify(bufname('%'), ':t')) call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
" clean up call feedkeys("\<C-^>", 'tx')
set nohidden call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
bw!
" Test for the expected behavior when only one buffer is named.
enew | let l:nr = bufnr('%')
call feedkeys("\<C-^>", 'tx')
call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
call feedkeys("\<C-^>", 'tx')
call assert_equal('', bufname('%'))
call assert_equal(l:nr, bufnr('%'))
" Test that no action is taken by "<C-^>" when an operator is pending.
edit Xfoo
call feedkeys("ci\<C-^>", 'tx')
call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
%bw!
endfunc endfunc
func! Test_normal22_zet() func Test_normal22_zet()
" Test for ZZ " Test for ZZ
" let shell = &shell " let shell = &shell
" let &shell = 'sh' " let &shell = 'sh'
@ -1308,7 +1322,7 @@ func! Test_normal22_zet()
" let &shell = shell " let &shell = shell
endfunc endfunc
func! Test_normal23_K() func Test_normal23_K()
" Test for K command " Test for K command
new new
call append(0, ['helphelp.txt', 'man', 'aa%bb', 'cc|dd']) call append(0, ['helphelp.txt', 'man', 'aa%bb', 'cc|dd'])
@ -1373,7 +1387,7 @@ func! Test_normal23_K()
bw! bw!
endfunc endfunc
func! Test_normal24_rot13() func Test_normal24_rot13()
" Testing for g?? g?g? " Testing for g?? g?g?
new new
call append(0, 'abcdefghijklmnopqrstuvwxyzäüö') call append(0, 'abcdefghijklmnopqrstuvwxyzäüö')
@ -1387,7 +1401,7 @@ func! Test_normal24_rot13()
bw! bw!
endfunc endfunc
func! Test_normal25_tag() func Test_normal25_tag()
" Testing for CTRL-] g CTRL-] g] " Testing for CTRL-] g CTRL-] g]
" CTRL-W g] CTRL-W CTRL-] CTRL-W g CTRL-] " CTRL-W g] CTRL-W CTRL-] CTRL-W g CTRL-]
h h
@ -1454,7 +1468,7 @@ func! Test_normal25_tag()
helpclose helpclose
endfunc endfunc
func! Test_normal26_put() func Test_normal26_put()
" Test for ]p ]P [p and [P " Test for ]p ]P [p and [P
new new
call append(0, ['while read LINE', 'do', ' ((count++))', ' if [ $? -ne 0 ]; then', " echo 'Error writing file'", ' fi', 'done']) call append(0, ['while read LINE', 'do', ' ((count++))', ' if [ $? -ne 0 ]; then', " echo 'Error writing file'", ' fi', 'done'])
@ -1473,7 +1487,7 @@ func! Test_normal26_put()
bw! bw!
endfunc endfunc
func! Test_normal27_bracket() func Test_normal27_bracket()
" Test for [' [` ]' ]` " Test for [' [` ]' ]`
call Setup_NewWindow() call Setup_NewWindow()
1,21s/.\+/ & b/ 1,21s/.\+/ & b/
@ -1524,7 +1538,7 @@ func! Test_normal27_bracket()
bw! bw!
endfunc endfunc
func! Test_normal28_parenthesis() func Test_normal28_parenthesis()
" basic testing for ( and ) " basic testing for ( and )
new new
call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here']) call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here'])
@ -1718,7 +1732,7 @@ fun! Test_normal31_r_cmd()
bw! bw!
endfunc endfunc
func! Test_normal32_g_cmd1() func Test_normal32_g_cmd1()
" Test for g*, g# " Test for g*, g#
new new
call append(0, ['abc.x_foo', 'x_foobar.abc']) call append(0, ['abc.x_foo', 'x_foobar.abc'])
@ -1849,7 +1863,7 @@ fun! Test_normal33_g_cmd2()
bw! bw!
endfunc endfunc
func! Test_g_ctrl_g() func Test_g_ctrl_g()
new new
let a = execute(":norm! g\<c-g>") let a = execute(":norm! g\<c-g>")
@ -2139,7 +2153,7 @@ fun! Test_normal41_insert_reg()
bw! bw!
endfunc endfunc
func! Test_normal42_halfpage() func Test_normal42_halfpage()
" basic test for Ctrl-D and Ctrl-U " basic test for Ctrl-D and Ctrl-U
call Setup_NewWindow() call Setup_NewWindow()
call assert_equal(5, &scroll) call assert_equal(5, &scroll)
@ -2207,7 +2221,7 @@ fun! Test_normal43_textobject1()
bw! bw!
endfunc endfunc
func! Test_normal44_textobjects2() func Test_normal44_textobjects2()
" basic testing for is and as text objects " basic testing for is and as text objects
new new
call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here']) call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here'])
@ -2262,7 +2276,7 @@ func! Test_normal44_textobjects2()
bw! bw!
endfunc endfunc
func! Test_normal45_drop() func Test_normal45_drop()
if !has('dnd') if !has('dnd')
" The ~ register does not exist " The ~ register does not exist
call assert_beeps('norm! "~') call assert_beeps('norm! "~')
@ -2280,7 +2294,7 @@ func! Test_normal45_drop()
bw! bw!
endfunc endfunc
func! Test_normal46_ignore() func Test_normal46_ignore()
new new
" How to test this? " How to test this?
" let's just for now test, that the buffer " let's just for now test, that the buffer
@ -2299,7 +2313,7 @@ func! Test_normal46_ignore()
bw! bw!
endfunc endfunc
func! Test_normal47_visual_buf_wipe() func Test_normal47_visual_buf_wipe()
" This was causing a crash or ml_get error. " This was causing a crash or ml_get error.
enew! enew!
call setline(1,'xxx') call setline(1,'xxx')
@ -2313,7 +2327,7 @@ func! Test_normal47_visual_buf_wipe()
set nomodified set nomodified
endfunc endfunc
func! Test_normal47_autocmd() func Test_normal47_autocmd()
" disabled, does not seem to be possible currently " disabled, does not seem to be possible currently
throw "Skipped: not possible to test cursorhold autocmd while waiting for input in normal_cmd" throw "Skipped: not possible to test cursorhold autocmd while waiting for input in normal_cmd"
new new
@ -2331,14 +2345,14 @@ func! Test_normal47_autocmd()
bw! bw!
endfunc endfunc
func! Test_normal48_wincmd() func Test_normal48_wincmd()
new new
exe "norm! \<c-w>c" exe "norm! \<c-w>c"
call assert_equal(1, winnr('$')) call assert_equal(1, winnr('$'))
call assert_fails(":norm! \<c-w>c", "E444") call assert_fails(":norm! \<c-w>c", "E444")
endfunc endfunc
func! Test_normal49_counts() func Test_normal49_counts()
new new
call setline(1, 'one two three four five six seven eight nine ten') call setline(1, 'one two three four five six seven eight nine ten')
1 1
@ -2347,7 +2361,7 @@ func! Test_normal49_counts()
bw! bw!
endfunc endfunc
func! Test_normal50_commandline() func Test_normal50_commandline()
if !has("timers") || !has("cmdline_hist") || !has("vertsplit") if !has("timers") || !has("cmdline_hist") || !has("vertsplit")
return return
endif endif
@ -2378,7 +2392,7 @@ func! Test_normal50_commandline()
bw! bw!
endfunc endfunc
func! Test_normal51_FileChangedRO() func Test_normal51_FileChangedRO()
if !has("autocmd") if !has("autocmd")
return return
endif endif
@ -2395,7 +2409,7 @@ func! Test_normal51_FileChangedRO()
call delete("Xreadonly.log") call delete("Xreadonly.log")
endfunc endfunc
func! Test_normal52_rl() func Test_normal52_rl()
if !has("rightleft") if !has("rightleft")
return return
endif endif
@ -2428,7 +2442,7 @@ func! Test_normal52_rl()
bw! bw!
endfunc endfunc
func! Test_normal53_digraph() func Test_normal53_digraph()
if !has('digraphs') if !has('digraphs')
return return
endif endif
@ -2516,6 +2530,29 @@ func Test_changelist()
let &ul = save_ul let &ul = save_ul
endfunc endfunc
func Test_nv_hat_count()
%bwipeout!
let l:nr = bufnr('%') + 1
call assert_fails(':execute "normal! ' . l:nr . '\<C-^>"', 'E92')
edit Xfoo
let l:foo_nr = bufnr('Xfoo')
edit Xbar
let l:bar_nr = bufnr('Xbar')
" Make sure we are not just using the alternate file.
edit Xbaz
call feedkeys(l:foo_nr . "\<C-^>", 'tx')
call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
call feedkeys(l:bar_nr . "\<C-^>", 'tx')
call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
%bwipeout!
endfunc
func Test_delete_until_paragraph() func Test_delete_until_paragraph()
new new
normal grádv} normal grádv}
@ -2617,3 +2654,80 @@ Piece of Java
close! close!
endfunc endfunc
fun! Test_normal_gdollar_cmd()
if !has("jumplist")
return
endif
" Tests for g cmds
call Setup_NewWindow()
" Make long lines that will wrap
%s/$/\=repeat(' foobar', 10)/
20vsp
set wrap
" Test for g$ with count
norm! gg
norm! 0vg$y
call assert_equal(20, col("'>"))
call assert_equal('1 foobar foobar foob', getreg(0))
norm! gg
norm! 0v4g$y
call assert_equal(72, col("'>"))
call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.."\n", getreg(0))
norm! gg
norm! 0v6g$y
call assert_equal(40, col("'>"))
call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
\ '2 foobar foobar foobar foobar foobar foo', getreg(0))
set nowrap
" clean up
norm! gg
norm! 0vg$y
call assert_equal(20, col("'>"))
call assert_equal('1 foobar foobar foob', getreg(0))
norm! gg
norm! 0v4g$y
call assert_equal(20, col("'>"))
call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
\ '2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
\ '3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
\ '4 foobar foobar foob', getreg(0))
norm! gg
norm! 0v6g$y
call assert_equal(20, col("'>"))
call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
\ '2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
\ '3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
\ '4 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
\ '5 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
\ '6 foobar foobar foob', getreg(0))
" Move to last line, also down movement is not possible, should still move
" the cursor to the last visible char
norm! G
norm! 0v6g$y
call assert_equal(20, col("'>"))
call assert_equal('100 foobar foobar fo', getreg(0))
bw!
endfunc
func Test_normal_gk()
" needs 80 column new window
new
vert 80new
put =[repeat('x',90)..' {{{1', 'x {{{1']
norm! gk
" In a 80 column wide terminal the window will be only 78 char
" (because Vim will leave space for the other window),
" but if the terminal is larger, it will be 80 chars, so verify the
" cursor column correctly.
call assert_equal(winwidth(0)+1, col('.'))
call assert_equal(winwidth(0)+1, virtcol('.'))
norm! j
call assert_equal(6, col('.'))
call assert_equal(6, virtcol('.'))
norm! gk
call assert_equal(95, col('.'))
call assert_equal(95, virtcol('.'))
bw!
bw!
endfunc

View File

@ -3315,6 +3315,20 @@ func Test_qfjump()
call Xqfjump_tests('l') call Xqfjump_tests('l')
endfunc endfunc
" Test helpgrep with lang specifier
func Xtest_helpgrep_with_lang_specifier(cchar)
call s:setup_commands(a:cchar)
Xhelpgrep Vim@en
call assert_equal('help', &filetype)
call assert_notequal(0, g:Xgetlist({'nr' : '$'}).nr)
new | only
endfunc
func Test_helpgrep_with_lang_specifier()
call Xtest_helpgrep_with_lang_specifier('c')
call Xtest_helpgrep_with_lang_specifier('l')
endfunc
" The following test used to crash Vim. " The following test used to crash Vim.
" Open the location list window and close the regular window associated with " Open the location list window and close the regular window associated with
" the location list. When the garbage collection runs now, it incorrectly " the location list. When the garbage collection runs now, it incorrectly

View File

@ -117,15 +117,71 @@ func Test_window_vertical_split()
bw bw
endfunc endfunc
" Test the ":wincmd ^" and "<C-W>^" commands.
func Test_window_split_edit_alternate() func Test_window_split_edit_alternate()
e Xa
e Xb
" Test for failure when the alternate buffer/file no longer exists.
edit Xfoo | %bw
call assert_fails(':wincmd ^', 'E23')
" Test for the expected behavior when we have two named buffers.
edit Xfoo | edit Xbar
wincmd ^ wincmd ^
call assert_equal('Xa', bufname(winbufnr(1))) call assert_equal('Xfoo', bufname(winbufnr(1)))
call assert_equal('Xb', bufname(winbufnr(2))) call assert_equal('Xbar', bufname(winbufnr(2)))
only
bw Xa Xb " Test for the expected behavior when the alternate buffer is not named.
enew | let l:nr1 = bufnr('%')
edit Xfoo | let l:nr2 = bufnr('%')
wincmd ^
call assert_equal(l:nr1, winbufnr(1))
call assert_equal(l:nr2, winbufnr(2))
only
" FIXME: this currently fails on AppVeyor, but passes locally
if !has('win32')
" Test the Normal mode command.
call feedkeys("\<C-W>\<C-^>", 'tx')
call assert_equal(l:nr2, winbufnr(1))
call assert_equal(l:nr1, winbufnr(2))
endif
%bw!
endfunc
" Test the ":[count]wincmd ^" and "[count]<C-W>^" commands.
func Test_window_split_edit_bufnr()
%bwipeout
let l:nr = bufnr('%') + 1
call assert_fails(':execute "normal! ' . l:nr . '\<C-W>\<C-^>"', 'E92')
call assert_fails(':' . l:nr . 'wincmd ^', 'E16')
call assert_fails(':0wincmd ^', 'E16')
edit Xfoo | edit Xbar | edit Xbaz
let l:foo_nr = bufnr('Xfoo')
let l:bar_nr = bufnr('Xbar')
let l:baz_nr = bufnr('Xbaz')
" FIXME: this currently fails on AppVeyor, but passes locally
if !has('win32')
call feedkeys(l:foo_nr . "\<C-W>\<C-^>", 'tx')
call assert_equal('Xfoo', bufname(winbufnr(1)))
call assert_equal('Xbaz', bufname(winbufnr(2)))
only
call feedkeys(l:bar_nr . "\<C-W>\<C-^>", 'tx')
call assert_equal('Xbar', bufname(winbufnr(1)))
call assert_equal('Xfoo', bufname(winbufnr(2)))
only
execute l:baz_nr . 'wincmd ^'
call assert_equal('Xbaz', bufname(winbufnr(1)))
call assert_equal('Xbar', bufname(winbufnr(2)))
endif
%bw!
endfunc endfunc
func Test_window_preview() func Test_window_preview()
@ -700,6 +756,42 @@ func Test_relative_cursor_second_line_after_resize()
let &so = so_save let &so = so_save
endfunc endfunc
func Test_split_noscroll()
let so_save = &so
enew
call setline(1, range(1, 8))
normal 100%
split
1wincmd w
let winid1 = win_getid()
let info1 = getwininfo(winid1)[0]
2wincmd w
let winid2 = win_getid()
let info2 = getwininfo(winid2)[0]
call assert_equal(1, info1.topline)
call assert_equal(1, info2.topline)
" window that fits all lines by itself, but not when split: closing other
" window should restore fraction.
only!
call setline(1, range(1, &lines - 10))
exe &lines / 4
let winid1 = win_getid()
let info1 = getwininfo(winid1)[0]
call assert_equal(1, info1.topline)
new
redraw
close
let info1 = getwininfo(winid1)[0]
call assert_equal(1, info1.topline)
bwipe!
let &so = so_save
endfunc
" Tests for the winnr() function " Tests for the winnr() function
func Test_winnr() func Test_winnr()
only | tabonly only | tabonly

View File

@ -131,8 +131,20 @@ do_window (
case '^': case '^':
CHECK_CMDWIN; CHECK_CMDWIN;
reset_VIsual_and_resel(); // stop Visual mode reset_VIsual_and_resel(); // stop Visual mode
cmd_with_count("split #", (char_u *)cbuf, sizeof(cbuf), Prenum);
do_cmdline_cmd(cbuf); if (buflist_findnr(Prenum == 0 ? curwin->w_alt_fnum : Prenum) == NULL) {
if (Prenum == 0) {
EMSG(_(e_noalt));
} else {
EMSGN(_("E92: Buffer %" PRId64 " not found"), Prenum);
}
break;
}
if (!curbuf_locked() && win_split(0, 0) == OK) {
(void)buflist_getfile(Prenum == 0 ? curwin->w_alt_fnum : Prenum,
(linenr_T)0, GETF_ALT, false);
}
break; break;
/* open new window */ /* open new window */
@ -5598,10 +5610,14 @@ void scroll_to_fraction(win_T *wp, int prev_height)
int sline, line_size; int sline, line_size;
int height = wp->w_height_inner; int height = wp->w_height_inner;
// Don't change w_topline when height is zero. Don't set w_topline when // Don't change w_topline in any of these cases:
// 'scrollbind' is set and this isn't the current window. // - window height is 0
// - 'scrollbind' is set and this isn't the current window
// - window height is sufficient to display the whole buffer and first line
// is visible.
if (height > 0 if (height > 0
&& (!wp->w_p_scb || wp == curwin) && (!wp->w_p_scb || wp == curwin)
&& (height < wp->w_buffer->b_ml.ml_line_count || wp->w_topline > 1)
) { ) {
/* /*
* Find a value for w_topline that shows the cursor at the same * Find a value for w_topline that shows the cursor at the same

View File

@ -734,11 +734,11 @@ describe(":substitute, inccommand=split", function()
feed_command("set nomodified") feed_command("set nomodified")
feed(":%s/tw") feed(":%s/tw")
screen:expect([[ screen:expect([[
Inc substitution on |
{12:tw}o lines |
Inc substitution on | Inc substitution on |
{12:tw}o lines | {12:tw}o lines |
| |
{15:~ }|
{15:~ }|
{11:[No Name] }| {11:[No Name] }|
|2| {12:tw}o lines | |2| {12:tw}o lines |
|4| {12:tw}o lines | |4| {12:tw}o lines |
@ -791,11 +791,11 @@ describe(":substitute, inccommand=split", function()
it('shows split window when typing the pattern', function() it('shows split window when typing the pattern', function()
feed(":%s/tw") feed(":%s/tw")
screen:expect([[ screen:expect([[
Inc substitution on |
{12:tw}o lines |
Inc substitution on | Inc substitution on |
{12:tw}o lines | {12:tw}o lines |
| |
{15:~ }|
{15:~ }|
{11:[No Name] [+] }| {11:[No Name] [+] }|
|2| {12:tw}o lines | |2| {12:tw}o lines |
|4| {12:tw}o lines | |4| {12:tw}o lines |
@ -812,11 +812,11 @@ describe(":substitute, inccommand=split", function()
it('shows preview with empty replacement', function() it('shows preview with empty replacement', function()
feed(":%s/tw/") feed(":%s/tw/")
screen:expect([[ screen:expect([[
Inc substitution on |
o lines |
Inc substitution on | Inc substitution on |
o lines | o lines |
| |
{15:~ }|
{15:~ }|
{11:[No Name] [+] }| {11:[No Name] [+] }|
|2| o lines | |2| o lines |
|4| o lines | |4| o lines |
@ -831,11 +831,11 @@ describe(":substitute, inccommand=split", function()
feed("x") feed("x")
screen:expect([[ screen:expect([[
Inc substitution on |
{12:x}o lines |
Inc substitution on | Inc substitution on |
{12:x}o lines | {12:x}o lines |
| |
{15:~ }|
{15:~ }|
{11:[No Name] [+] }| {11:[No Name] [+] }|
|2| {12:x}o lines | |2| {12:x}o lines |
|4| {12:x}o lines | |4| {12:x}o lines |
@ -850,11 +850,11 @@ describe(":substitute, inccommand=split", function()
feed("<bs>") feed("<bs>")
screen:expect([[ screen:expect([[
Inc substitution on |
o lines |
Inc substitution on | Inc substitution on |
o lines | o lines |
| |
{15:~ }|
{15:~ }|
{11:[No Name] [+] }| {11:[No Name] [+] }|
|2| o lines | |2| o lines |
|4| o lines | |4| o lines |
@ -872,11 +872,11 @@ describe(":substitute, inccommand=split", function()
it('shows split window when typing replacement', function() it('shows split window when typing replacement', function()
feed(":%s/tw/XX") feed(":%s/tw/XX")
screen:expect([[ screen:expect([[
Inc substitution on |
{12:XX}o lines |
Inc substitution on | Inc substitution on |
{12:XX}o lines | {12:XX}o lines |
| |
{15:~ }|
{15:~ }|
{11:[No Name] [+] }| {11:[No Name] [+] }|
|2| {12:XX}o lines | |2| {12:XX}o lines |
|4| {12:XX}o lines | |4| {12:XX}o lines |
@ -938,11 +938,11 @@ describe(":substitute, inccommand=split", function()
feed(":%s/tw") feed(":%s/tw")
-- 'cursorline' is NOT active during preview. -- 'cursorline' is NOT active during preview.
screen:expect([[ screen:expect([[
Inc substitution on |
{12:tw}o lines | {12:tw}o lines |
Inc substitution on | Inc substitution on |
{12:tw}o lines | {12:tw}o lines |
| |
{15:~ }|
{11:[No Name] [+] }| {11:[No Name] [+] }|
|2| {12:tw}o lines | |2| {12:tw}o lines |
|4| {12:tw}o lines | |4| {12:tw}o lines |
@ -2205,11 +2205,11 @@ describe(":substitute", function()
feed("/KKK") feed("/KKK")
screen:expect([[ screen:expect([[
T T123 T T123 T2T TT T23423424|
x |
afa {12:KKK}adf la;lkd {12:KKK}alx | afa {12:KKK}adf la;lkd {12:KKK}alx |
| |
{15:~ }| {15:~ }|
{15:~ }|
{15:~ }|
{11:[No Name] [+] }| {11:[No Name] [+] }|
|3| afa {12:KKK}adf la;lkd {12:KKK}alx | |3| afa {12:KKK}adf la;lkd {12:KKK}alx |
{15:~ }| {15:~ }|
@ -2485,11 +2485,11 @@ describe(":substitute", function()
wait() wait()
feed([[:%s/\(some\)\@<lt>!thing/one/]]) feed([[:%s/\(some\)\@<lt>!thing/one/]])
screen:expect([[ screen:expect([[
something |
every{12:one} | every{12:one} |
someone | someone |
{15:~ }| {15:~ }|
{15:~ }| {15:~ }|
{15:~ }|
{11:[No Name] [+] }| {11:[No Name] [+] }|
|2| every{12:one} | |2| every{12:one} |
{15:~ }| {15:~ }|
@ -2527,11 +2527,11 @@ describe(":substitute", function()
wait() wait()
feed([[:%s/some\(thing\)\@!/every/]]) feed([[:%s/some\(thing\)\@!/every/]])
screen:expect([[ screen:expect([[
something |
everything |
{12:every}one | {12:every}one |
{15:~ }| {15:~ }|
{15:~ }| {15:~ }|
{15:~ }|
{15:~ }|
{11:[No Name] [+] }| {11:[No Name] [+] }|
|3| {12:every}one | |3| {12:every}one |
{15:~ }| {15:~ }|

View File

@ -419,9 +419,9 @@ describe('ui/mouse/input', function()
meths.set_option('showtabline', 2) meths.set_option('showtabline', 2)
screen:expect([[ screen:expect([[
{fill:test-test2 }| {fill:test-test2 }|
testing |
mouse | mouse |
support and selectio^n | support and selectio^n |
{0:~ }|
| |
]]) ]])
meths.set_var('reply', {}) meths.set_var('reply', {})
@ -539,9 +539,9 @@ describe('ui/mouse/input', function()
feed_command('tabprevious') -- go to first tab feed_command('tabprevious') -- go to first tab
screen:expect([[ screen:expect([[
{sel: + foo }{tab: + bar }{fill: }{tab:X}| {sel: + foo }{tab: + bar }{fill: }{tab:X}|
testing |
mouse | mouse |
support and selectio^n | support and selectio^n |
{0:~ }|
:tabprevious | :tabprevious |
]]) ]])
feed('<LeftMouse><10,0><LeftRelease>') -- go to second tab feed('<LeftMouse><10,0><LeftRelease>') -- go to second tab

View File

@ -1491,20 +1491,20 @@ describe('builtin popupmenu', function()
command("split") command("split")
screen:expect([[ screen:expect([[
xx |
choice^ | choice^ |
{1:~ }|
{n:word }{1: }| {n:word }{1: }|
{s:choice }{4: }| {s:choice }{4: }|
{n:text } | {n:text } |
{n:thing }{1: }| {n:thing } |
{3:[No Name] [+] }| {3:[No Name] [+] }|
{2:-- INSERT --} | {2:-- INSERT --} |
]]) ]])
meths.input_mouse('wheel', 'down', '', 0, 6, 15) meths.input_mouse('wheel', 'down', '', 0, 6, 15)
screen:expect{grid=[[ screen:expect{grid=[[
xx |
choice^ | choice^ |
{1:~ }|
{n:word }{1: }| {n:word }{1: }|
{s:choice }{4: }| {s:choice }{4: }|
{n:text } | {n:text } |