commit 4990f74f8395174a50ca269ad12dbdf646ab7924
parent 8ffc33cd891a9008a70185f736b074e06b5044a3
Author: Benno Schulenberg <bensberg@justemail.net>
Date: Sun, 26 Jul 2015 09:23:24 +0000
Adding two new bindable functions that repeat the last search command
in a fixed direction without prompting.
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5320 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
Diffstat:
6 files changed, 59 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -1,6 +1,10 @@
2015-07-26 Benno Schulenberg <bensberg@justemail.net>
* src/search.c (do_replace_loop): When doing regex replacements, find
- each zero-length match only once. This fixes Savannah bug #45626.
+ each zero-length match only once. This fixes Savannah bug #45626.
+ * src/global.c (shortcut_init, strtosc), src/search.c (do_findnext,
+ do_findprevious), doc/man/nanorc.5, doc/texinfo/nano.texi: Add two
+ new bindable functions, 'findnext' and 'findprevious', which repeat
+ the last search command in a fixed direction without prompting.
2015-07-25 Benno Schulenberg <bensberg@justemail.net>
* src/global.c (shortcut_init, strtosc), src/files.c (savefile),
diff --git a/doc/man/nanorc.5 b/doc/man/nanorc.5
@@ -394,7 +394,13 @@ Searches for text in the current buffer -- or for filenames matching
a string in the current list in the file browser.
.TP
.B searchagain
-Repeats the last search command.
+Repeats the last search command without prompting.
+.TP
+.B findprevious
+As \fBsearchagain\fR, but always in the backward direction.
+.TP
+.B findnext
+As \fBsearchagain\fR, but always in the forward direction.
.TP
.B replace
Interactively replaces text within the current buffer.
diff --git a/doc/texinfo/nano.texi b/doc/texinfo/nano.texi
@@ -964,7 +964,13 @@ Searches for text in the current buffer --- or for filenames matching
a string in the current list in the file browser
@item searchagain
-Repeats the last search command.
+Repeats the last search command without prompting.
+
+@item findprevious
+As @code{searchagain}, but always in the backward direction.
+
+@item findnext
+As @code{searchagain}, but always in the forward direction.
@item replace
Interactively replaces text within the current buffer.
diff --git a/src/global.c b/src/global.c
@@ -602,6 +602,8 @@ void shortcut_init(void)
N_("Suspend the editor (if suspend is enabled)");
#ifndef NANO_TINY
const char *nano_savefile_msg = N_("Save file without prompting");
+ const char *nano_findprev_msg = N_("Search next occurrence backward");
+ const char *nano_findnext_msg = N_("Search next occurrence forward");
const char *nano_case_msg =
N_("Toggle the case sensitivity of the search");
const char *nano_reverse_msg =
@@ -915,6 +917,11 @@ void shortcut_init(void)
#ifndef NANO_TINY
add_to_funcs(do_savefile, MMAIN,
N_("Save"), IFSCHELP(nano_savefile_msg), BLANKAFTER, NOVIEW);
+
+ add_to_funcs(do_findprevious, MMAIN,
+ N_("Previous"), IFSCHELP(nano_findprev_msg), TOGETHER, VIEW);
+ add_to_funcs(do_findnext, MMAIN,
+ N_("Next"), IFSCHELP(nano_findnext_msg), BLANKAFTER, VIEW);
#endif
#ifndef DISABLE_HISTORIES
@@ -1317,6 +1324,10 @@ sc *strtosc(char *input)
else if (!strcasecmp(input, "searchagain") ||
!strcasecmp(input, "research"))
s->scfunc = do_research;
+ else if (!strcasecmp(input, "findprevious"))
+ s->scfunc = do_findprevious;
+ else if (!strcasecmp(input, "findnext"))
+ s->scfunc = do_findnext;
#endif
else if (!strcasecmp(input, "replace"))
s->scfunc = do_replace;
diff --git a/src/proto.h b/src/proto.h
@@ -591,6 +591,10 @@ bool findnextstr(
const char *needle, size_t *needle_len);
void findnextstr_wrap_reset(void);
void do_search(void);
+#ifndef NANO_TINY
+void do_findprevious(void);
+void do_findnext(void);
+#endif
#if !defined(NANO_TINY) || !defined(DISABLE_BROWSER)
void do_research(void);
#endif
diff --git a/src/search.c b/src/search.c
@@ -474,6 +474,31 @@ void do_search(void)
search_replace_abort();
}
+#ifndef NANO_TINY
+/* Search in the backward direction for the next occurrence. */
+void do_findprevious(void)
+{
+ if ISSET(BACKWARDS_SEARCH)
+ do_research();
+ else {
+ SET(BACKWARDS_SEARCH);
+ do_research();
+ UNSET(BACKWARDS_SEARCH);
+ }
+}
+
+/* Search in the forward direction for the next occurrence. */
+void do_findnext(void)
+{
+ if ISSET(BACKWARDS_SEARCH) {
+ UNSET(BACKWARDS_SEARCH);
+ do_research();
+ SET(BACKWARDS_SEARCH);
+ } else
+ do_research();
+}
+#endif
+
#if !defined(NANO_TINY) || !defined(DISABLE_BROWSER)
/* Search for the last string without prompting. */
void do_research(void)