tweaks: refactor the implanting of a key expansion
parent
d9ac785a07
commit
5eccaa7633
18
src/global.c
18
src/global.c
|
@ -318,11 +318,6 @@ void flip_newbuffer(void)
|
||||||
void discard_buffer(void)
|
void discard_buffer(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
#ifdef ENABLE_NANORC
|
|
||||||
void implant(void)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Add a function to the function list. */
|
/* Add a function to the function list. */
|
||||||
void add_to_funcs(void (*func)(void), int menus, const char *desc, const char *help,
|
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 */
|
#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)
|
const subnfunc *sctofunc(const sc *s)
|
||||||
{
|
{
|
||||||
subnfunc *f = allfuncs;
|
subnfunc *f = allfuncs;
|
||||||
|
|
|
@ -1728,8 +1728,8 @@ int do_input(bool allow_funcs)
|
||||||
pletion_line = NULL;
|
pletion_line = NULL;
|
||||||
#endif
|
#endif
|
||||||
#ifdef ENABLE_NANORC
|
#ifdef ENABLE_NANORC
|
||||||
if (shortcut->func == implant) {
|
if (shortcut->func == (void *)implant) {
|
||||||
execute(shortcut);
|
implant(shortcut->expansion);
|
||||||
return 42;
|
return 42;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -1756,7 +1756,7 @@ int do_input(bool allow_funcs)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
/* Execute the function of the shortcut. */
|
/* Execute the function of the shortcut. */
|
||||||
execute(shortcut);
|
shortcut->func();
|
||||||
|
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
/* When the marked region changes without Shift being held,
|
/* When the marked region changes without Shift being held,
|
||||||
|
|
|
@ -153,8 +153,8 @@ int do_statusbar_input(bool *finished)
|
||||||
shortcut->func == do_backspace))
|
shortcut->func == do_backspace))
|
||||||
;
|
;
|
||||||
#ifdef ENABLE_NANORC
|
#ifdef ENABLE_NANORC
|
||||||
else if (shortcut->func == implant)
|
else if (shortcut->func == (void *)implant)
|
||||||
execute(shortcut);
|
implant(shortcut->expansion);
|
||||||
#endif
|
#endif
|
||||||
else if (shortcut->func == do_verbatim_input)
|
else if (shortcut->func == do_verbatim_input)
|
||||||
do_statusbar_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
|
* to TRUE to indicate that we're done after running or trying to
|
||||||
* run its associated function. */
|
* run its associated function. */
|
||||||
if (!ISSET(VIEW_MODE) || sctofunc(shortcut)->viewok)
|
if (!ISSET(VIEW_MODE) || sctofunc(shortcut)->viewok)
|
||||||
execute(shortcut);
|
shortcut->func();
|
||||||
*finished = TRUE;
|
*finished = TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -318,7 +318,6 @@ char *input_tab(char *buf, bool allow_files, size_t *place,
|
||||||
|
|
||||||
/* Some functions in global.c. */
|
/* Some functions in global.c. */
|
||||||
size_t length_of_list(int menu);
|
size_t length_of_list(int menu);
|
||||||
void implant(void);
|
|
||||||
const sc *first_sc_for(int menu, void (*func)(void));
|
const sc *first_sc_for(int menu, void (*func)(void));
|
||||||
int the_code_for(void (*func)(void), int defaultval);
|
int the_code_for(void (*func)(void), int defaultval);
|
||||||
functionptrtype func_from_key(int *kbinput);
|
functionptrtype func_from_key(int *kbinput);
|
||||||
|
@ -330,7 +329,6 @@ void shortcut_init(void);
|
||||||
void set_lint_or_format_shortcuts(void);
|
void set_lint_or_format_shortcuts(void);
|
||||||
void set_spell_shortcuts(void);
|
void set_spell_shortcuts(void);
|
||||||
#endif
|
#endif
|
||||||
void execute(const sc *shortcut);
|
|
||||||
const subnfunc *sctofunc(const sc *s);
|
const subnfunc *sctofunc(const sc *s);
|
||||||
const char *flagtostr(int flag);
|
const char *flagtostr(int flag);
|
||||||
sc *strtosc(const char *input);
|
sc *strtosc(const char *input);
|
||||||
|
@ -624,6 +622,9 @@ void run_macro(void);
|
||||||
size_t get_key_buffer_len(void);
|
size_t get_key_buffer_len(void);
|
||||||
void put_back(int keycode);
|
void put_back(int keycode);
|
||||||
void unget_kbinput(int kbinput, bool metakey);
|
void unget_kbinput(int kbinput, bool metakey);
|
||||||
|
#ifdef ENABLE_NANORC
|
||||||
|
void implant(const char *string);
|
||||||
|
#endif
|
||||||
int get_kbinput(WINDOW *win, bool showcursor);
|
int get_kbinput(WINDOW *win, bool showcursor);
|
||||||
int parse_kbinput(WINDOW *win);
|
int parse_kbinput(WINDOW *win);
|
||||||
int arrow_from_abcd(int kbinput);
|
int arrow_from_abcd(int kbinput);
|
||||||
|
|
|
@ -338,7 +338,7 @@ bool is_universal(void (*func)(void))
|
||||||
func == do_prev_word_void || func == do_next_word_void ||
|
func == do_prev_word_void || func == do_next_word_void ||
|
||||||
#endif
|
#endif
|
||||||
#ifdef ENABLE_NANORC
|
#ifdef ENABLE_NANORC
|
||||||
func == implant ||
|
func == (void *)implant ||
|
||||||
#endif
|
#endif
|
||||||
func == do_delete || func == do_backspace ||
|
func == do_delete || func == do_backspace ||
|
||||||
func == do_cut_text_void || func == do_uncut_text ||
|
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. */
|
* otherwise it is the name of a function. */
|
||||||
if (*funcptr == '"') {
|
if (*funcptr == '"') {
|
||||||
newsc = nmalloc(sizeof(sc));
|
newsc = nmalloc(sizeof(sc));
|
||||||
newsc->func = implant;
|
newsc->func = (void *)implant;
|
||||||
newsc->expansion = mallocstrcpy(NULL, funcptr + 1);
|
newsc->expansion = mallocstrcpy(NULL, funcptr + 1);
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
newsc->toggle = 0;
|
newsc->toggle = 0;
|
||||||
|
|
|
@ -286,6 +286,15 @@ void unget_kbinput(int kbinput, bool metakey)
|
||||||
put_back(ESC_CODE);
|
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
|
/* 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
|
* 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
|
* codes from win and add them to the keystroke buffer before doing
|
||||||
|
|
Loading…
Reference in New Issue