revisiting ^F for Search

Benno Schulenberg <[email protected]>
Newsgroups gmane.editors.nano.devel
Message-ID <[email protected]>
Hi all,

Although no one offered me yet a remote login through the browser,
let's assume there is some demand for getting away from the default
^W for Search, even if it's just to avoid new users acquiring the
dangerous habit of typing ^W.

So... the first patch makes ^F an additional keystroke for starting
a forward search, sacrificing the step-one-character-forward keystroke.
As it does not make sense to have a step-backward Ctrl+letter keystroke
when there is no corresponding step-forward keystroke, the patch also
makes ^B start a backward search.  And as having M-W for find-next and
M-Q for find-previous are weird when ^F and ^B are used to start searches,
also M-F and M-B are reassigned to do find-next and find-previous.

But... when that patch is applied, probably soon someone will say: why
have ^Q for doing a backward search when ^B now already does that?
Why not make ^Q do Quit/Exit, freeing up ^X to do Cut?  Et cetera.

So, the second patch instead adds an option (--hipperkeys), that
changes nano's bindings to be more like what most people know from
modern desktop programs: ^Q for Quit, ^O for Open file, ^F for Find,
^Z for undo, and so on.

The second patch also makes it so that --hipperkeys is activated
when nano's binary starts with the letter "e".  This allows using
the newer bindings without having to pass any option by making a
one-time symlink to the nano binary.  For example:

   cd /usr/local/bin && sudo ln -s nano eta


(The second patch changes only the bindings in the edit window:
the main menu.  I haven't yet bothered to make the bindings in
all the submenus consistent/compatible with the main bindings.)


Thoughts?


Benno
control-F-for-Search.patch (text/x-patch, 3 KB)
From 6f1205aed94b76ef211db79b671ae9feab5de2ee Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <[email protected]>
Date: Thu, 16 Feb 2023 17:06:17 +0100
Subject: [PATCH] bindings: let ^F by default start a forward search

This makes nano more usable for users that are accustomed to the
near universal use of ^F for Find/Search in other programs.

To keep the bindings consistent, let ^B start a backward search, and
let M-F and M-B search for the next occurrence in that direction.
---
 src/global.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/global.c b/src/global.c
index ed93fa31..0b729697 100644
--- a/src/global.c
+++ b/src/global.c
@@ -1178,6 +1178,8 @@ void shortcut_init(void)
 	add_to_sclist(MMAIN, "^O", 0, do_writeout, 0);
 	add_to_sclist(MMAIN, "^R", 0, do_insertfile, 0);
 	add_to_sclist(MMAIN, "Ins", KEY_IC, do_insertfile, 0);
+	add_to_sclist(MMAIN|MBROWSER|MHELP, "^B", 0, do_search_backward,  0);
+	add_to_sclist(MMAIN|MBROWSER|MHELP, "^F", 0, do_search_forward, 0);
 	if (!ISSET(PRESERVE))
 		add_to_sclist(MMAIN|MBROWSER|MHELP, "^Q", 0, do_search_backward, 0);
 	add_to_sclist(MMAIN|MBROWSER|MHELP, "^W", 0, do_search_forward, 0);
@@ -1202,11 +1204,9 @@ void shortcut_init(void)
 	add_to_sclist(MMAIN, "^J", '\n', do_justify, 0);
 #endif
 #ifdef ENABLE_LINTER
-	add_to_sclist(MMAIN, "M-B", 0, do_linter, 0);
 	add_to_sclist(MEXECUTE, "^Y", 0, do_linter, 0);
 #endif
 #ifdef ENABLE_FORMATTER
-	add_to_sclist(MMAIN, "M-F", 0, do_formatter, 0);
 	add_to_sclist(MEXECUTE, "^O", 0, do_formatter, 0);
 #endif
 	add_to_sclist(MMAIN, "^C", 0, report_cursor_position, 0);
@@ -1224,17 +1224,17 @@ void shortcut_init(void)
 	add_to_sclist(MMAIN|MHELP, "^Home", CONTROL_HOME, to_first_line, 0);
 	add_to_sclist(MMAIN|MHELP, "M-/", 0, to_last_line, 0);
 	add_to_sclist(MMAIN|MHELP, "^End", CONTROL_END, to_last_line, 0);
+	add_to_sclist(MMAIN|MBROWSER|MHELP, "M-B", 0, do_findprevious, 0);
+	add_to_sclist(MMAIN|MBROWSER|MHELP, "M-F", 0, do_findnext, 0);
 	add_to_sclist(MMAIN|MBROWSER|MHELP, "M-W", 0, do_findnext, 0);
 	add_to_sclist(MMAIN|MBROWSER|MHELP, "M-Q", 0, do_findprevious, 0);
 #ifdef NANO_TINY
 #ifdef ENABLE_LINENUMBERS
 	add_to_sclist(MMAIN, "M-N", 0, toggle_numbers, 0);
 #else
