nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Nano-devel] [PATCH 1/2] new feature: a bindable function that starts al


From: Benno Schulenberg
Subject: [Nano-devel] [PATCH 1/2] new feature: a bindable function that starts always a backward search
Date: Sun, 24 Sep 2017 21:02:07 +0200

---
 doc/nano.texi |  7 +++++--
 doc/nanorc.5  |  7 +++++--
 src/global.c  |  9 ++++++++-
 src/proto.h   |  2 ++
 src/search.c  | 14 ++++++++++++++
 5 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/doc/nano.texi b/doc/nano.texi
index 026755ea..462d3a36 100644
--- a/doc/nano.texi
+++ b/doc/nano.texi
@@ -1087,8 +1087,11 @@ Inserts a file into the current buffer (at the current 
cursor position),
 or into a new buffer when option @code{multibuffer} is set.
 
 @item whereis
-Searches for text in the current buffer --- or for filenames matching
-a string in the current list in the file browser
+Starts a forward search for text in the current buffer --- or for filenames
+matching a string in the current list in the file browser.
+
address@hidden wherewas
+Starts a backward search for text in the current buffer.
 
 @item searchagain
 Repeats the last search command without prompting.
diff --git a/doc/nanorc.5 b/doc/nanorc.5
index 49a0d69a..cf0ec115 100644
--- a/doc/nanorc.5
+++ b/doc/nanorc.5
@@ -444,8 +444,11 @@ Inserts a file into the current buffer (at the current 
cursor position),
 or into a new buffer when option \fBmultibuffer\fR is set.
 .TP
 .B whereis
-Searches for text in the current buffer -- or for filenames matching
-a string in the current list in the file browser.
+Starts a forward search for text in the current buffer -- or for filenames
+matching a string in the current list in the file browser.
+.TP
+.B wherewas
+Starts a backward search for text in the current buffer.
 .TP
 .B searchagain
 Repeats the last search command without prompting.
diff --git a/src/global.c b/src/global.c
index 46633e38..2926403b 100644
--- a/src/global.c
+++ b/src/global.c
@@ -534,6 +534,8 @@ void shortcut_init(void)
        N_("Insert another file into the current one");
     const char *nano_whereis_msg =
        N_("Search for a string or a regular expression");
+    const char *nano_wherewas_msg =
+       N_("Search backward for a string or expression");
 #ifdef ENABLE_BROWSER
     const char *nano_browser_whereis_msg = N_("Search for a string");
     const char *nano_browser_refresh_msg = N_("Refresh the file list");
@@ -974,6 +976,9 @@ void shortcut_init(void)
        N_("Comment Lines"), IFSCHELP(nano_comment_msg), BLANKAFTER, NOVIEW);
 #endif
 #ifndef NANO_TINY
+    add_to_funcs(do_search_backward, MMAIN,
+       N_("Where Was"), IFSCHELP(N_(nano_wherewas_msg)), BLANKAFTER, VIEW);
+
     add_to_funcs(do_savefile, MMAIN,
        N_("Save"), IFSCHELP(nano_savefile_msg), BLANKAFTER, NOVIEW);
 #endif
@@ -1462,7 +1467,9 @@ sc *strtosc(const char *input)
     else if (!strcasecmp(input, "insert"))
        s->scfunc = do_insertfile_void;
     else if (!strcasecmp(input, "whereis"))
-       s->scfunc = do_search;
+       s->scfunc = do_search_forward;
+    else if (!strcasecmp(input, "wherewas"))
+       s->scfunc = do_search_backward;
     else if (!strcasecmp(input, "searchagain") ||
             !strcasecmp(input, "research"))  /* Deprecated.  Remove in 2018. */
        s->scfunc = do_research;
diff --git a/src/proto.h b/src/proto.h
index 71c12d40..41ad640c 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -502,6 +502,8 @@ void search_replace_abort(void);
 int findnextstr(const char *needle, bool whole_word_only, bool have_region,
        size_t *match_len, bool skipone, const filestruct *begin, size_t 
begin_x);
 void do_search(void);
+void do_search_forward(void);
+void do_search_backward(void);
 #ifndef NANO_TINY
 void do_findprevious(void);
 void do_findnext(void);
diff --git a/src/search.c b/src/search.c
index ea7b6b65..86a00f87 100644
--- a/src/search.c
+++ b/src/search.c
@@ -374,6 +374,20 @@ void do_search(void)
        go_looking();
 }
 
+/* Search forward for a string. */
+void do_search_forward(void)
+{
+    UNSET(BACKWARDS_SEARCH);
+    do_search();
+}
+
+/* Search backwards for a string. */
+void do_search_backward(void)
+{
+    SET(BACKWARDS_SEARCH);
+    do_search();
+}
+
 #ifndef NANO_TINY
 /* Search in the backward direction for the next occurrence. */
 void do_findprevious(void)
-- 
2.14.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]