tweaks: refactor the implanting of a key expansion

This commit is contained in:
Benno Schulenberg 2018-02-27 13:34:32 +01:00
parent d9ac785a07
commit 5eccaa7633
6 changed files with 20 additions and 28 deletions

View File

@ -318,11 +318,6 @@ void flip_newbuffer(void)
void discard_buffer(void)
{
}
#ifdef ENABLE_NANORC
void implant(void)
{
}
#endif
/* Add a function to the function list. */
void add_to_funcs(void (*func)(void), int menus, const char *desc, const char *help,
@ -1386,19 +1381,6 @@ void set_spell_shortcuts(void)
}
#endif /* ENABLE_COLOR && ENABLE_SPELLER */
/* Execute the function of the given shortcut. */
void execute(const sc *shortcut)
{
#ifdef ENABLE_NANORC
if (shortcut->func == implant)
/* Insert the corresponding string into the keyboard buffer. */
for (int i = strlen(shortcut->expansion); i > 0; i--)
put_back(shortcut->expansion[i - 1]);
else
#endif
shortcut->func();
}
const subnfunc *sctofunc(const sc *s)
{
subnfunc *f = allfuncs;

View File

@ -1728,8 +1728,8 @@ int do_input(bool allow_funcs)
pletion_line = NULL;
#endif
#ifdef ENABLE_NANORC
if (shortcut->func == implant) {
execute(shortcut);
if (shortcut->func == (void *)implant) {
implant(shortcut->expansion);
return 42;
}
#endif
@ -1756,7 +1756,7 @@ int do_input(bool allow_funcs)
}
#endif
/* Execute the function of the shortcut. */
execute(shortcut);
shortcut->func();
#ifndef NANO_TINY
/* When the marked region changes without Shift being held,

View File

@ -153,8 +153,8 @@ int do_statusbar_input(bool *finished)
shortcut->func == do_backspace))
;
#ifdef ENABLE_NANORC
else if (shortcut->func == implant)
execute(shortcut);
else if (shortcut->func == (void *)implant)
implant(shortcut->expansion);
#endif
else if (shortcut->func == do_verbatim_input)
do_statusbar_verbatim_input();
@ -172,7 +172,7 @@ int do_statusbar_input(bool *finished)
* to TRUE to indicate that we're done after running or trying to
* run its associated function. */
if (!ISSET(VIEW_MODE) || sctofunc(shortcut)->viewok)
execute(shortcut);
shortcut->func();
*finished = TRUE;
}
}

View File

@ -318,7 +318,6 @@ char *input_tab(char *buf, bool allow_files, size_t *place,
/* Some functions in global.c. */
size_t length_of_list(int menu);
void implant(void);
const sc *first_sc_for(int menu, void (*func)(void));
int the_code_for(void (*func)(void), int defaultval);
functionptrtype func_from_key(int *kbinput);
@ -330,7 +329,6 @@ void shortcut_init(void);
void set_lint_or_format_shortcuts(void);
void set_spell_shortcuts(void);
#endif
void execute(const sc *shortcut);
const subnfunc *sctofunc(const sc *s);
const char *flagtostr(int flag);
sc *strtosc(const char *input);
@ -624,6 +622,9 @@ void run_macro(void);
size_t get_key_buffer_len(void);
void put_back(int keycode);
void unget_kbinput(int kbinput, bool metakey);
#ifdef ENABLE_NANORC
void implant(const char *string);
#endif
int get_kbinput(WINDOW *win, bool showcursor);
int parse_kbinput(WINDOW *win);
int arrow_from_abcd(int kbinput);

View File

@ -338,7 +338,7 @@ bool is_universal(void (*func)(void))
func == do_prev_word_void || func == do_next_word_void ||
#endif
#ifdef ENABLE_NANORC
func == implant ||
func == (void *)implant ||
#endif
func == do_delete || func == do_backspace ||
func == do_cut_text_void || func == do_uncut_text ||
@ -421,7 +421,7 @@ void parse_binding(char *ptr, bool dobind)
* otherwise it is the name of a function. */
if (*funcptr == '"') {
newsc = nmalloc(sizeof(sc));
newsc->func = implant;
newsc->func = (void *)implant;
newsc->expansion = mallocstrcpy(NULL, funcptr + 1);
#ifndef NANO_TINY
newsc->toggle = 0;

View File

@ -286,6 +286,15 @@ void unget_kbinput(int kbinput, bool metakey)
put_back(ESC_CODE);
}
#ifdef ENABLE_NANORC
/* Insert the given string into the keyboard buffer. */
void implant(const char *string)
{
for (int i = strlen(string); i > 0; i--)
put_back(string[i - 1]);
}
#endif
/* Try to read input_len codes from the keystroke buffer. If the
* keystroke buffer is empty and win isn't NULL, try to read in more
* codes from win and add them to the keystroke buffer before doing