-	add_to_sclist(MMAIN, "M-B", 0, to_prev_word, 0);
 	add_to_sclist(MMAIN, "M-N", 0, to_next_word, 0);
 #endif
 	add_to_sclist(MMAIN, "M-D", 0, to_prev_word, 0);
-	add_to_sclist(MMAIN, "M-F", 0, to_next_word, 0);
 #else
 	add_to_sclist(MMAIN, "M-]", 0, do_find_bracket, 0);
 	add_to_sclist(MMAIN, "M-A", 0, do_mark, 0);
@@ -1264,8 +1264,8 @@ void shortcut_init(void)
 #ifdef ENABLE_COMMENT
 	add_to_sclist(MMAIN, "M-3", 0, do_comment, 0);
 #endif
-	add_to_sclist(MMOST|MBROWSER, "^B", 0, do_left, 0);
-	add_to_sclist(MMOST|MBROWSER, "^F", 0, do_right, 0);
+	add_to_sclist(MMOST & ~MMAIN, "^B", 0, do_left, 0);
+	add_to_sclist(MMOST & ~MMAIN, "^F", 0, do_right, 0);
 #ifdef ENABLE_UTF8
 	if (using_utf8()) {
 		add_to_sclist(MMOST|MBROWSER|MHELP, "\xE2\x97\x82", KEY_LEFT, do_left, 0);
-- 
2.37.5
trendier-bindings-with--hipperkeys.patch (text/x-patch, 5.4 KB)
From 786525415ddd3321aff491effd941ce7017a0ee4 Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <[email protected]>
Date: Fri, 17 Feb 2023 12:34:04 +0100
Subject: [PATCH] new thing: option --hipperkeys activates more widespread key
 bindings

With --hipperkeys, ^Q quits, ^F finds, ^B finds backward, ^G finds again,
^D finds again backward, ^O opens a file, ^X cuts, ^C copies, ^V pastes,
^S saves, ^Z undoes, ^Y redoes, ^E executes, ^P shows the position, and
^T goes to a given line, and ^W writes out a file.

As ^H is hardbound to Backspace on some terminals, ^N is used for Help.

The hipper bindings are activated also when the name of the binary starts
with the letter "e".  This allows activating the trendy bindings without
having to pass an option, by simply invoking nano through a symlink like
'en' (short for "editor nano") or 'et' (short for "edit").
---
 src/definitions.h |  3 ++-
 src/global.c      | 26 ++++++++++++++++++++++++--
 src/nano.c        |  9 ++++++++-
 src/rcfile.c      |  1 +
 4 files changed, 35 insertions(+), 4 deletions(-)

diff --git a/src/definitions.h b/src/definitions.h
index 288f1ff9..ca10848e 100644
--- a/src/definitions.h
+++ b/src/definitions.h
@@ -371,7 +371,8 @@ enum {
 	STATEFLAGS,
 	USE_MAGIC,
 	MINIBAR,
-	ZERO
+	ZERO,
+	TRENDY_BINDINGS
 };
 
 /* Structure types. */
diff --git a/src/global.c b/src/global.c
index ed93fa31..c91d06c7 100644
--- a/src/global.c
+++ b/src/global.c
@@ -1167,20 +1167,42 @@ void shortcut_init(void)
 	add_to_sclist(MMOST, "^H", '\b', do_backspace, 0);
 	add_to_sclist(MMOST, "Bsp", KEY_BACKSPACE, do_backspace, 0);
 	add_to_sclist(MMOST, "Sh-Del", SHIFT_DELETE, do_backspace, 0);
-	add_to_sclist(MMOST, "^D", 0, do_delete, 0);
 	add_to_sclist(MMOST, "Del", KEY_DC, do_delete, 0);
 	add_to_sclist(MMOST, "^I", '\t', do_tab, 0);
 	add_to_sclist(MMOST, "Tab", '\t', do_tab, 0);
+	if (ISSET(TRENDY_BINDINGS)) {
+		add_to_sclist((MMOST|MBROWSER) & ~MFINDINHELP, "^N", 0, do_help, 0);
+		add_to_sclist(MMAIN|MBROWSER|MHELP, "^Q", 0, do_exit, 0);
+		add_to_sclist(MMAIN, "^S", 0, do_savefile, 0);
+		add_to_sclist(MMAIN, "^W", 0, do_writeout, 0);
+		add_to_sclist(MMAIN, "^O", 0, do_insertfile, 0);
+		add_to_sclist(MMAIN|MBROWSER|MHELP, "^B", 0, do_search_backward,  0);
+		add_to_sclist(MMAIN|MBROWSER|MHELP, "^F", 0, do_search_forward, 0);
+		add_to_sclist(MMAIN|MBROWSER|MHELP, "^D", 0, do_findprevious, 0);
+		add_to_sclist(MMAIN|MBROWSER|MHELP, "^G", 0, do_findnext, 0);
+		add_to_sclist(MMAIN, "^R", 0, do_replace, 0);
+		add_to_sclist(MMAIN, "^E", 0, do_execute, 0);
+		add_to_sclist(MMAIN, "^T", 0, do_gotolinecolumn, 0);
+		add_to_sclist(MMAIN, "^P", 0, report_cursor_position, 0);
+		add_to_sclist(MMAIN, "^A", 0, do_mark, 0);
+		add_to_sclist(MMAIN, "^X", 0, cut_text, 0);
+		add_to_sclist(MMAIN, "^C", 0, copy_text, 0);
+		add_to_sclist(MMOST, "^V", 0, paste_text, 0);
+		add_to_sclist(MMAIN, "^Z", 0, do_undo, 0);
+		add_to_sclist(MMAIN, "^Y", 0, do_redo, 0);
+	} else {
 	add_to_sclist((MMOST|MBROWSER) & ~MFINDINHELP, "^G", 0, do_help, 0);
 	add_to_sclist(MMAIN|MBROWSER|MHELP, "^X", 0, do_exit, 0);
 	if (!ISSET(PRESERVE))
 		add_to_sclist(MMAIN, "^S", 0, do_savefile, 0);
 	add_to_sclist(MMAIN, "^O", 0, do_writeout, 0);
 	add_to_sclist(MMAIN, "^R", 0, do_insertfile, 0);
-	add_to_sclist(MMAIN, "Ins", KEY_IC, do_insertfile, 0);
 	if (!ISSET(PRESERVE))
 		add_to_sclist(MMAIN|MBROWSER|MHELP, "^Q", 0, do_search_backward, 0);
 	add_to_sclist(MMAIN|MBROWSER|MHELP, "^W", 0, do_search_forward, 0);
+	add_to_sclist(MMOST, "^D", 0, do_delete, 0);
+	}
+	add_to_sclist(MMAIN, "Ins", KEY_IC, do_insertfile, 0);
 	add_to_sclist(MMAIN, "^\\", 0, do_replace, 0);
 	add_to_sclist(MMAIN, "M-R", 0, do_replace, 0);
 	add_to_sclist(MMOST, "^K", 0, cut_text, 0);
diff --git a/src/nano.c b/src/nano.c
index 4d5e7ea6..b4fe44d2 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -659,6 +659,7 @@ void usage(void)
 	print_opt("-_", "--minibar", N_("Show a feedback bar at the bottom"));
 	print_opt("-0", "--zero", N_("Hide all bars, use whole terminal"));
 #endif
+	print_opt("-/", "--hipperkeys", N_("Use better-known key bindings"));
 }
 
 /* Display the version number of this nano, a copyright notice, some contact
@@ -1774,6 +1775,7 @@ int main(int argc, char **argv)
 		{"nowrap", 0, NULL, 'w'},
 #endif
 		{"nohelp", 0, NULL, 'x'},
+		{"hipperkeys", 0, NULL, '/'},
 #ifndef NANO_TINY
 		{"smarthome", 0, NULL, 'A'},
 		{"backup", 0, NULL, 'B'},
@@ -1847,9 +1849,11 @@ int main(int argc, char **argv)
 	/* If the executable's name starts with 'r', activate restricted mode. */
 	if (*(tail(argv[0])) == 'r')
 		SET(RESTRICTED);
