From e347efb9ff168f309fd2525a3c0d46283c14e588 Mon Sep 17 00:00:00 2001 From: Chris Allegretta Date: Sun, 9 Mar 2008 02:52:40 +0000 Subject: [PATCH] More keybinding fixes - Fix tiny mode compilation problems - Fix F-keys not working (silly typo) - Change file browser to use new backend - global.c - new helper function sc_seq_or, makes logic simpler down in the functions than calling first_sc_for directly git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4218 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- src/browser.c | 78 ++++++------- src/global.c | 300 ++++++++++++++++++++++++++++---------------------- src/help.c | 4 +- src/proto.h | 5 + src/rcfile.c | 31 +++++- src/winio.c | 127 +++++++++------------ 6 files changed, 292 insertions(+), 253 deletions(-) diff --git a/src/browser.c b/src/browser.c index 37d904c4..29a37be9 100644 --- a/src/browser.c +++ b/src/browser.c @@ -60,6 +60,8 @@ char *do_browser(char *path, DIR *dir) /* The last answer the user typed at the statusbar prompt. */ size_t old_selected; /* The selected file we had before the current selected file. */ + const sc *s; + const subnfunc *f; curs_set(0); blank_statusbar(); @@ -124,11 +126,15 @@ char *do_browser(char *path, DIR *dir) kbinput = get_kbinput(edit, &meta_key, &func_key); parse_browser_input(&kbinput, &meta_key, &func_key); - - switch (kbinput) { + s = get_shortcut(MBROWSER, &kbinput, &meta_key, &func_key); + if (!s) + continue; + f = sctofunc((sc *) s); + if (!f) + break; #ifndef DISABLE_MOUSE - case KEY_MOUSE: - { + if (f->scfunc == (void *) do_mouse) { + int mouse_x, mouse_y; /* We can click on the edit window to select a @@ -158,55 +164,45 @@ char *do_browser(char *path, DIR *dir) if (old_selected == selected) unget_kbinput(NANO_ENTER_KEY, FALSE, FALSE); } - } - break; + } else #endif /* !DISABLE_MOUSE */ - /* Redraw the screen. */ - case NANO_REFRESH_KEY: + if (f->scfunc == total_refresh) { total_redraw(); - break; - case NANO_HELP_KEY: + } else if (f->scfunc == do_help_void) { #ifndef DISABLE_HELP do_browser_help(); curs_set(0); #else nano_disabled_msg(); #endif - break; /* Search for a filename. */ - case NANO_WHEREIS_KEY: + } else if (f->scfunc == do_search) { curs_set(1); do_filesearch(); curs_set(0); - break; /* Search for another filename. */ - case NANO_WHEREIS_NEXT_KEY: + } else if (f->scfunc == (void *) whereis_next_msg) { do_fileresearch(); - break; - case NANO_PREVPAGE_KEY: + } else if (f->scfunc == do_page_up) { if (selected >= (editwinrows + fileline % editwinrows) * width) selected -= (editwinrows + fileline % editwinrows) * width; else selected = 0; - break; - case NANO_NEXTPAGE_KEY: + } else if (f->scfunc == do_page_down) { selected += (editwinrows - fileline % editwinrows) * width; if (selected > filelist_len - 1) selected = filelist_len - 1; - break; - case NANO_FIRSTFILE_METAKEY: + } else if (f->scfunc == (void *) first_file_msg) { if (meta_key) selected = 0; - break; - case NANO_LASTFILE_METAKEY: + } else if (f->scfunc == (void *) last_file_msg) { if (meta_key) selected = filelist_len - 1; - break; /* Go to a specific directory. */ - case NANO_GOTODIR_KEY: + } else if (f->scfunc == (void *) goto_dir_msg) { curs_set(1); i = do_prompt(TRUE, @@ -285,23 +281,19 @@ char *do_browser(char *path, DIR *dir) free(path); path = new_path; goto change_browser_directory; - case NANO_PREVLINE_KEY: + } else if (f->scfunc == do_up_void) { if (selected >= width) selected -= width; - break; - case NANO_BACK_KEY: + } else if (f->scfunc == do_left) { if (selected > 0) selected--; - break; - case NANO_NEXTLINE_KEY: + } else if (f->scfunc == do_down_void) { if (selected + width <= filelist_len - 1) selected += width; - break; - case NANO_FORWARD_KEY: + } else if (f->scfunc == do_right) { if (selected < filelist_len - 1) selected++; - break; - case NANO_ENTER_KEY: + } else if (f->scfunc == do_enter) { /* We can't move up from "/". */ if (strcmp(filelist[selected], "/..") == 0) { statusbar(_("Can't move up a directory")); @@ -359,12 +351,10 @@ char *do_browser(char *path, DIR *dir) /* Start over again with the new path value. */ goto change_browser_directory; /* Abort the file browser. */ - case NANO_EXIT_KEY: + } else if (f->scfunc == do_exit) { abort = TRUE; - break; } } - titlebar(NULL); edit_refresh(); curs_set(1); @@ -558,31 +548,31 @@ void parse_browser_input(int *kbinput, bool *meta_key, bool *func_key) if (!*meta_key) { switch (*kbinput) { case ' ': - *kbinput = NANO_NEXTPAGE_KEY; + *kbinput = sc_seq_or(do_page_down, 0); break; case '-': - *kbinput = NANO_PREVPAGE_KEY; + *kbinput = sc_seq_or(do_page_up, 0); break; case '?': - *kbinput = NANO_HELP_KEY; + *kbinput = sc_seq_or(do_help_void, 0); break; - /* Cancel is equivalent to Exit here. */ + /* Cancel equivalent to Exit here. */ case NANO_CANCEL_KEY: case 'E': case 'e': - *kbinput = NANO_EXIT_KEY; + *kbinput = sc_seq_or(do_exit, 0); break; case 'G': case 'g': - *kbinput = NANO_GOTODIR_KEY; + *kbinput = sc_seq_or((void *) goto_dir_msg, 0); break; case 'S': case 's': - *kbinput = NANO_ENTER_KEY; + *kbinput = sc_seq_or(do_enter, 0); break; case 'W': case 'w': - *kbinput = NANO_WHEREIS_KEY; + *kbinput = sc_seq_or(do_search, 0); break; } } diff --git a/src/global.c b/src/global.c index e3f455b6..5b1f1ee6 100644 --- a/src/global.c +++ b/src/global.c @@ -209,7 +209,7 @@ function_type strtokeytype(char *str) return META; } else if (str[0] == '^') { return CONTROL; - } else if (str[0] == 'M' || str[0] == 'm') { + } else if (str[0] == 'F' || str[0] == 'F') { return FKEY; } else { return RAW; @@ -257,7 +257,7 @@ const sc *first_sc_for(int menu, void *func) { } #ifdef DEBUG - fprintf(stderr, "Whoops, returning null given func %ld\n", (long) func); + fprintf(stderr, "Whoops, returning null given func %ld in menu %d\n", (long) func, menu); #endif /* Otherwise... */ return NULL; @@ -303,6 +303,19 @@ void add_to_sclist(int menu, char *scstring, void *func, int toggle, int execute #endif } +/* Return the given menu's first shortcut sequence, or the default value + (2nd arg). Assumes currmenu for the menu to check*/ +int sc_seq_or (void *func, int defaultval) +{ + const sc *s = first_sc_for(currmenu, func); + + if (s) + return s->seq; + /* else */ + return defaultval; + +} + /* Assign the info to the shortcut struct Assumes keystr is already assigned, naturally */ void assign_keyinfo(sc *s) @@ -337,7 +350,7 @@ void print_sclist(void) for (s = sclist; s->next != NULL; s = s->next) { f = sctofunc(s); if (f) - fprintf(stderr, "Shortcut \"%s\", function: %s\n", s->keystr, f->desc); + fprintf(stderr, "Shortcut \"%s\", function: %s, menus %d\n", s->keystr, f->desc, f->menus); else fprintf(stderr, "Hmm, didnt find a func for \"%s\"\n", s->keystr); } @@ -386,8 +399,8 @@ const char *nano_delete_msg = ""; const char *nano_backspace_msg = ""; const char *nano_regexp_msg = ""; const char *gototext_msg = ""; -const char *do_para_begin_void = ""; -const char *do_para_end_void = ""; +const char *do_para_begin_msg = ""; +const char *do_para_end_msg = ""; const char *case_sens_msg = ""; const char *backwards_msg = ""; const char *do_cut_till_end = ""; @@ -397,15 +410,23 @@ const char *append_msg = ""; const char *prepend_msg = ""; const char *backup_file_msg = ""; const char *to_files_msg = ""; -#else /* NANO_TINY */ -const char *prev_history_msg = N_("PrevHstory"); +const char *first_file_msg = ""; +const char *whereis_next_msg = ""; +/* TRANSLATORS: Try to keep this at most 12 characters. */ +const char *last_file_msg = ""; +const char *new_buffer_msg = ""; +const char *goto_dir_msg; + +#else /* TRANSLATORS: Try to keep this and previous strings at most 10 * characters. */ +const char *prev_history_msg = N_("PrevHstory"); const char *next_history_msg = N_("NextHstory"); const char *replace_msg = N_("Replace"); const char *no_replace_msg = N_("No Replace"); -const char *go_to_line_msg = N_("Go To Line"); const char *gototext_msg = N_("Go To Text"); +/* TRANSLATORS: Try to keep this at most 12 characters. */ +const char *whereis_next_msg = N_("WhereIs Next"); #ifndef DISABLE_BROWSER /* TRANSLATORS: Try to keep this at most 16 characters. */ const char *to_files_msg = N_("To Files"); @@ -429,8 +450,9 @@ const char *backup_file_msg = N_("Backup File"); /* TRANSLATORS: Try to keep this at most 16 characters. */ const char *new_buffer_msg = N_("New Buffer"); #endif +const char *goto_dir_msg = N_("Go To Dir"); -#endif +#endif /* NANO_TINY */ /* Initialize all shortcut lists. If unjustify is TRUE, replace the * Uncut shortcut in the main shortcut list with UnJustify. */ @@ -445,10 +467,6 @@ void shortcut_init(bool unjustify) const char *next_page_msg = N_("Next Page"); /* TRANSLATORS: Try to keep this string at most 10 characters. */ -#ifndef NANO_TINY - /* TRANSLATORS: Try to keep this at most 12 characters. */ - const char *whereis_next_msg = N_("WhereIs Next"); -#endif /* TRANSLATORS: Try to keep this and following strings at most 10 * characters. */ const char *first_line_msg = N_("First Line"); @@ -460,8 +478,8 @@ void shortcut_init(bool unjustify) #endif const char *refresh_msg = N_("Refresh"); const char *insert_file_msg = N_("Insert File"); - const char *goto_dir_msg = N_("Go To Dir"); const char *ext_cmd_msg = N_("Execute Command"); + const char *go_to_line_msg = N_("Go To Line"); #ifndef DISABLE_HELP const char *nano_cancel_msg = N_("Cancel the current function"); @@ -656,12 +674,12 @@ void shortcut_init(bool unjustify) NOVIEW); #endif - add_to_funcs(do_search, MMAIN, whereis_msg, + add_to_funcs(do_search, MMAIN|MBROWSER, whereis_msg, nano_whereis_msg, FALSE, VIEW); - add_to_funcs(do_page_up, (MMAIN|MHELP|MBROWSER), + add_to_funcs(do_page_up, MMAIN|MHELP, prev_page_msg, nano_prevpage_msg, FALSE, VIEW); - add_to_funcs(do_page_down, (MMAIN|MHELP|MBROWSER), + add_to_funcs(do_page_down, MMAIN|MHELP, next_page_msg, nano_nextpage_msg, TRUE, VIEW); /* TRANSLATORS: Try to keep this at most 10 characters. */ @@ -678,9 +696,10 @@ void shortcut_init(bool unjustify) add_to_funcs(do_uncut_text, MMAIN, N_("UnCut Text"), nano_uncut_msg, FALSE, NOVIEW); - /* TRANSLATORS: Try to keep this at most 10 characters. */ +#ifndef NANO_TINY add_to_funcs(do_cursorpos_void, MMAIN, N_("Cur Pos"), nano_cursorpos_msg, FALSE, VIEW); +#endif /* If we're using restricted mode, spell checking is disabled * because it allows reading from or writing to files not specified @@ -704,6 +723,13 @@ void shortcut_init(bool unjustify) add_to_funcs(do_gotolinecolumn_void, (MMAIN|MWHEREIS), go_to_line_msg, nano_gotoline_msg, FALSE, VIEW); + /* TRANSLATORS: Try to keep this at most 10 characters. */ +#ifdef NANO_TINY + add_to_funcs(do_cursorpos_void, MMAIN, N_("Cur Pos"), nano_cursorpos_msg, + FALSE, VIEW); +#endif + + add_to_funcs(do_replace, (MMAIN|MWHEREIS), replace_msg, nano_replace_msg, #ifndef NANO_TINY @@ -732,11 +758,16 @@ void shortcut_init(bool unjustify) #endif + add_to_funcs(do_page_up, MBROWSER, + prev_page_msg, nano_prevpage_msg, FALSE, VIEW); + add_to_funcs(do_page_down, MBROWSER, + next_page_msg, nano_nextpage_msg, TRUE, VIEW); + - add_to_funcs(do_right, MMAIN, N_("Forward"), nano_forward_msg, + add_to_funcs(do_right, (MMAIN|MBROWSER), N_("Forward"), nano_forward_msg, FALSE, VIEW); - add_to_funcs(do_left, MMAIN, N_("Back"), nano_back_msg, + add_to_funcs(do_left, (MMAIN|MBROWSER), N_("Back"), nano_back_msg, FALSE, VIEW); #ifndef NANO_TINY @@ -747,10 +778,10 @@ void shortcut_init(bool unjustify) nano_prevword_msg, FALSE, VIEW); #endif - add_to_funcs(do_up_void, (MMAIN|MHELP), N_("Prev Line"), + add_to_funcs(do_up_void, (MMAIN|MHELP|MBROWSER), N_("Prev Line"), nano_prevline_msg, FALSE, VIEW); - add_to_funcs(do_down_void, (MMAIN|MHELP), N_("Next Line"), + add_to_funcs(do_down_void, (MMAIN|MHELP|MBROWSER), N_("Next Line"), nano_nextline_msg, TRUE, VIEW); add_to_funcs(do_home, MMAIN, N_("Home"), nano_home_msg, @@ -943,10 +974,8 @@ void shortcut_init(bool unjustify) add_to_sclist(MALL, "^G", do_help_void, 0, TRUE); add_to_sclist(MALL, "F1", do_help_void, 0, TRUE); #endif - add_to_sclist(MMAIN, "^X", do_exit, 0, TRUE); - add_to_sclist(MMAIN, "F2", do_exit, 0, TRUE); - add_to_sclist(MHELP, "^X", do_exit, 0, TRUE); - add_to_sclist(MHELP, "F2", do_exit, 0, TRUE); + add_to_sclist(MMAIN|MHELP|MBROWSER, "^X", do_exit, 0, TRUE); + add_to_sclist(MMAIN|MHELP|MBROWSER, "F2", do_exit, 0, TRUE); add_to_sclist(MMAIN, "^_", do_gotolinecolumn_void, 0, TRUE); add_to_sclist(MMAIN, "F13", do_gotolinecolumn_void, 0, TRUE); add_to_sclist(MMAIN, "^O", do_writeout_void, 0, TRUE); @@ -957,12 +986,12 @@ void shortcut_init(bool unjustify) #endif add_to_sclist(MMAIN, "^R", do_insertfile_void, 0, TRUE); add_to_sclist(MMAIN, "F5", do_insertfile_void, 0, TRUE); - add_to_sclist(MMAIN, "^W", do_search, 0, TRUE); - add_to_sclist(MMAIN, "F6", do_search, 0, TRUE); - add_to_sclist(MMAIN, "^Y", do_page_up, 0, TRUE); - add_to_sclist(MMAIN, "F7", do_page_up, 0, TRUE); - add_to_sclist(MMAIN, "^V", do_page_down, 0, TRUE); - add_to_sclist(MMAIN, "F8", do_page_down, 0, TRUE); + add_to_sclist(MMAIN|MBROWSER, "^W", do_search, 0, TRUE); + add_to_sclist(MMAIN|MBROWSER, "F6", do_search, 0, TRUE); + add_to_sclist(MMAIN|MBROWSER, "^Y", do_page_up, 0, TRUE); + add_to_sclist(MMAIN|MBROWSER, "F7", do_page_up, 0, TRUE); + add_to_sclist(MMAIN|MBROWSER, "^V", do_page_down, 0, TRUE); + add_to_sclist(MMAIN|MBROWSER, "F8", do_page_down, 0, TRUE); add_to_sclist(MMAIN, "^K", do_cut_text_void, 0, TRUE); add_to_sclist(MMAIN, "F9", do_cut_text_void, 0, TRUE); add_to_sclist(MMAIN, "^U", do_uncut_text, 0, TRUE); @@ -986,8 +1015,8 @@ void shortcut_init(bool unjustify) add_to_sclist(MMAIN, "^^", do_mark, 0, TRUE); add_to_sclist(MMAIN, "F15", do_mark, 0, TRUE); add_to_sclist(MMAIN, "M-A", do_mark, 0, TRUE); - add_to_sclist(MALL, "F16", do_research, 0, TRUE); add_to_sclist(MALL, "M-W", do_research, 0, TRUE); + add_to_sclist(MALL, "F16", do_research, 0, TRUE); add_to_sclist(MMAIN, "M-^", do_copy_text, 0, TRUE); add_to_sclist(MMAIN, "M-6", do_copy_text, 0, TRUE); add_to_sclist(MMAIN, "M-}", do_indent_void, 0, TRUE); @@ -1003,6 +1032,7 @@ void shortcut_init(bool unjustify) add_to_sclist(MALL, "^N", do_down_void, 0, TRUE); add_to_sclist(MALL, "^A", do_home, 0, TRUE); add_to_sclist(MALL, "^E", do_end, 0, TRUE); +#ifndef NANO_TINY add_to_sclist(MWHEREIS|MREPLACE|MREPLACE2, "^W", do_para_begin_void, 0, TRUE); add_to_sclist(MWHEREIS|MREPLACE|MREPLACE2, @@ -1011,6 +1041,7 @@ void shortcut_init(bool unjustify) add_to_sclist(MALL, "M-9", do_para_begin_void, 0, TRUE); add_to_sclist(MALL, "M-)", do_para_end_void, 0, TRUE); add_to_sclist(MALL, "M-0", do_para_end_void, 0, TRUE); +#endif add_to_sclist(MWHEREIS|MREPLACE|MREPLACE2, "^Y", do_first_line, 0, TRUE); add_to_sclist(MWHEREIS|MREPLACE|MREPLACE2, @@ -1031,6 +1062,10 @@ void shortcut_init(bool unjustify) add_to_sclist(MMAIN, "M-|", do_first_line, 0, TRUE); add_to_sclist(MMAIN, "M-/", do_last_line, 0, TRUE); add_to_sclist(MMAIN, "M-?", do_last_line, 0, TRUE); + add_to_sclist(MBROWSER|MWHEREISFILE, "M-\\", (void *) first_file_msg, 0, TRUE); + add_to_sclist(MBROWSER|MWHEREISFILE, "M-|", (void *) first_file_msg, 0, TRUE); + add_to_sclist(MBROWSER|MWHEREISFILE, "M-/", (void *) last_file_msg, 0, TRUE); + add_to_sclist(MBROWSER|MWHEREISFILE, "M-?", (void *) last_file_msg, 0, TRUE); #ifndef NANO_TINY add_to_sclist(MMAIN, "M-[", do_find_bracket, 0, TRUE); add_to_sclist(MMAIN, "M--", do_scroll_up, 0, TRUE); @@ -1050,8 +1085,8 @@ void shortcut_init(bool unjustify) add_to_sclist(MALL, "^M", do_enter, 0, TRUE); add_to_sclist(MALL, "^D", do_delete, 0, TRUE); add_to_sclist(MALL, "^H", do_backspace, 0, TRUE); - add_to_sclist(MALL, "M-T", do_cut_till_end, 0, TRUE); #ifndef NANO_TINY + add_to_sclist(MALL, "M-T", do_cut_till_end, 0, TRUE); add_to_sclist(MALL, "M-J", do_full_justify, 0, TRUE); add_to_sclist(MALL, "M-D", do_wordlinechar_count, 0, TRUE); add_to_sclist(MMAIN, "M-X", do_toggle, NO_HELP, TRUE); @@ -1073,10 +1108,10 @@ void shortcut_init(bool unjustify) #endif add_to_sclist((MWHEREIS|MREPLACE|MREPLACE2|MGOTOLINE|MWRITEFILE|MINSERTFILE|MEXTCMD|MSPELL|MWHEREISFILE|MGOTODIR), "^C", (void *) cancel_msg, 0, FALSE); - add_to_sclist(MHELP, "^Y", do_page_up, 0, TRUE); - add_to_sclist(MHELP, "F7", do_page_up, 0, TRUE); - add_to_sclist(MHELP, "^V", do_page_down, 0, TRUE); - add_to_sclist(MHELP, "F8", do_page_down, 0, TRUE); + add_to_sclist(MHELP|MBROWSER|MWHEREISFILE, "^Y", do_page_up, 0, TRUE); + add_to_sclist(MHELP|MBROWSER|MWHEREISFILE, "F7", do_page_up, 0, TRUE); + add_to_sclist(MHELP|MBROWSER|MWHEREISFILE, "^V", do_page_down, 0, TRUE); + add_to_sclist(MHELP|MBROWSER|MWHEREISFILE, "F8", do_page_down, 0, TRUE); add_to_sclist(MHELP, "^X", do_exit, 0, TRUE); add_to_sclist(MHELP, "F2", do_exit, 0, TRUE); add_to_sclist(MWRITEFILE, "M-D", (void *) dos_format_msg, 0, FALSE); @@ -1159,6 +1194,7 @@ char *flagtostr(int flag) return "?????"; } } +#endif /* NANO_TINY */ /* Interpret the string given by the rc file and return a shortcut struct, complete with proper value for execute */ @@ -1169,17 +1205,19 @@ sc *strtosc(int menu, char *input) s = (sc *)nmalloc(sizeof(sc)); s->execute = TRUE; /* overridden as needed below */ + +#ifndef DISABLE_HELP if (!strcasecmp(input, "help")) s->scfunc = do_help_void; - else if (!strcasecmp(input, "cancel")) { + else +#endif + if (!strcasecmp(input, "cancel")) { s->scfunc = (void *) cancel_msg; s->execute = FALSE; } else if (!strcasecmp(input, "exit")) s->scfunc = do_exit; else if (!strcasecmp(input, "writeout")) s->scfunc = do_writeout_void; - else if (!strcasecmp(input, "justify")) - s->scfunc = do_justify_void; else if (!strcasecmp(input, "insert")) s->scfunc = do_insertfile_void; else if (!strcasecmp(input, "whereis")) @@ -1203,6 +1241,9 @@ sc *strtosc(int menu, char *input) s->scfunc = do_gotolinecolumn_void; else if (!strcasecmp(input, "replace")) s->scfunc = do_replace; +#ifndef NANO_TINY + else if (!strcasecmp(input, "justify")) + s->scfunc = do_justify_void; else if (!strcasecmp(input, "mark")) s->scfunc = do_mark; else if (!strcasecmp(input, "searchagain") || @@ -1214,105 +1255,24 @@ sc *strtosc(int menu, char *input) s->scfunc = do_indent_void; else if (!strcasecmp(input, "unindent")) s->scfunc = do_unindent; - else if (!strcasecmp(input, "right") || - !strcasecmp(input, "forward")) - s->scfunc = do_right; - else if (!strcasecmp(input, "left") || - !strcasecmp(input, "back")) - s->scfunc = do_left; + else if (!strcasecmp(input, "scrollup")) + s->scfunc = do_scroll_up; + else if (!strcasecmp(input, "scrolldown")) + s->scfunc = do_scroll_down; else if (!strcasecmp(input, "nextword")) s->scfunc = do_next_word_void; else if (!strcasecmp(input, "prevword")) s->scfunc = do_prev_word_void; - else if (!strcasecmp(input, "up") || - !strcasecmp(input, "prevline")) - s->scfunc = do_up_void; - else if (!strcasecmp(input, "down") || - !strcasecmp(input, "nextline")) - s->scfunc = do_down_void; - else if (!strcasecmp(input, "home")) - s->scfunc = do_home; - else if (!strcasecmp(input, "end")) - s->scfunc = do_end; - else if (!strcasecmp(input, "beginpara")) - s->scfunc = do_para_begin_void; - else if (!strcasecmp(input, "endpara")) - s->scfunc = do_para_end_void; else if (!strcasecmp(input, "findbracket")) s->scfunc = do_find_bracket; - else if (!strcasecmp(input, "scrollup")) - s->scfunc = do_scroll_up; - else if (!strcasecmp(input, "scrolldown")) - s->scfunc = do_scroll_down; -#ifdef ENABLE_MULTIBUFFER - else if (!strcasecmp(input, "prevbuf")) - s->scfunc = switch_to_prev_buffer_void; - else if (!strcasecmp(input, "nextbuf")) - s->scfunc = switch_to_next_buffer_void; -#endif - else if (!strcasecmp(input, "verbatim")) - s->scfunc = do_verbatim_input; - else if (!strcasecmp(input, "tab")) - s->scfunc = do_tab; - else if (!strcasecmp(input, "enter")) - s->scfunc = do_enter; - else if (!strcasecmp(input, "delete")) - s->scfunc = do_delete; - else if (!strcasecmp(input, "fulljustify")) - s->scfunc = do_full_justify; else if (!strcasecmp(input, "wordcount")) s->scfunc = do_wordlinechar_count; - else if (!strcasecmp(input, "refresh")) - s->scfunc = total_refresh; - else if (!strcasecmp(input, "casesens")) { - s->scfunc = (void *) case_sens_msg; - s->execute = FALSE; - } else if (!strcasecmp(input, "regexp") || - !strcasecmp(input, "regex")) { - s->scfunc = (void *) regexp_msg; - s->execute = FALSE; - } else if (!strcasecmp(input, "prevhistory")) { + else if (!strcasecmp(input, "prevhistory")) { s->scfunc = (void *) prev_history_msg; s->execute = FALSE; } else if (!strcasecmp(input, "nexthistory")) { s->scfunc = (void *) next_history_msg; s->execute = FALSE; - } else if (!strcasecmp(input, "dontreplace")) { - s->scfunc = (void *) no_replace_msg; - s->execute = FALSE; - } else if (!strcasecmp(input, "gototext")) { - s->scfunc = (void *) gototext_msg; - s->execute = FALSE; - } else if (!strcasecmp(input, "browser") || - !strcasecmp(input, "tofiles")) { - s->scfunc = (void *) to_files_msg; - s->execute = FALSE; - } else if (!strcasecmp(input, "dosformat")) { - s->scfunc = (void *) dos_format_msg; - s->execute = FALSE; - } else if (!strcasecmp(input, "macformat")) { - s->scfunc = (void *) mac_format_msg; - s->execute = FALSE; - } else if (!strcasecmp(input, "append")) { - s->scfunc = (void *) append_msg; - s->execute = FALSE; - } else if (!strcasecmp(input, "prepend")) { - s->scfunc = (void *) prepend_msg; - s->execute = FALSE; - } else if (!strcasecmp(input, "backup")) { - s->scfunc = (void *) backup_file_msg; - s->execute = FALSE; -#ifdef ENABLE_MULTIBUFFER - } else if (!strcasecmp(input, "newbuffer")) { - s->scfunc = (void *) new_buffer_msg; - s->execute = FALSE; -#endif - } else if (!strcasecmp(input, "firstfile")) { - s->scfunc = (void *) first_file_msg; - s->execute = FALSE; - } else if (!strcasecmp(input, "lastfile")) { - s->scfunc = (void *) last_file_msg; - s->execute = FALSE; } else if (!strcasecmp(input, "nohelp") || !strcasecmp(input, "nohelp")) { s->scfunc = (void *) do_toggle; @@ -1378,6 +1338,88 @@ sc *strtosc(int menu, char *input) s->scfunc = (void *) do_toggle; s->execute = FALSE; s->toggle = SUSPEND; + } else if (!strcasecmp(input, "beginpara")) + s->scfunc = do_para_begin_void; + else if (!strcasecmp(input, "endpara")) + s->scfunc = do_para_end_void; + else if (!strcasecmp(input, "fulljustify")) + s->scfunc = do_full_justify; +#endif /* NANO_TINY */ + else if (!strcasecmp(input, "right") || + !strcasecmp(input, "forward")) + s->scfunc = do_right; + else if (!strcasecmp(input, "left") || + !strcasecmp(input, "back")) + s->scfunc = do_left; + else if (!strcasecmp(input, "up") || + !strcasecmp(input, "prevline")) + s->scfunc = do_up_void; + else if (!strcasecmp(input, "down") || + !strcasecmp(input, "nextline")) + s->scfunc = do_down_void; + else if (!strcasecmp(input, "home")) + s->scfunc = do_home; + else if (!strcasecmp(input, "end")) + s->scfunc = do_end; +#ifdef ENABLE_MULTIBUFFER + else if (!strcasecmp(input, "prevbuf")) + s->scfunc = switch_to_prev_buffer_void; + else if (!strcasecmp(input, "nextbuf")) + s->scfunc = switch_to_next_buffer_void; +#endif + else if (!strcasecmp(input, "verbatim")) + s->scfunc = do_verbatim_input; + else if (!strcasecmp(input, "tab")) + s->scfunc = do_tab; + else if (!strcasecmp(input, "enter")) + s->scfunc = do_enter; + else if (!strcasecmp(input, "delete")) + s->scfunc = do_delete; + else if (!strcasecmp(input, "refresh")) + s->scfunc = total_refresh; + else if (!strcasecmp(input, "casesens")) { + s->scfunc = (void *) case_sens_msg; + s->execute = FALSE; + } else if (!strcasecmp(input, "regexp") || + !strcasecmp(input, "regex")) { + s->scfunc = (void *) regexp_msg; + s->execute = FALSE; + } else if (!strcasecmp(input, "dontreplace")) { + s->scfunc = (void *) no_replace_msg; + s->execute = FALSE; + } else if (!strcasecmp(input, "gototext")) { + s->scfunc = (void *) gototext_msg; + s->execute = FALSE; + } else if (!strcasecmp(input, "browser") || + !strcasecmp(input, "tofiles")) { + s->scfunc = (void *) to_files_msg; + s->execute = FALSE; + } else if (!strcasecmp(input, "dosformat")) { + s->scfunc = (void *) dos_format_msg; + s->execute = FALSE; + } else if (!strcasecmp(input, "macformat")) { + s->scfunc = (void *) mac_format_msg; + s->execute = FALSE; + } else if (!strcasecmp(input, "append")) { + s->scfunc = (void *) append_msg; + s->execute = FALSE; + } else if (!strcasecmp(input, "prepend")) { + s->scfunc = (void *) prepend_msg; + s->execute = FALSE; + } else if (!strcasecmp(input, "backup")) { + s->scfunc = (void *) backup_file_msg; + s->execute = FALSE; +#ifdef ENABLE_MULTIBUFFER + } else if (!strcasecmp(input, "newbuffer")) { + s->scfunc = (void *) new_buffer_msg; + s->execute = FALSE; +#endif + } else if (!strcasecmp(input, "firstfile")) { + s->scfunc = (void *) first_file_msg; + s->execute = FALSE; + } else if (!strcasecmp(input, "lastfile")) { + s->scfunc = (void *) last_file_msg; + s->execute = FALSE; } else { free(s); return NULL; @@ -1387,6 +1429,7 @@ sc *strtosc(int menu, char *input) } +#ifdef ENABLE_NANORC /* Same thing as abnove but for the menu */ int strtomenu(char *input) { @@ -1423,10 +1466,9 @@ int strtomenu(char *input) return -1; } - - #endif + #ifdef DEBUG /* This function is used to gracefully return all the memory we've used. * It should be called just before calling exit(). Practically, the diff --git a/src/help.c b/src/help.c index 3e21e66f..76f48f10 100644 --- a/src/help.c +++ b/src/help.c @@ -129,10 +129,10 @@ void do_help(void (*refresh_func)(void)) kbinput = get_kbinput(edit, &meta_key, &func_key); parse_help_input(&kbinput, &meta_key, &func_key); - s = get_shortcut(MMAIN, &kbinput, &meta_key, &func_key); + s = get_shortcut(MHELP, &kbinput, &meta_key, &func_key); if (!s) continue; - f = sctofunc(s); + f = sctofunc((sc *) s); if (!f) continue; diff --git a/src/proto.h b/src/proto.h index ab44188a..3e239f70 100644 --- a/src/proto.h +++ b/src/proto.h @@ -779,6 +779,7 @@ int strtomenu(char *input); void assign_keyinfo(sc *s); void xon_complaint(void); void xoff_complaint(void); +int sc_seq_or (void *func, int defaultval); const char *cancel_msg; @@ -789,6 +790,10 @@ const char *backwards_msg; const char *replace_msg; const char *no_replace_msg; const char *go_to_line_msg; +const char *whereis_next_msg; +const char *first_file_msg; +const char *last_file_msg; +const char *goto_dir_msg; #ifdef HAVE_REGEX_H const char *regexp_msg; diff --git a/src/rcfile.c b/src/rcfile.c index c88bc40a..1c3c4f7c 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -423,8 +423,7 @@ void parse_keybinding(char *ptr) we found for the same menu, then make this new new beginning */ for (s = sclist; s != NULL; s = s->next) { - if (((s->menu & newsc->menu) || newsc->menu == MALL) && - (s->seq == newsc->seq)) { + if (((s->menu & newsc->menu)) && s->seq == newsc->seq) { s->menu &= ~newsc->menu; #ifdef DEBUG fprintf(stderr, "replaced menu entry %d\n", s->menu); @@ -934,6 +933,8 @@ void parse_rcfile(FILE *rcstream fclose(rcstream); lineno = 0; + check_vitals_mapped(); + if (errors) { errors = FALSE; fprintf(stderr, @@ -1020,4 +1021,30 @@ void do_rcfile(void) #endif } +/* Check whether the user has unmapped every shortcut for a +sequence we consider 'vital', like the exit function */ +int check_vitals_mapped(void) +{ + subnfunc *f; + int v; +#define VITALS 5 + void *vitals[VITALS] = { do_exit, do_exit, (void *) cancel_msg, (void *) cancel_msg, (void *) cancel_msg }; + int inmenus[VITALS] = { MMAIN, MHELP, MWHEREIS, MREPLACE, MGOTOLINE }; + + for (v = 0; v < VITALS; v++) { + for (f = allfuncs; f != NULL; f = f->next) { + if (f->scfunc == vitals[v] && f->menus & inmenus[v]) { + const sc *s = first_sc_for(inmenus[v], f->scfunc); + if (!s) { + rcfile_error(N_("Fatal error: no keys mapped for function \"%s\""), + f->desc); + fprintf(stderr, N_("Exiting. Please use nano with the -I option if needed to adjust your nanorc settings\n")); + exit(1); + } + break; + } + } + } +} + #endif /* ENABLE_NANORC */ diff --git a/src/winio.c b/src/winio.c index 77e6172e..70e1b2fe 100644 --- a/src/winio.c +++ b/src/winio.c @@ -490,44 +490,36 @@ int parse_kbinput(WINDOW *win, bool *meta_key, bool *func_key) if (retval != ERR) { switch (retval) { case NANO_CONTROL_8: - retval = ISSET(REBIND_DELETE) ? NANO_DELETE_KEY : - NANO_BACKSPACE_KEY; + retval = ISSET(REBIND_DELETE) ? sc_seq_or(do_delete, 0) : + sc_seq_or(do_backspace, 0); break; case KEY_DOWN: #ifdef KEY_SDOWN /* ncurses and Slang don't support KEY_SDOWN. */ case KEY_SDOWN: #endif - s = first_sc_for(currmenu, (void *) do_down_void); - if (s) - retval = s->seq; + retval = sc_seq_or((void *) do_down_void, *kbinput); break; case KEY_UP: #ifdef KEY_SUP /* ncurses and Slang don't support KEY_SUP. */ case KEY_SUP: #endif - s = first_sc_for(currmenu, (void *) do_up_void); - if (s) - retval = s->seq; + retval = sc_seq_or((void *) do_up_void, *kbinput); break; case KEY_LEFT: #ifdef KEY_SLEFT /* Slang doesn't support KEY_SLEFT. */ case KEY_SLEFT: #endif - s = first_sc_for(currmenu, (void *) do_up_void); - if (s) - retval = s->seq; + retval = sc_seq_or((void *) do_left, *kbinput); break; case KEY_RIGHT: #ifdef KEY_SRIGHT /* Slang doesn't support KEY_SRIGHT. */ case KEY_SRIGHT: #endif - s = first_sc_for(currmenu, (void *) do_right); - if (s) - retval = s->seq; + retval = sc_seq_or((void *) do_right, *kbinput); break; #ifdef KEY_HOME /* HP-UX 10-11 doesn't support KEY_HOME. */ @@ -539,14 +531,10 @@ int parse_kbinput(WINDOW *win, bool *meta_key, bool *func_key) #endif case KEY_A1: /* Home (7) on numeric keypad with * NumLock off. */ - s = first_sc_for(currmenu, (void *) do_home); - if (s) - retval = s->seq; + retval = sc_seq_or((void *) do_home, *kbinput); break; case KEY_BACKSPACE: - s = first_sc_for(currmenu, (void *) do_backspace); - if (s) - retval = s->seq; + retval = sc_seq_or((void *) do_backspace, *kbinput); break; case KEY_DC: #ifdef KEY_SDC @@ -554,40 +542,29 @@ int parse_kbinput(WINDOW *win, bool *meta_key, bool *func_key) case KEY_SDC: #endif if (ISSET(REBIND_DELETE)) - s = first_sc_for(currmenu, (void *) do_delete); + retval = sc_seq_or((void *) do_delete, *kbinput); else - s = first_sc_for(currmenu, (void *) do_backspace); - - if (s) - retval = s->seq; + retval = sc_seq_or((void *) do_backspace, *kbinput); break; case KEY_IC: #ifdef KEY_SIC /* Slang doesn't support KEY_SIC. */ case KEY_SIC: #endif - s = first_sc_for(currmenu, (void *) do_insertfile_void); - if (s) - retval = s->seq; + retval = sc_seq_or((void *) do_insertfile_void, *kbinput); break; case KEY_NPAGE: case KEY_C3: /* PageDown (4) on numeric keypad with * NumLock off. */ - s = first_sc_for(currmenu, (void *) do_page_down); - if (s) - retval = s->seq; + retval = sc_seq_or((void *) do_page_down, *kbinput); break; case KEY_PPAGE: case KEY_A3: /* PageUp (9) on numeric keypad with * NumLock off. */ - s = first_sc_for(currmenu, (void *) do_page_up); - if (s) - retval = s->seq; + retval = sc_seq_or((void *) do_page_up, *kbinput); break; case KEY_ENTER: - s = first_sc_for(currmenu, (void *) do_enter); - if (s) - retval = s->seq; + retval = sc_seq_or((void *) do_enter, *kbinput); break; case KEY_B2: /* Center (5) on numeric keypad with * NumLock off. */ @@ -603,9 +580,7 @@ int parse_kbinput(WINDOW *win, bool *meta_key, bool *func_key) /* HP-UX 10-11 and Slang don't support KEY_SEND. */ case KEY_SEND: #endif - s = first_sc_for(currmenu, (void *) do_end); - if (s) - retval = s->seq; + retval = sc_seq_or((void *) do_end, *kbinput); break; #ifdef KEY_BEG /* Slang doesn't support KEY_BEG. */ @@ -788,15 +763,15 @@ int get_escape_seq_kbinput(const int *seq, size_t seq_len) retval = KEY_B2; break; case 'F': /* Esc O F == End on xterm/Terminal. */ - retval = NANO_END_KEY; + retval = sc_seq_or(do_end, 0); break; case 'H': /* Esc O H == Home on xterm/Terminal. */ - retval = NANO_HOME_KEY; + retval = sc_seq_or(do_home, 0);; break; case 'M': /* Esc O M == Enter on numeric keypad with * NumLock off on VT100/VT220/VT320/xterm/ * rxvt/Eterm. */ - retval = NANO_ENTER_KEY; + retval = sc_seq_or(do_home, 0);; break; case 'P': /* Esc O P == F1 on VT100/VT220/VT320/Mach * console. */ @@ -861,7 +836,7 @@ int get_escape_seq_kbinput(const int *seq, size_t seq_len) case 'n': /* Esc O n == Delete (.) on numeric keypad * with NumLock off on VT100/VT220/VT320/ * xterm/rxvt/Eterm/Terminal. */ - retval = NANO_DELETE_KEY; + retval = sc_seq_or(do_delete, 0);; break; case 'o': /* Esc O o == '/' on numeric keypad with * NumLock off on VT100/VT220/VT320/xterm/ @@ -871,27 +846,27 @@ int get_escape_seq_kbinput(const int *seq, size_t seq_len) case 'p': /* Esc O p == Insert (0) on numeric keypad * with NumLock off on VT100/VT220/VT320/ * rxvt/Eterm/Terminal. */ - retval = NANO_INSERTFILE_KEY; + retval = sc_seq_or(do_insertfile_void, 0);; break; case 'q': /* Esc O q == End (1) on numeric keypad * with NumLock off on VT100/VT220/VT320/ * rxvt/Eterm/Terminal. */ - retval = NANO_END_KEY; + retval = sc_seq_or(do_end, 0);; break; case 'r': /* Esc O r == Down (2) on numeric keypad * with NumLock off on VT100/VT220/VT320/ * rxvt/Eterm/Terminal. */ - retval = NANO_NEXTLINE_KEY; + retval = sc_seq_or(do_down_void, 0);; break; case 's': /* Esc O s == PageDown (3) on numeric * keypad with NumLock off on VT100/VT220/ * VT320/rxvt/Eterm/Terminal. */ - retval = NANO_NEXTPAGE_KEY; + retval = sc_seq_or(do_page_down, 0);; break; case 't': /* Esc O t == Left (4) on numeric keypad * with NumLock off on VT100/VT220/VT320/ * rxvt/Eterm/Terminal. */ - retval = NANO_BACK_KEY; + retval = sc_seq_or(do_left, 0);; break; case 'u': /* Esc O u == Center (5) on numeric keypad * with NumLock off on VT100/VT220/VT320/ @@ -901,22 +876,22 @@ int get_escape_seq_kbinput(const int *seq, size_t seq_len) case 'v': /* Esc O v == Right (6) on numeric keypad * with NumLock off on VT100/VT220/VT320/ * rxvt/Eterm/Terminal. */ - retval = NANO_FORWARD_KEY; + retval = sc_seq_or(do_right, 0); break; case 'w': /* Esc O w == Home (7) on numeric keypad * with NumLock off on VT100/VT220/VT320/ * rxvt/Eterm/Terminal. */ - retval = NANO_HOME_KEY; + retval = sc_seq_or(do_home, 0);; break; case 'x': /* Esc O x == Up (8) on numeric keypad * with NumLock off on VT100/VT220/VT320/ * rxvt/Eterm/Terminal. */ - retval = NANO_PREVLINE_KEY; + retval = sc_seq_or(do_up_void, 0);; break; case 'y': /* Esc O y == PageUp (9) on numeric keypad * with NumLock off on VT100/VT220/VT320/ * rxvt/Eterm/Terminal. */ - retval = NANO_PREVPAGE_KEY; + retval = sc_seq_or(do_up, 0);; break; } break; @@ -1010,7 +985,7 @@ int get_escape_seq_kbinput(const int *seq, size_t seq_len) break; default: /* Esc [ 1 ~ == Home on * VT320/Linux console. */ - retval = NANO_HOME_KEY; + retval = sc_seq_or(do_home, 0);; break; } } @@ -1061,40 +1036,40 @@ int get_escape_seq_kbinput(const int *seq, size_t seq_len) default: /* Esc [ 2 ~ == Insert on * VT220/VT320/Linux console/ * xterm/Terminal. */ - retval = NANO_INSERTFILE_KEY; + retval = sc_seq_or(do_insertfile_void, 0);; break; } } break; case '3': /* Esc [ 3 ~ == Delete on VT220/VT320/ * Linux console/xterm/Terminal. */ - retval = NANO_DELETE_KEY; + retval = sc_seq_or(do_delete, 0);; break; case '4': /* Esc [ 4 ~ == End on VT220/VT320/Linux * console/xterm. */ - retval = NANO_END_KEY; + retval = sc_seq_or(do_end, 0);; break; case '5': /* Esc [ 5 ~ == PageUp on VT220/VT320/ * Linux console/xterm/Terminal; * Esc [ 5 ^ == PageUp on Eterm. */ - retval = NANO_PREVPAGE_KEY; + retval = sc_seq_or(do_page_up, 0);; break; case '6': /* Esc [ 6 ~ == PageDown on VT220/VT320/ * Linux console/xterm/Terminal; * Esc [ 6 ^ == PageDown on Eterm. */ - retval = NANO_NEXTPAGE_KEY; + retval = sc_seq_or(do_page_down, 0);; break; case '7': /* Esc [ 7 ~ == Home on rxvt. */ - retval = NANO_HOME_KEY; + retval = sc_seq_or(do_home, 0); break; case '8': /* Esc [ 8 ~ == End on rxvt. */ - retval = NANO_END_KEY; + retval = sc_seq_or(do_end, 0); break; case '9': /* Esc [ 9 == Delete on Mach console. */ - retval = NANO_DELETE_KEY; + retval = sc_seq_or(do_delete, 0);; break; case '@': /* Esc [ @ == Insert on Mach console. */ - retval = NANO_INSERTFILE_KEY; + retval = sc_seq_or(do_insertfile_void, 0);; break; case 'A': /* Esc [ A == Up on ANSI/VT220/Linux * console/FreeBSD console/Mach console/ @@ -1117,23 +1092,23 @@ int get_escape_seq_kbinput(const int *seq, size_t seq_len) break; case 'F': /* Esc [ F == End on FreeBSD * console/Eterm. */ - retval = NANO_END_KEY; + retval = sc_seq_or(do_end, 0); break; case 'G': /* Esc [ G == PageDown on FreeBSD * console. */ - retval = NANO_NEXTPAGE_KEY; + retval = sc_seq_or(do_page_down, 0); break; case 'H': /* Esc [ H == Home on ANSI/VT220/FreeBSD * console/Mach console/Eterm. */ - retval = NANO_HOME_KEY; + retval = sc_seq_or(do_home, 0); break; case 'I': /* Esc [ I == PageUp on FreeBSD * console. */ - retval = NANO_PREVPAGE_KEY; + retval = sc_seq_or(do_page_up, 0); break; case 'L': /* Esc [ L == Insert on ANSI/FreeBSD * console. */ - retval = NANO_INSERTFILE_KEY; + retval = sc_seq_or(do_insertfile_void, 0); break; case 'M': /* Esc [ M == F1 on FreeBSD console. */ retval = KEY_F(1); @@ -1181,10 +1156,10 @@ int get_escape_seq_kbinput(const int *seq, size_t seq_len) retval = KEY_F(8); break; case 'U': /* Esc [ U == PageDown on Mach console. */ - retval = NANO_NEXTPAGE_KEY; + retval = sc_seq_or(do_page_down, 0); break; case 'V': /* Esc [ V == PageUp on Mach console. */ - retval = NANO_PREVPAGE_KEY; + retval = sc_seq_or(do_page_up, 0); break; case 'W': /* Esc [ W == F11 on FreeBSD console. */ retval = KEY_F(11); @@ -1193,7 +1168,7 @@ int get_escape_seq_kbinput(const int *seq, size_t seq_len) retval = KEY_F(12); break; case 'Y': /* Esc [ Y == End on Mach console. */ - retval = NANO_END_KEY; + retval = sc_seq_or(do_end, 0); break; case 'Z': /* Esc [ Z == F14 on FreeBSD console. */ retval = KEY_F(14); @@ -1250,13 +1225,13 @@ int get_escape_seq_abcd(int kbinput) { switch (tolower(kbinput)) { case 'a': - return NANO_PREVLINE_KEY; + return sc_seq_or(do_up_void, 0);; case 'b': - return NANO_NEXTLINE_KEY; + return sc_seq_or(do_down_void, 0);; case 'c': - return NANO_FORWARD_KEY; + return sc_seq_or(do_right, 0);; case 'd': - return NANO_BACK_KEY; + return sc_seq_or(do_left, 0);; default: return ERR; } @@ -1766,7 +1741,7 @@ int get_mouseinput(int *mouse_x, int *mouse_y, bool allow_shortcuts) * wheel is equivalent to moving down three lines. */ for (i = 0; i < 3; i++) unget_kbinput((mevent.bstate & BUTTON4_PRESSED) ? - NANO_PREVLINE_KEY : NANO_NEXTLINE_KEY, FALSE, + sc_seq_or(do_up_void, 0) : sc_seq_or(do_down_void, 0);, FALSE, FALSE); return 1; -- 2.39.5