vim-patch:8.0.1768: SET_NO_HLSEARCH() used in a wrong way

Problem:    SET_NO_HLSEARCH() used in a wrong way.
Solution:   Make it a function. (suggested by Dominique Pelle,
            closes vim/vim#2850)
451fc7b954
This commit is contained in:
Jan Edmund Lazo
2019-09-02 15:56:29 -04:00
parent 6434a0bf99
commit 07b209b1fe
9 changed files with 24 additions and 21 deletions

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()

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

@@ -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