new feature: option --modernbindings sets up more widespread key bindings

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

Note that with --modernbindings ^Q and ^S are always bound, meaning that
--preserve / 'set preserve' is ignored.  This is necessary because ^Q is
an essential keystroke in the modern bindings.

Also note that these "modern bindings" are effective only in the main
edit window, not in the various menus.  In all menus ^C means Cancel,
and I can't think of a good alternative default keystroke for that
(in order for ^C to mean Copy).  And in a few menus ^V has a meaning,
and there is no good alternative for that either.  So... in the menus
the user has to use M-6 for Copy and ^U for Paste (and ^K for Erase --
Cut does not exist in the menus), like with the default bindings.
This commit is contained in:
Benno Schulenberg 2023-02-17 12:34:04 +01:00
parent 64ac4610de
commit 18b37c980a
3 changed files with 42 additions and 15 deletions

View File

@ -374,7 +374,8 @@ enum {
STATEFLAGS,
USE_MAGIC,
MINIBAR,
ZERO
ZERO,
MODERN_BINDINGS
};
/* Structure types. */

View File

@ -1171,33 +1171,61 @@ 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(MODERN_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, "^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, "^T", 0, do_gotolinecolumn, 0);
add_to_sclist(MMAIN, "^P", 0, report_cursor_position, 0);
#ifndef NANO_TINY
add_to_sclist(MMAIN, "^Z", 0, do_undo, 0);
add_to_sclist(MMAIN, "^Y", 0, do_redo, 0);
add_to_sclist(MMAIN, "^A", 0, do_mark, 0);
add_to_sclist(MMAIN, "^C", 0, copy_text, 0);
#endif
add_to_sclist(MMAIN, "^X", 0, cut_text, 0);
add_to_sclist(MMAIN, "^V", 0, paste_text, 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);
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);
add_to_sclist(MMOST, "^A", 0, do_home, 0);
add_to_sclist(MMOST, "^E", 0, do_end, 0);
add_to_sclist(MMAIN|MBROWSER|MHELP, "^P", 0, do_up, 0);
add_to_sclist(MMAIN|MBROWSER|MHELP, "^N", 0, do_down, 0);
add_to_sclist(MMAIN|MBROWSER|MHELP|MLINTER, "^Y", 0, do_page_up, 0);
add_to_sclist(MMAIN|MBROWSER|MHELP|MLINTER, "^V", 0, do_page_down, 0);
add_to_sclist(MMAIN, "^C", 0, report_cursor_position, 0);
add_to_sclist(MMOST, "^D", 0, do_delete, 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);
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);
#ifdef NANO_TINY
add_to_sclist(MMAIN, "^U", 0, paste_text, 0);
#ifdef ENABLE_SPELLER
add_to_sclist(MMAIN, "^T", 0, do_spell, 0);
add_to_sclist(MMAIN, ISSET(MODERN_BINDINGS) ? "^E" : "^T", 0, do_spell, 0);
#endif
#else
add_to_sclist(MMOST, "^U", 0, paste_text, 0);
add_to_sclist(MMAIN, "^T", 0, do_execute, 0);
add_to_sclist(MMAIN, ISSET(MODERN_BINDINGS) ? "^E" : "^T", 0, do_execute, 0);
#ifdef ENABLE_SPELLER
if (!ISSET(PRESERVE))
add_to_sclist(MEXECUTE, "^S", 0, do_spell, 0);
@ -1213,13 +1241,10 @@ void shortcut_init(void)
#ifdef ENABLE_FORMATTER
add_to_sclist(MEXECUTE, "^O", 0, do_formatter, 0);
#endif
add_to_sclist(MMAIN, "^C", 0, report_cursor_position, 0);
add_to_sclist(MMAIN, SLASH_OR_DASH, 0, do_gotolinecolumn, 0);
add_to_sclist(MMAIN, "M-G", 0, do_gotolinecolumn, 0);
add_to_sclist(MMAIN, "^_", 0, do_gotolinecolumn, 0);
add_to_sclist(MMAIN|MBROWSER|MHELP|MLINTER, "^Y", 0, do_page_up, 0);
add_to_sclist(MMAIN|MBROWSER|MHELP|MLINTER, "PgUp", KEY_PPAGE, do_page_up, 0);
add_to_sclist(MMAIN|MBROWSER|MHELP|MLINTER, "^V", 0, do_page_down, 0);
add_to_sclist(MMAIN|MBROWSER|MHELP|MLINTER, "PgDn", KEY_NPAGE, do_page_down, 0);
add_to_sclist(MBROWSER|MHELP, "Bsp", KEY_BACKSPACE, do_page_up, 0);
add_to_sclist(MBROWSER|MHELP, "Sh-Del", SHIFT_DELETE, do_page_up, 0);
@ -1298,12 +1323,8 @@ void shortcut_init(void)
}
add_to_sclist(MMOST, "M-Space", 0, to_prev_word, 0);
add_to_sclist(MMOST, "^Space", 0, to_next_word, 0);
add_to_sclist(MMOST, "^A", 0, do_home, 0);
add_to_sclist(MMOST, "Home", KEY_HOME, do_home, 0);
add_to_sclist(MMOST, "^E", 0, do_end, 0);
add_to_sclist(MMOST, "End", KEY_END, do_end, 0);
add_to_sclist(MMAIN|MBROWSER|MHELP, "^P", 0, do_up, 0);
add_to_sclist(MMAIN|MBROWSER|MHELP, "^N", 0, do_down, 0);
#ifdef ENABLE_UTF8
if (using_utf8()) {
add_to_sclist(MMAIN|MBROWSER|MHELP, "\xE2\x96\xb4", KEY_UP, do_up, 0);

View File

@ -660,6 +660,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("-/", "--modernbindings", N_("Use better-known key bindings"));
}
/* Display the version number of this nano, a copyright notice, some contact
@ -1778,6 +1779,7 @@ int main(int argc, char **argv)
{"nowrap", 0, NULL, 'w'},
#endif
{"nohelp", 0, NULL, 'x'},
{"modernbindings", 0, NULL, '/'},
#ifndef NANO_TINY
{"smarthome", 0, NULL, 'A'},
{"backup", 0, NULL, 'B'},
@ -1853,7 +1855,7 @@ int main(int argc, char **argv)
SET(RESTRICTED);
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':
@ -2102,6 +2104,9 @@ int main(int argc, char **argv)
SET(ZERO);
break;
#endif
case '/':
SET(MODERN_BINDINGS);
break;
default:
printf(_("Type '%s -h' for a list of available options.\n"), argv[0]);
exit(1);