aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--TODO5
-rw-r--r--src/core-commands.c3
-rw-r--r--src/search.c33
-rw-r--r--src/search.h4
-rw-r--r--tests/testsuite.at2
5 files changed, 41 insertions, 6 deletions
diff --git a/TODO b/TODO
index ea7b36d..9a353eb 100644
--- a/TODO
+++ b/TODO
@@ -324,10 +324,7 @@ Features:
(request of N.M.).
Could be called <_> (a global-search variant in classic TECO).
* Shortcut for cutting into Q-Register. Typing 10Xq10K is very
- annoying to type. We could use the @ modifier 10@Xq or
- define a new command, like ^X (search-mode flag in classic
- TECO). On the other hand, a search mode setting would be
- useful in SciTECO as well!
+ annoying to type. We could use the @ modifier 10@Xq.
FX would be available as well, but is perhaps best reserved
for some mmenonics.
An elegant alternative might be to introduce single-character
diff --git a/src/core-commands.c b/src/core-commands.c
index 27f5c64..ca0245b 100644
--- a/src/core-commands.c
+++ b/src/core-commands.c
@@ -1835,7 +1835,8 @@ teco_state_control_input(teco_machine_main_t *ctx, gunichar chr, GError **error)
['O'] = {&teco_state_start, teco_state_control_octal},
['D'] = {&teco_state_start, teco_state_control_decimal},
['R'] = {&teco_state_start, teco_state_control_radix},
- ['E'] = {&teco_state_start, teco_state_control_glyphs2bytes}
+ ['E'] = {&teco_state_start, teco_state_control_glyphs2bytes},
+ ['X'] = {&teco_state_start, teco_state_control_search_mode}
};
/*
diff --git a/src/search.c b/src/search.c
index 07a5154..ec62d02 100644
--- a/src/search.c
+++ b/src/search.c
@@ -52,6 +52,34 @@ TECO_DEFINE_UNDO_OBJECT_OWN(parameters, teco_search_parameters_t, /* don't delet
*/
static teco_search_parameters_t teco_search_parameters;
+static teco_bool_t teco_search_mode = TECO_FAILURE; /* case-insensitive */
+
+/*$ ^X search-mode
+ * mode^X -- Set or get search mode flag
+ * -^X
+ * ^X -> mode
+ *
+ * The search mode is interpreted as a TECO boolean.
+ * A true value (smaller than zero) configures case-sensitive searches,
+ * while a false value (larger than or equal to zero) configures case-insensitive
+ * searches.
+ * "-^X" is equivalent to "-1^X" and also enables case-sensitive searches.
+ * Searches are case-insensitive by default.
+ */
+void
+teco_state_control_search_mode(teco_machine_main_t *ctx, GError **error)
+{
+ if (!teco_expressions_eval(FALSE, error))
+ return;
+ if (!teco_expressions_args() && teco_num_sign > 0) {
+ teco_expressions_push(teco_search_mode);
+ } else {
+ teco_undo_int(teco_search_mode);
+ if (!teco_expressions_pop_num_calc(&teco_search_mode, teco_num_sign, error))
+ return;
+ }
+}
+
static gboolean
teco_state_search_initial(teco_machine_main_t *ctx, GError **error)
{
@@ -599,7 +627,10 @@ static gboolean
teco_state_search_process(teco_machine_main_t *ctx, const teco_string_t *str, gsize new_chars, GError **error)
{
/* FIXME: Should G_REGEX_OPTIMIZE be added under certain circumstances? */
- GRegexCompileFlags flags = G_REGEX_CASELESS | G_REGEX_MULTILINE | G_REGEX_DOTALL;
+ GRegexCompileFlags flags = G_REGEX_MULTILINE | G_REGEX_DOTALL;
+
+ if (teco_is_failure(teco_search_mode))
+ flags |= G_REGEX_CASELESS;
/* this is set in teco_state_search_initial() */
if (ctx->expectstring.machine.codepage != SC_CP_UTF8) {
diff --git a/src/search.h b/src/search.h
index 3eacb6d..40ab4d8 100644
--- a/src/search.h
+++ b/src/search.h
@@ -16,8 +16,12 @@
*/
#pragma once
+#include <glib.h>
+
#include "parser.h"
+void teco_state_control_search_mode(teco_machine_main_t *ctx, GError **error);
+
TECO_DECLARE_STATE(teco_state_search);
TECO_DECLARE_STATE(teco_state_search_all);
TECO_DECLARE_STATE(teco_state_search_kill);
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 4bd4cfe..e7d50da 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -95,6 +95,8 @@ AT_SETUP([Searches])
# You also cannot search for a single ASCII 5 using Caret+E.
# 2 additional ^Q are translated to a single ^Q and interpreted at the search-pattern layer.
AT_CHECK([$SCITECO -e "@I/^Q\05/ J @:S/^Q^Q^Q\05/\"F(0/0)'"], 0, ignore, ignore)
+# Canse-sensitive search
+AT_CHECK([$SCITECO -e "@I/XXX/J -^X @:S/xxx/\"S(0/0)'"], 0, ignore, ignore)
AT_CLEANUP
AT_SETUP([Editing local registers in macro calls])