From baf1e854312c7d78f2dbe1b353808386b62d2c7d Mon Sep 17 00:00:00 2001 From: Rishabh Dave Date: Sun, 4 Sep 2016 21:29:14 +0530 Subject: [PATCH] feature: make rebinding Ctrl-arrow key possible Since ctrl-arrow key combinations are already recognized, make them reassginable too. This make them rebindable, making editor more flexible. This fulfills http://savannah.gnu.org/bugs/?44688 Signed-off-by: Rishabh Dave --- doc/syntax/nanorc.nanorc | 4 ++-- src/global.c | 17 ++++++++++++++++- src/winio.c | 16 ++++++++-------- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/doc/syntax/nanorc.nanorc b/doc/syntax/nanorc.nanorc index 3d2e353..2c072b9 100644 --- a/doc/syntax/nanorc.nanorc +++ b/doc/syntax/nanorc.nanorc @@ -10,8 +10,8 @@ icolor brightred "^[[:space:]]*((un)?(bind|set)|include|syntax|header|comment|ma icolor brightgreen "^[[:space:]]*(set|unset)[[:space:]]+(allow_insecure_backup|autoindent|backup|backwards|boldtext|casesensitive|const(antshow)?|cut|fill|historylog|justifytrim|locking|morespace|mouse|multibuffer|noconvert|nohelp|nonewlines|nowrap|pos(ition)?log|preserve|quickblank|quiet|rebinddelete|rebindkeypad|regexp|smarthome|smooth|softwrap|suspend|tabsize|tabstospaces|tempfile|unix|view|wordbounds)\>" icolor yellow "^[[:space:]]*set[[:space:]]+(functioncolor|keycolor|statuscolor|titlecolor)[[:space:]]+(bright)?(white|black|red|blue|green|yellow|magenta|cyan)?(,(white|black|red|blue|green|yellow|magenta|cyan))?\>" icolor brightgreen "^[[:space:]]*set[[:space:]]+(backupdir|brackets|functioncolor|keycolor|matchbrackets|operatingdir|punct|quotestr|speller|statuscolor|titlecolor|whitespace)[[:space:]]+" -icolor brightgreen "^[[:space:]]*bind[[:space:]]+((\^|M-)([[:alpha:]]|space|[]]|[0-9^_=+{}|;:'\",./<>\?-])|F([1-9]|1[0-6])|Ins|Del)[[:space:]]+[[:alpha:]]+[[:space:]]+(all|main|search|replace(2|with)?|gotoline|writeout|insert|ext(ernal)?cmd|help|spell|linter|browser|whereisfile|gotodir)([[:space:]]+#|[[:space:]]*$)" -icolor brightgreen "^[[:space:]]*unbind[[:space:]]+((\^|M-)([[:alpha:]]|space|[]]|[0-9^_=+{}|;:'\",./<>\?-])|F([1-9]|1[0-6])|Ins|Del)[[:space:]]+(all|main|search|replace(2|with)?|gotoline|writeout|insert|ext(ernal)?cmd|help|spell|linter|browser|whereisfile|gotodir)([[:space:]]+#|[[:space:]]*$)" +icolor brightgreen "^[[:space:]]*bind[[:space:]]+((\^(Up|Down|Right|Left))|(\^|M-)([[:alpha:]]|Space|[]]|[0-9^_=+{}|;:'\",./<>\?-])|F([1-9]|1[0-6])|Ins|Del)[[:space:]]+[[:alpha:]]+[[:space:]]+(all|main|search|replace(2|with)?|gotoline|writeout|insert|ext(ernal)?cmd|help|spell|linter|browser|whereisfile|gotodir)([[:space:]]+#|[[:space:]]*$)" +icolor brightgreen "^[[:space:]]*unbind[[:space:]]+((\^(Up|Down|Right|Left))|(\^|M-)([[:alpha:]]|Space|[]]|[0-9^_=+{}|;:'\",./<>\?-])|F([1-9]|1[0-6])|Ins|Del)[[:space:]]+(all|main|search|replace(2|with)?|gotoline|writeout|insert|ext(ernal)?cmd|help|spell|linter|browser|whereisfile|gotodir)([[:space:]]+#|[[:space:]]*$)" icolor brightgreen "^[[:space:]]*extendsyntax[[:space:]]+[[:alpha:]]+[[:space:]]+(i?color|header|magic|comment|linter|formatter)[[:space:]]+.*$" icolor green "^[[:space:]]*((un)?(bind|set)|include|syntax|header|magic|comment|linter|formatter|extendsyntax)\>" diff --git a/src/global.c b/src/global.c index 11f4e2a..fb9736f 100644 --- a/src/global.c +++ b/src/global.c @@ -411,9 +411,20 @@ void assign_keyinfo(sc *s, const char *keystring) assert(strlen(keystring) > 1 && (!s->meta || strlen(keystring) > 2)); if (keystring[0] == '^') { - s->keycode = keystring[1] - 64; if (strcasecmp(keystring, "^Space") == 0) s->keycode = 0; +#ifndef NANO_TINY + else if (!strcasecmp(keystring, "^Up")) + s->keycode = CONTROL_UP; + else if (!strcasecmp(keystring, "^Down")) + s->keycode = CONTROL_DOWN; + else if (!strcasecmp(keystring, "^Left")) + s->keycode = CONTROL_LEFT; + else if (!strcasecmp(keystring, "^Right")) + s->keycode = CONTROL_RIGHT; +#endif + else + s->keycode = keystring[1] - 64; } else if (s->meta) { s->keycode = tolower((int)keystring[2]); if (strcasecmp(keystring, "M-Space") == 0) @@ -1120,7 +1131,9 @@ void shortcut_init(void) add_to_sclist(MMOST, "^F", do_right, 0); add_to_sclist(MMOST, "Right", do_right, 0); #ifndef NANO_TINY + add_to_sclist(MMOST, "^Left", do_prev_word_void, 0); add_to_sclist(MMOST, "M-Space", do_prev_word_void, 0); + add_to_sclist(MMOST, "^Right", do_next_word_void, 0); add_to_sclist(MMOST, "^Space", do_next_word_void, 0); #endif add_to_sclist((MMOST & ~MBROWSER), "^A", do_home, 0); @@ -1132,7 +1145,9 @@ void shortcut_init(void) add_to_sclist(MMAIN|MHELP|MBROWSER, "^N", do_down_void, 0); add_to_sclist(MMAIN|MHELP|MBROWSER, "Down", do_down_void, 0); #ifndef NANO_TINY + add_to_sclist(MMAIN, "^Up", do_prev_block, 0); add_to_sclist(MMAIN, "M-7", do_prev_block, 0); + add_to_sclist(MMAIN, "^Down", do_next_block, 0); add_to_sclist(MMAIN, "M-8", do_next_block, 0); #endif #ifndef DISABLE_JUSTIFY diff --git a/src/winio.c b/src/winio.c index 0784539..f6aba22 100644 --- a/src/winio.c +++ b/src/winio.c @@ -502,13 +502,13 @@ int parse_kbinput(WINDOW *win) #ifndef NANO_TINY if (retval == controlleft) - return sc_seq_or(do_prev_word_void, 0); + return CONTROL_LEFT; else if (retval == controlright) - return sc_seq_or(do_next_word_void, 0); + return CONTROL_RIGHT; else if (retval == controlup) - return sc_seq_or(do_prev_block, 0); + return CONTROL_UP; else if (retval == controldown) - return sc_seq_or(do_next_block, 0); + return CONTROL_DOWN; else if (retval == shiftcontrolleft) { shift_held = TRUE; return sc_seq_or(do_prev_word_void, 0); @@ -548,13 +548,13 @@ int parse_kbinput(WINDOW *win) /* Is Ctrl being held? */ if (modifiers & 0x04) { if (retval == KEY_UP) - return sc_seq_or(do_prev_block, 0); + return CONTROL_UP; else if (retval == KEY_DOWN) - return sc_seq_or(do_next_block, 0); + return CONTROL_DOWN; else if (retval == KEY_LEFT) - return sc_seq_or(do_prev_word_void, 0); + return CONTROL_LEFT; else if (retval == KEY_RIGHT) - return sc_seq_or(do_next_word_void, 0); + return CONTROL_RIGHT; } /* Are both Shift and Alt being held? */ -- 2.7.4