summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpgen <p.gen.progs@gmail.com>2021-02-06 22:15:31 +0100
committerpgen <p.gen.progs@gmail.com>2021-02-10 00:34:00 +0100
commit0baa84486e91beefb2d071e77247b674c1d43794 (patch)
treecdf233cef335a5a258ef83174ef8a1dfeed64f90
parent29b697207b3256232a4775e80ae77ab745e8f68e (diff)
A new search session is now forgetful by default
The old incremental search behaviour can still be used using the new -is|-incremental_search parameter.
-rw-r--r--smenu.111
-rw-r--r--smenu.c132
-rw-r--r--smenu.h8
-rw-r--r--usage.c3
4 files changed, 108 insertions, 46 deletions
diff --git a/smenu.1 b/smenu.1
index dfd5d33..8ebb194 100644
--- a/smenu.1
+++ b/smenu.1
@@ -57,6 +57,7 @@ and outputs the selection to stdout.
[\fB-X\fP|\fB-htmout\fP|\fB-hidden_timeout\fP \fItype\fP [\fIword\fP] \
\fIdelay\fP]
[\fB-r\fP|\fB-auto_validate\fP]
+ [\fB-is\fP|\fB-incremental_search\fP]
[\fB-v\fP|\fB-vb\fP|\fB-visual_bell\fP]
[\fB-Q\fP|\fB-ignore_quotes\fP]
@@ -1503,6 +1504,16 @@ is displayed above the selection window.
(Allowed in all contexts.)
Enables \fBENTER\fP to validate the selection even in search mode.
+.IP "\fB-is\fP|\fB-incremental_search\fP"
+(Allowed in all contexts.)
+
+By default, when a new search session is initiated, the current search
+buffer is reset.
+When this parameter is set, the next search will start where the last
+search ended, except if \fBESC\fP was hit before.
+
+This option instructs not to clean the previous search buffer each time
+a new search session is started.
.IP "\fB-v\fP|\fB-vb\fP|\fB-visual_bell\fP"
(Allowed in all contexts.)
diff --git a/smenu.c b/smenu.c
index 06b0c3e..82adfbf 100644
--- a/smenu.c
+++ b/smenu.c
@@ -4923,6 +4923,7 @@ init_main_ds(attrib_t * init_attr, win_t * win, limit_t * limits,
toggles->autotag = 0;
toggles->pinable = 0;
toggles->visual_bell = 0;
+ toggles->incremental_search = 0;
/* Misc default values. */
/* """""""""""""""""""" */
@@ -5159,6 +5160,8 @@ toggle_action(char * ctx_name, char * opt_name, char * param, int nb_values,
toggles->no_scrollbar = 1;
else if (strcmp(opt_name, "auto_tag") == 0)
toggles->autotag = 1;
+ else if (strcmp(opt_name, "incremental_search") == 0)
+ toggles->incremental_search = 1;
}
void
@@ -5977,6 +5980,53 @@ ignore_quotes_action(char * ctx_name, char * opt_name, char * param,
misc->ignore_quotes = 1;
}
+/* =================================================================== */
+/* Cancels a search. Called when ESC is hit or a new search session is */
+/* initiated and the incremental_search option is not used. */
+/* =================================================================== */
+void
+reset_search_buffer(win_t * win, search_data_t * search_data, ticker_t * timers,
+ toggle_t * toggles, term_t * term, daccess_t * daccess,
+ langinfo_t * langinfo, long last_line, char * tmp_word,
+ long word_real_max_size)
+{
+ long nl;
+
+ /* ESC key has been pressed. */
+ /* """"""""""""""""""""""""" */
+ search_mode_t old_search_mode = search_mode;
+
+ /* Cancel the search timer. */
+ /* """""""""""""""""""""""" */
+ search_timer = 0;
+
+ search_data->fuzzy_err = 0;
+ search_data->only_starting = 0;
+ search_data->only_ending = 0;
+
+ if (help_mode)
+ nl = disp_lines(win, toggles, current, count, search_mode, search_data,
+ term, last_line, tmp_word, langinfo);
+
+ /* Reset the direct access selector stack. */
+ /* """"""""""""""""""""""""""""""""""""""" */
+ memset(daccess_stack, '\0', 6);
+ daccess_stack_head = 0;
+ daccess_timer = timers->direct_access;
+
+ /* Clean the potential matching words non empty list. */
+ /* """""""""""""""""""""""""""""""""""""""""""""""""" */
+ search_mode = NONE;
+
+ if (matches_count > 0 || old_search_mode != search_mode)
+ {
+ clean_matches(search_data, word_real_max_size);
+
+ nl = disp_lines(win, toggles, current, count, search_mode, search_data,
+ term, last_line, tmp_word, langinfo);
+ }
+}
+
/* ================= */
/* Main entry point. */
/* ================= */
@@ -6524,7 +6574,8 @@ main(int argc, char * argv[])
"[hidden_timeout #...] "
"[validate_in_search_mode] "
"[visual_bell] "
- "[ignore_quotes] "; /* Do not remove the last space. */
+ "[ignore_quotes] "
+ "[incremental_search] "; /* Do not remove the last space. */
main_spec_options = "[*version] "
"[*long_help] "
@@ -6670,6 +6721,8 @@ main(int argc, char * argv[])
"-r -auto_validate");
ctxopt_add_opt_settings(parameters, "visual_bell", "-v -vb -visual_bell");
ctxopt_add_opt_settings(parameters, "ignore_quotes", "-Q -ignore_quotes");
+ ctxopt_add_opt_settings(parameters, "incremental_search",
+ "-is -incremental_search");
/* ctxopt options incompatibilities. */
/* """"""""""""""""""""""""""""""""" */
@@ -6745,6 +6798,8 @@ main(int argc, char * argv[])
ctxopt_add_opt_settings(actions, "version", version_action, (char *)0);
ctxopt_add_opt_settings(actions, "visual_bell", toggle_action, &toggles,
(char *)0);
+ ctxopt_add_opt_settings(actions, "incremental_search", toggle_action,
+ &toggles, (char *)0);
ctxopt_add_opt_settings(actions, "wide_mode", wide_mode_action, &win,
(char *)0);
ctxopt_add_opt_settings(actions, "post_subst_all", post_subst_action,
@@ -9693,39 +9748,9 @@ main(int argc, char * argv[])
{
/* ESC key has been pressed. */
/* """"""""""""""""""""""""" */
- search_mode_t old_search_mode = search_mode;
-
- /* Cancel the search timer. */
- /* """""""""""""""""""""""" */
- search_timer = 0;
-
- search_data.fuzzy_err = 0;
- search_data.only_starting = 0;
- search_data.only_ending = 0;
-
- if (help_mode)
- nl = disp_lines(&win, &toggles, current, count, search_mode,
- &search_data, &term, last_line, tmp_word,
- &langinfo);
-
- /* Reset the direct access selector stack. */
- /* """"""""""""""""""""""""""""""""""""""" */
- memset(daccess_stack, '\0', 6);
- daccess_stack_head = 0;
- daccess_timer = timers.direct_access;
-
- /* Clean the potential matching words non empty list. */
- /* """""""""""""""""""""""""""""""""""""""""""""""""" */
- search_mode = NONE;
-
- if (matches_count > 0 || old_search_mode != search_mode)
- {
- clean_matches(&search_data, word_real_max_size);
-
- nl = disp_lines(&win, &toggles, current, count, search_mode,
- &search_data, &term, last_line, tmp_word,
- &langinfo);
- }
+ reset_search_buffer(&win, &search_data, &timers, &toggles, &term,
+ &daccess, &langinfo, last_line, tmp_word,
+ word_real_max_size);
break;
}
@@ -10426,12 +10451,17 @@ main(int argc, char * argv[])
/* """""""""""""""""""""""""""""""""" */
fuzzy_method:
- /* Set the search timer. */
- /* """"""""""""""""""""" */
- search_timer = timers.search; /* default 10 s. */
-
if (search_mode == NONE)
{
+ if (!toggles.incremental_search)
+ reset_search_buffer(&win, &search_data, &timers, &toggles, &term,
+ &daccess, &langinfo, last_line, tmp_word,
+ word_real_max_size);
+
+ /* Set the search timer. */
+ /* """"""""""""""""""""" */
+ search_timer = timers.search; /* default 10 s. */
+
search_mode = FUZZY;
if (old_search_mode != FUZZY)
@@ -10456,12 +10486,17 @@ main(int argc, char * argv[])
/* """""""""""""""""""""""""""""""""""""" */
substring_method:
- /* Set the search timer. */
- /* """"""""""""""""""""" */
- search_timer = timers.search; /* default 10 s. */
-
if (search_mode == NONE)
{
+ if (!toggles.incremental_search)
+ reset_search_buffer(&win, &search_data, &timers, &toggles, &term,
+ &daccess, &langinfo, last_line, tmp_word,
+ word_real_max_size);
+
+ /* Set the search timer. */
+ /* """"""""""""""""""""" */
+ search_timer = timers.search; /* default 10 s. */
+
search_mode = SUBSTRING;
if (old_search_mode != SUBSTRING)
@@ -10486,12 +10521,17 @@ main(int argc, char * argv[])
/* """"""""""""""""""""""""""""""""""" */
prefix_method:
- /* Set the search timer. */
- /* """"""""""""""""""""" */
- search_timer = timers.search; /* default 10 s. */
-
if (search_mode == NONE)
{
+ if (!toggles.incremental_search)
+ reset_search_buffer(&win, &search_data, &timers, &toggles, &term,
+ &daccess, &langinfo, last_line, tmp_word,
+ word_real_max_size);
+
+ /* Set the search timer. */
+ /* """"""""""""""""""""" */
+ search_timer = timers.search; /* default 10 s. */
+
search_mode = PREFIX;
if (old_search_mode != PREFIX)
diff --git a/smenu.h b/smenu.h
index 6433c97..f0448cb 100644
--- a/smenu.h
+++ b/smenu.h
@@ -161,6 +161,8 @@ struct toggle_s
* not and we do no want an automatic tagging *
* when the users presses <ENTER> */
int visual_bell; /* 1 to flash the window, 0 to make a sound */
+ int incremental_search; /* 1 makes the searching process incremental. *
+ * 0 keeps it forgetful. */
};
/* Structure to store the default or imposed smenu limits */
@@ -610,4 +612,10 @@ void
init_main_ds(attrib_t * init_attr, win_t * win, limit_t * limits,
ticker_t * timers, toggle_t * toggles, misc_t * misc,
timeout_t * timeout, daccess_t * daccess);
+
+void
+reset_search_buffer(win_t * win, search_data_t * search_data, ticker_t * timers,
+ toggle_t * toggles, term_t * term, daccess_t * daccess,
+ langinfo_t * langinfo, long last_line, char * tmp_word,
+ long word_real_max_size);
#endif
diff --git a/usage.c b/usage.c
index 13905a0..546a709 100644
--- a/usage.c
+++ b/usage.c
@@ -74,6 +74,9 @@ common_help(void)
printf(" sets a timeout and specifies what to do when it expires.\n");
printf("-r|-auto_validate\n");
printf(" enables ENTER to validate the selection even in search mode.\n");
+ printf("-is|-incremental_search\n");
+ printf(" the search buffer is not reset when starting a new search "
+ "session.\n");
printf("-v|-vb|-visual_bell\n");
printf(" makes the bell visual (fuzzy search with error).\n");
printf("-Q|-ignore_quotes\n");