From 786525415ddd3321aff491effd941ce7017a0ee4 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg 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