+	else if (*(tail(argv[0])) == 'e')
+		SET(TRENDY_BINDINGS);
 
 	while ((optchr = getopt_long(argc, argv, "ABC:DEFGHIJ:KLMNOPQ:RS$T:UVWX:Y:Z"
-				"abcdef:ghijklmno:pqr:s:tuvwxy!%_0", long_options, NULL)) != -1) {
+				"abcdef:ghijklmno:pqr:s:tuvwxy!%_0/", long_options, NULL)) != -1) {
 		switch (optchr) {
 #ifndef NANO_TINY
 			case 'A':
@@ -2098,6 +2102,9 @@ int main(int argc, char **argv)
 				SET(ZERO);
 				break;
 #endif
+			case '/':
+				SET(TRENDY_BINDINGS);
+				break;
 			default:
 				printf(_("Type '%s -h' for a list of available options.\n"), argv[0]);
 				exit(1);
diff --git a/src/rcfile.c b/src/rcfile.c
index c225a565..32ed69ce 100644
--- a/src/rcfile.c
+++ b/src/rcfile.c
@@ -51,6 +51,7 @@ static const rcoption rcopts[] = {
 #ifdef ENABLED_WRAPORJUSTIFY
 	{"fill", 0},
 #endif
+	{"hipperkeys", TRENDY_BINDINGS},
 #ifdef ENABLE_HISTORIES
 	{"historylog", HISTORYLOG},
 #endif
-- 
2.37.5
OpenPGP_signature (application/pgp-signature, 840 B) - not displayed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.