From 6e0c9d2e37d2611ca3d32d578f9ce6374fed6119 Mon Sep 17 00:00:00 2001 From: OIX Date: Sun, 13 Dec 2020 14:55:29 +0100 Subject: [PATCH] options: added 'hide' keyword for .nanorc to disable selected shortcut hints in bottom window there is no point in displaying shortcut hints for common ever-day-use-functions in the legend in the bottom window. especially when one has already tailored the shortcuts to his favorite keys, like Ctrl-X, Ctrl-C and Ctrl-V for cut, copy and paste etc., having these functions listed as reminders, does not make sense and consumes space for less often used functions, when a hint for the assigend shortcut key could be helpful. thus I added functionality to exclude functions from being displayed in the legend by specifying them in the .nanorc configuration file, using a new 'hide' keyword. the keyword can be followed by a space seperated list of functions, that should not be listed in the legend. the function names are the ones also used with the 'bind' keyword. multiple 'hide' lines are permitted (ie. to group functions to easily enable or disable certain types of functionality by commenting out/in their 'hide'-setting). Signed-off-by: OIX --- src/definitions.h | 9 +++++++++ src/global.c | 17 +++++++++++++++++ src/prototypes.h | 3 +++ src/rcfile.c | 24 ++++++++++++++++++++++++ src/winio.c | 5 +++++ 5 files changed, 58 insertions(+) diff --git a/src/definitions.h b/src/definitions.h index 19e1a68..d3cb890 100644 --- a/src/definitions.h +++ b/src/definitions.h @@ -111,6 +111,11 @@ #define REPLACING 1 #define INREGION 2 +#ifdef ENABLE_NANORC +#define SC_HINT TRUE /* Show a shortcut hint. */ +#define NO_SC_HINT FALSE +#endif + /* In UTF-8 a character is at most six bytes long. */ #ifdef ENABLE_UTF8 #define MAXCHARLEN 6 @@ -621,6 +626,10 @@ typedef struct funcstruct { /* Whether there should be a blank line after the help text * for this function. */ #endif +#ifdef ENABLE_NANORC + bool sc_hint; + /* Show shortcut hint for this function in bottom window? */ +#endif bool viewok; /* Is this function allowed when in view mode? */ int menus; diff --git a/src/global.c b/src/global.c index 8b2bb7a..715b686 100644 --- a/src/global.c +++ b/src/global.c @@ -369,12 +369,29 @@ void add_to_funcs(void (*func)(void), int menus, const char *desc, f->menus = menus; f->desc = desc; f->viewok = viewok; +#ifdef ENABLE_NANORC + f->sc_hint = SC_HINT; +#endif #ifdef ENABLE_HELP f->help = help; f->blank_after = blank_after; #endif } +#ifdef ENABLE_NANORC +void set_func_sc_hint(void (*func)(void), bool sc_hint) +{ + if(!allfuncs || !func) return; + + funcstruct *f = allfuncs; // definition of all functions + for(; f != NULL; f=f->next) // search for the specified one + if(f->func == func) break; + if(!f) return; // function doesn't exist + + f->sc_hint = sc_hint; +} +#endif + /* Parse the given keystring and return the corresponding keycode, * or return -1 when the string is invalid. */ int keycode_from_string(const char *keystring) diff --git a/src/prototypes.h b/src/prototypes.h index f9ac3a9..e2d2493 100644 --- a/src/prototypes.h +++ b/src/prototypes.h @@ -325,6 +325,9 @@ functionptrtype interpret(int *keycode); int keycode_from_string(const char *keystring); void shortcut_init(void); const char *flagtostr(int flag); +#ifdef ENABLE_NANORC +void set_func_sc_hint(void (*func)(void), bool sc_hint); +#endif /* Some functions in help.c. */ #ifdef ENABLE_HELP diff --git a/src/rcfile.c b/src/rcfile.c index ef41036..5641a23 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -732,6 +732,28 @@ bool is_universal(void (*func)(void)) func == do_tab || func == do_enter || func == do_verbatim_input); } +void parse_sc_hint(char *ptr) +{ + if(!ptr || *ptr=='\0') return; // ignore an empty 'hide' statement + + char *funcname; + while(*ptr!='\0') { + funcname = ptr; + ptr = parse_argument(ptr); + if(!ptr) return; // parse error + + if(funcname[0]=='"') continue; // just ignore string literals + + keystruct *sc = strtosc(funcname); + if(sc && sc->func) set_func_sc_hint(sc->func, NO_SC_HINT); + else if(sc) jot_error(N_("Cannot hide function '%s'"), funcname); + else jot_error(N_("Function '%s' does not exist"), funcname); + free(sc); + } + + return; +} + /* Bind or unbind a key combo, to or from a function. */ void parse_binding(char *ptr, bool dobind) { @@ -1481,6 +1503,8 @@ void parse_rcfile(FILE *rcstream, bool just_syntax, bool intros_only) parse_binding(ptr, TRUE); else if (strcmp(keyword, "unbind") == 0) parse_binding(ptr, FALSE); + else if (strcmp(keyword, "hide") == 0) + parse_sc_hint(ptr); else if (intros_only) jot_error(N_("Command \"%s\" not understood"), keyword); diff --git a/src/winio.c b/src/winio.c index e961ccc..604a9bc 100644 --- a/src/winio.c +++ b/src/winio.c @@ -2190,6 +2190,11 @@ void bottombars(int menu) for (f = allfuncs, index = 0; f != NULL && index < number; f = f->next) { size_t thiswidth = itemwidth; +#ifdef ENABLE_NANORC + if (f->sc_hint == NO_SC_HINT) // shortcut hint for this function + continue; // is disabled in configuration file +#endif + if ((f->menus & menu) == 0) continue; -- 2.7.4