Merge #10921 from janlazo/vim-8.0.1768

vim-patch:8.0.{1768,1806},8.1.{46,1063}
This commit is contained in:
Justin M. Keyes 2019-09-03 04:49:30 -07:00 committed by GitHub
commit 03be64ce2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 143 additions and 43 deletions

View File

@ -5541,13 +5541,15 @@ insertchar (
// 'paste' is set).. // 'paste' is set)..
// Don't do this when there an InsertCharPre autocommand is defined, // Don't do this when there an InsertCharPre autocommand is defined,
// because we need to fire the event for every character. // because we need to fire the event for every character.
// Do the check for InsertCharPre before the call to vpeekc() because the
// InsertCharPre autocommand could change the input buffer.
if (!ISSPECIAL(c) if (!ISSPECIAL(c)
&& (!has_mbyte || (*mb_char2len)(c) == 1) && (!has_mbyte || (*mb_char2len)(c) == 1)
&& !has_event(EVENT_INSERTCHARPRE)
&& vpeekc() != NUL && vpeekc() != NUL
&& !(State & REPLACE_FLAG) && !(State & REPLACE_FLAG)
&& !cindent_on() && !cindent_on()
&& !p_ri && !p_ri) {
&& !has_event(EVENT_INSERTCHARPRE)) {
#define INPUT_BUFLEN 100 #define INPUT_BUFLEN 100
char_u buf[INPUT_BUFLEN + 1]; char_u buf[INPUT_BUFLEN + 1];
int i; int i;

View File

@ -9990,12 +9990,18 @@ static void ex_set(exarg_T *eap)
(void)do_set(eap->arg, flags); (void)do_set(eap->arg, flags);
} }
void set_no_hlsearch(bool flag)
{
no_hlsearch = flag;
set_vim_var_nr(VV_HLSEARCH, !no_hlsearch && p_hls);
}
/* /*
* ":nohlsearch" * ":nohlsearch"
*/ */
static void ex_nohlsearch(exarg_T *eap) static void ex_nohlsearch(exarg_T *eap)
{ {
SET_NO_HLSEARCH(TRUE); set_no_hlsearch(true);
redraw_all_later(SOME_VALID); redraw_all_later(SOME_VALID);
} }

View File

@ -1830,7 +1830,7 @@ static int command_line_changed(CommandLineState *s)
// If there is no command line, don't do anything // If there is no command line, don't do anything
if (ccline.cmdlen == 0) { if (ccline.cmdlen == 0) {
i = 0; i = 0;
SET_NO_HLSEARCH(true); // turn off previous highlight set_no_hlsearch(true); // turn off previous highlight
redraw_all_later(SOME_VALID); redraw_all_later(SOME_VALID);
} else { } else {
int search_flags = SEARCH_OPT + SEARCH_NOOF + SEARCH_PEEK; int search_flags = SEARCH_OPT + SEARCH_NOOF + SEARCH_PEEK;
@ -1888,7 +1888,7 @@ static int command_line_changed(CommandLineState *s)
// Disable 'hlsearch' highlighting if the pattern matches // Disable 'hlsearch' highlighting if the pattern matches
// everything. Avoids a flash when typing "foo\|". // everything. Avoids a flash when typing "foo\|".
if (empty_pattern(ccline.cmdbuff)) { if (empty_pattern(ccline.cmdbuff)) {
SET_NO_HLSEARCH(true); set_no_hlsearch(true);
} }
validate_cursor(); validate_cursor();

View File

@ -862,8 +862,8 @@ EXTERN char_u wim_flags[4];
# define STL_IN_TITLE 2 # define STL_IN_TITLE 2
EXTERN int stl_syntax INIT(= 0); EXTERN int stl_syntax INIT(= 0);
/* don't use 'hlsearch' temporarily */ // don't use 'hlsearch' temporarily
EXTERN int no_hlsearch INIT(= FALSE); EXTERN bool no_hlsearch INIT(= false);
/* Page number used for %N in 'pageheader' and 'guitablabel'. */ /* Page number used for %N in 'pageheader' and 'guitablabel'. */
EXTERN linenr_T printer_page_num; EXTERN linenr_T printer_page_num;

View File

@ -3959,7 +3959,7 @@ static char *set_bool_option(const int opt_idx, char_u *const varp,
redraw_all_later(SOME_VALID); redraw_all_later(SOME_VALID);
} else if ((int *)varp == &p_hls) { } else if ((int *)varp == &p_hls) {
// when 'hlsearch' is set or reset: reset no_hlsearch // when 'hlsearch' is set or reset: reset no_hlsearch
SET_NO_HLSEARCH(false); set_no_hlsearch(false);
} else if ((int *)varp == &curwin->w_p_scb) { } else if ((int *)varp == &curwin->w_p_scb) {
// when 'scrollbind' is set: snapshot the current position to avoid a jump // when 'scrollbind' is set: snapshot the current position to avoid a jump
// at the end of normal_cmd() // at the end of normal_cmd()
@ -4330,19 +4330,26 @@ static char *set_num_option(int opt_idx, char_u *varp, long value,
// Number options that need some action when changed // Number options that need some action when changed
if (pp == &p_wh) { if (pp == &p_wh) {
// 'winheight'
if (!ONE_WINDOW && curwin->w_height < p_wh) { if (!ONE_WINDOW && curwin->w_height < p_wh) {
win_setheight((int)p_wh); win_setheight((int)p_wh);
} }
} else if (pp == &p_hh) { } else if (pp == &p_hh) {
// 'helpheight'
if (!ONE_WINDOW && curbuf->b_help && curwin->w_height < p_hh) { if (!ONE_WINDOW && curbuf->b_help && curwin->w_height < p_hh) {
win_setheight((int)p_hh); win_setheight((int)p_hh);
} }
} else if (pp == &p_wmh) { } else if (pp == &p_wmh) {
// 'winminheight'
win_setminheight(); win_setminheight();
} else if (pp == &p_wiw) { } else if (pp == &p_wiw) {
// 'winwidth'
if (!ONE_WINDOW && curwin->w_width < p_wiw) { if (!ONE_WINDOW && curwin->w_width < p_wiw) {
win_setwidth((int)p_wiw); win_setwidth((int)p_wiw);
} }
} else if (pp == &p_wmw) {
// 'winminwidth'
win_setminwidth();
} else if (pp == &p_ls) { } else if (pp == &p_ls) {
last_status(false); // (re)set last window status line. last_status(false); // (re)set last window status line.
} else if (pp == &p_stal) { } else if (pp == &p_stal) {

View File

@ -5762,7 +5762,7 @@ next_search_hl (
if (shl == &search_hl) { if (shl == &search_hl) {
// don't free regprog in the match list, it's a copy // don't free regprog in the match list, it's a copy
vim_regfree(shl->rm.regprog); vim_regfree(shl->rm.regprog);
SET_NO_HLSEARCH(TRUE); set_no_hlsearch(true);
} }
shl->rm.regprog = NULL; shl->rm.regprog = NULL;
shl->lnum = 0; shl->lnum = 0;

View File

@ -100,7 +100,7 @@ static struct spat saved_spats[2];
// searching // searching
static struct spat saved_last_search_spat; static struct spat saved_last_search_spat;
static int saved_last_idx = 0; static int saved_last_idx = 0;
static int saved_no_hlsearch = 0; static bool saved_no_hlsearch = false;
static char_u *mr_pattern = NULL; // pattern used by search_regcomp() static char_u *mr_pattern = NULL; // pattern used by search_regcomp()
static int mr_pattern_alloced = false; // mr_pattern was allocated static int mr_pattern_alloced = false; // mr_pattern was allocated
@ -248,7 +248,7 @@ void save_re_pat(int idx, char_u *pat, int magic)
/* If 'hlsearch' set and search pat changed: need redraw. */ /* If 'hlsearch' set and search pat changed: need redraw. */
if (p_hls) if (p_hls)
redraw_all_later(SOME_VALID); redraw_all_later(SOME_VALID);
SET_NO_HLSEARCH(FALSE); set_no_hlsearch(false);
} }
} }
@ -281,7 +281,7 @@ void restore_search_patterns(void)
free_spat(&spats[1]); free_spat(&spats[1]);
spats[1] = saved_spats[1]; spats[1] = saved_spats[1];
last_idx = saved_last_idx; last_idx = saved_last_idx;
SET_NO_HLSEARCH(saved_no_hlsearch); set_no_hlsearch(saved_no_hlsearch);
} }
} }
@ -330,7 +330,7 @@ void restore_last_search_pattern(void)
spats[RE_SEARCH] = saved_last_search_spat; spats[RE_SEARCH] = saved_last_search_spat;
set_vv_searchforward(); set_vv_searchforward();
last_idx = saved_last_idx; last_idx = saved_last_idx;
SET_NO_HLSEARCH(saved_no_hlsearch); set_no_hlsearch(saved_no_hlsearch);
} }
char_u *last_search_pattern(void) char_u *last_search_pattern(void)
@ -1048,7 +1048,7 @@ int do_search(
*/ */
if (no_hlsearch && !(options & SEARCH_KEEP)) { if (no_hlsearch && !(options & SEARCH_KEEP)) {
redraw_all_later(SOME_VALID); redraw_all_later(SOME_VALID);
SET_NO_HLSEARCH(FALSE); set_no_hlsearch(false);
} }
/* /*

View File

@ -32,6 +32,7 @@
#include "nvim/api/private/helpers.h" #include "nvim/api/private/helpers.h"
#include "nvim/buffer.h" #include "nvim/buffer.h"
#include "nvim/buffer_defs.h" #include "nvim/buffer_defs.h"
#include "nvim/ex_docmd.h"
#include "nvim/ex_getln.h" #include "nvim/ex_getln.h"
#include "nvim/search.h" #include "nvim/search.h"
#include "nvim/regexp.h" #include "nvim/regexp.h"
@ -1274,7 +1275,7 @@ static void shada_read(ShaDaReadDef *const sd_reader, const int flags)
if (cur_entry.data.search_pattern.is_last_used) { if (cur_entry.data.search_pattern.is_last_used) {
set_last_used_pattern( set_last_used_pattern(
cur_entry.data.search_pattern.is_substitute_pattern); cur_entry.data.search_pattern.is_substitute_pattern);
SET_NO_HLSEARCH(!cur_entry.data.search_pattern.highlighted); set_no_hlsearch(!cur_entry.data.search_pattern.highlighted);
} }
// Do not free shada entry: its allocated memory was saved above. // Do not free shada entry: its allocated memory was saved above.
break; break;

View File

@ -2310,7 +2310,6 @@ static int jumpto_tag(
int retval = FAIL; int retval = FAIL;
int getfile_result = GETFILE_UNUSED; int getfile_result = GETFILE_UNUSED;
int search_options; int search_options;
int save_no_hlsearch;
win_T *curwin_save = NULL; win_T *curwin_save = NULL;
char_u *full_fname = NULL; char_u *full_fname = NULL;
const bool old_KeyTyped = KeyTyped; // getting the file may reset it const bool old_KeyTyped = KeyTyped; // getting the file may reset it
@ -2453,9 +2452,9 @@ static int jumpto_tag(
secure = 1; secure = 1;
++sandbox; ++sandbox;
save_magic = p_magic; save_magic = p_magic;
p_magic = FALSE; /* always execute with 'nomagic' */ p_magic = false; // always execute with 'nomagic'
/* Save value of no_hlsearch, jumping to a tag is not a real search */ // Save value of no_hlsearch, jumping to a tag is not a real search
save_no_hlsearch = no_hlsearch; const bool save_no_hlsearch = no_hlsearch;
/* /*
* If 'cpoptions' contains 't', store the search pattern for the "n" * If 'cpoptions' contains 't', store the search pattern for the "n"
@ -2560,7 +2559,7 @@ static int jumpto_tag(
--sandbox; --sandbox;
/* restore no_hlsearch when keeping the old search pattern */ /* restore no_hlsearch when keeping the old search pattern */
if (search_options) { if (search_options) {
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!).

View File

@ -15,14 +15,48 @@ func Test_complete_list()
endfunc endfunc
func Test_complete_wildmenu() func Test_complete_wildmenu()
call writefile(['testfile1'], 'Xtestfile1') call mkdir('Xdir1/Xdir2', 'p')
call writefile(['testfile2'], 'Xtestfile2') call writefile(['testfile1'], 'Xdir1/Xtestfile1')
call writefile(['testfile2'], 'Xdir1/Xtestfile2')
call writefile(['testfile3'], 'Xdir1/Xdir2/Xtestfile3')
call writefile(['testfile3'], 'Xdir1/Xdir2/Xtestfile4')
set wildmenu set wildmenu
call feedkeys(":e Xtestf\t\t\r", "tx")
" Pressing <Tab> completes, and moves to next files when pressing again.
call feedkeys(":e Xdir1/\<Tab>\<Tab>\<CR>", 'tx')
call assert_equal('testfile1', getline(1))
call feedkeys(":e Xdir1/\<Tab>\<Tab>\<Tab>\<CR>", 'tx')
call assert_equal('testfile2', getline(1)) call assert_equal('testfile2', getline(1))
call delete('Xtestfile1') " <S-Tab> is like <Tab> but begin with the last match and then go to
call delete('Xtestfile2') " previous.
call feedkeys(":e Xdir1/Xtest\<S-Tab>\<CR>", 'tx')
call assert_equal('testfile2', getline(1))
call feedkeys(":e Xdir1/Xtest\<S-Tab>\<S-Tab>\<CR>", 'tx')
call assert_equal('testfile1', getline(1))
" <Left>/<Right> to move to previous/next file.
call feedkeys(":e Xdir1/\<Tab>\<Right>\<CR>", 'tx')
call assert_equal('testfile1', getline(1))
call feedkeys(":e Xdir1/\<Tab>\<Right>\<Right>\<CR>", 'tx')
call assert_equal('testfile2', getline(1))
call feedkeys(":e Xdir1/\<Tab>\<Right>\<Right>\<Left>\<CR>", 'tx')
call assert_equal('testfile1', getline(1))
" <Up>/<Down> to go up/down directories.
call feedkeys(":e Xdir1/\<Tab>\<Down>\<CR>", 'tx')
call assert_equal('testfile3', getline(1))
call feedkeys(":e Xdir1/\<Tab>\<Down>\<Up>\<Right>\<CR>", 'tx')
call assert_equal('testfile1', getline(1))
" cleanup
%bwipe
call delete('Xdir1/Xdir2/Xtestfile4')
call delete('Xdir1/Xdir2/Xtestfile3')
call delete('Xdir1/Xtestfile2')
call delete('Xdir1/Xtestfile1')
call delete('Xdir1/Xdir2', 'd')
call delete('Xdir1', 'd')
set nowildmenu set nowildmenu
endfunc endfunc

View File

@ -106,13 +106,22 @@ endfunc
func Test_mksession_winheight() func Test_mksession_winheight()
new new
set winheight=10 winminheight=2 set winheight=10
set winminheight=2
mksession! Xtest_mks.out mksession! Xtest_mks.out
source Xtest_mks.out source Xtest_mks.out
call delete('Xtest_mks.out') call delete('Xtest_mks.out')
endfunc endfunc
func Test_mksession_large_winheight()
set winheight=999
mksession! Xtest_mks_winheight.out
set winheight&
source Xtest_mks_winheight.out
call delete('Xtest_mks_winheight.out')
endfunc
" Verify that arglist is stored correctly to the session file. " Verify that arglist is stored correctly to the session file.
func Test_mksession_arglist() func Test_mksession_arglist()
argdel * argdel *

View File

@ -746,6 +746,36 @@ func Test_popup_complete_backwards()
bwipe! bwipe!
endfunc endfunc
fun! Test_complete_o_tab()
throw 'skipped: Nvim does not support test_override()'
let s:o_char_pressed = 0
fun! s:act_on_text_changed()
if s:o_char_pressed
let s:o_char_pressed = 0
call feedkeys("\<c-x>\<c-n>", 'i')
endif
endf
set completeopt=menu,noselect
new
imap <expr> <buffer> <tab> pumvisible() ? "\<c-p>" : "X"
autocmd! InsertCharPre <buffer> let s:o_char_pressed = (v:char ==# 'o')
autocmd! TextChangedI <buffer> call <sid>act_on_text_changed()
call setline(1, ['hoard', 'hoax', 'hoarse', ''])
let l:expected = ['hoard', 'hoax', 'hoarse', 'hoax', 'hoax']
call cursor(4,1)
call test_override("char_avail", 1)
call feedkeys("Ahoa\<tab>\<tab>\<c-y>\<esc>", 'tx')
call feedkeys("oho\<tab>\<tab>\<c-y>\<esc>", 'tx')
call assert_equal(l:expected, getline(1,'$'))
call test_override("char_avail", 0)
bwipe!
set completeopt&
delfunc s:act_on_text_changed
endf
func Test_popup_complete_info_01() func Test_popup_complete_info_01()
new new
inoremap <buffer><F5> <C-R>=complete_info().mode<CR> inoremap <buffer><F5> <C-R>=complete_info().mode<CR>

View File

@ -296,9 +296,6 @@ enum { FOLD_TEXT_LEN = 51 }; //!< buffer size for get_foldtext()
#include "nvim/buffer_defs.h" // buffer and windows #include "nvim/buffer_defs.h" // buffer and windows
#include "nvim/ex_cmds_defs.h" // Ex command defines #include "nvim/ex_cmds_defs.h" // Ex command defines
# define SET_NO_HLSEARCH(flag) no_hlsearch = (flag); set_vim_var_nr( \
VV_HLSEARCH, !no_hlsearch && p_hls)
// Used for flags in do_in_path() // Used for flags in do_in_path()
#define DIP_ALL 0x01 // all matches, not just the first one #define DIP_ALL 0x01 // all matches, not just the first one
#define DIP_DIR 0x02 // find directories instead of files #define DIP_DIR 0x02 // find directories instead of files

View File

@ -5229,27 +5229,42 @@ static void frame_setwidth(frame_T *curfrp, int width)
} }
} }
/* // Check 'winminheight' for a valid value and reduce it if needed.
* Check 'winminheight' for a valid value.
*/
void win_setminheight(void) void win_setminheight(void)
{ {
int room; bool first = true;
int first = TRUE;
/* loop until there is a 'winminheight' that is possible */ // loop until there is a 'winminheight' that is possible
while (p_wmh > 0) { while (p_wmh > 0) {
/* TODO: handle vertical splits */ const int room = Rows - p_ch;
room = -p_wh; const int needed = frame_minheight(topframe, NULL);
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { if (room >= needed) {
room += wp->w_height - p_wmh;
}
if (room >= 0)
break; break;
--p_wmh; }
p_wmh--;
if (first) { if (first) {
EMSG(_(e_noroom)); EMSG(_(e_noroom));
first = FALSE; first = false;
}
}
}
// Check 'winminwidth' for a valid value and reduce it if needed.
void win_setminwidth(void)
{
bool first = true;
// loop until there is a 'winminheight' that is possible
while (p_wmw > 0) {
const int room = Columns;
const int needed = frame_minwidth(topframe, NULL);
if (room >= needed) {
break;
}
p_wmw--;
if (first) {
EMSG(_(e_noroom));
first = false;
} }
} }
} }