general: make five tools accessible through the "Execute Command" menu

Instead of creating a special Tools menu, add the five functions that
affect the whole buffer to the "Execute Command" menu.  There is room
for these five functions there, and they kind of fit in because three
of them (Speller, Linter, and Formatter) actually invoke an external
command, and Full Justify could have been implemented externally, and
the destructive Cut Till End ought to have required a double keystroke
since the beginning.
master
Benno Schulenberg 2020-05-22 11:46:30 +02:00
parent 933dd567de
commit cd594b85f4
5 changed files with 48 additions and 6 deletions

View File

@ -525,6 +525,8 @@ void cut_text(void)
/* Cut from the current cursor position to the end of the file. */
void cut_till_eof(void)
{
ran_a_tool = TRUE;
if (openfile->current->data[openfile->current_x] == '\0' &&
(openfile->current->next == NULL ||
(!ISSET(NO_NEWLINES) && openfile->current_x > 0 &&

View File

@ -1086,6 +1086,9 @@ void do_insertfile(void)
/* Display newlines in filenames as ^J. */
as_an_at = FALSE;
/* Reset the flag that is set by the Spell Checker and Linter and such. */
ran_a_tool = FALSE;
while (TRUE) {
#ifndef NANO_TINY
if (execute) {
@ -1146,6 +1149,9 @@ void do_insertfile(void)
#endif
given = mallocstrcpy(given, answer);
if (ran_a_tool)
break;
#ifdef ENABLE_MULTIBUFFER
if (func == flip_newbuffer) {
/* Allow toggling only when not in view mode. */

View File

@ -52,6 +52,9 @@ bool we_are_running = FALSE;
bool more_than_one = FALSE;
/* Whether more than one buffer is or has been open. */
bool ran_a_tool = FALSE;
/* Whether a tool has been run at the Execute-Command prompt. */
bool inhelp = FALSE;
/* Whether we are in the help viewer. */
char *title = NULL;
@ -847,11 +850,6 @@ void shortcut_init(void)
add_to_funcs(flip_goto, MWHEREIS,
N_("Go To Line"), WITHORSANS(gotoline_gist), BLANKAFTER, VIEW);
#ifdef ENABLE_JUSTIFY
add_to_funcs(do_full_justify, MWHEREIS,
N_("Full Justify"), WITHORSANS(fulljustify_gist), BLANKAFTER, NOVIEW);
#endif
#ifdef ENABLE_BROWSER
add_to_funcs(goto_dir, MBROWSER,
/* TRANSLATORS: Try to keep the next seven strings at most 10 characters. */
@ -1049,6 +1047,23 @@ void shortcut_init(void)
add_to_funcs(do_savefile, MMAIN,
N_("Save"), WITHORSANS(savefile_gist), BLANKAFTER, NOVIEW);
#ifdef ENABLE_SPELLER
add_to_funcs(do_spell, MEXECUTE,
N_("Spell Check"), WITHORSANS(spell_gist), TOGETHER, NOVIEW);
#endif
#ifdef ENABLE_COLOR
add_to_funcs(do_linter, MEXECUTE,
N_("Linter"), WITHORSANS(lint_gist), BLANKAFTER, NOVIEW);
#endif
#ifdef ENABLE_JUSTIFY
add_to_funcs(do_full_justify, MEXECUTE|MWHEREIS,
N_("Full Justify"), WITHORSANS(fulljustify_gist), TOGETHER, NOVIEW);
#endif
#ifdef ENABLE_COLOR
add_to_funcs(do_formatter, MEXECUTE,
N_("Formatter"), WITHORSANS(formatter_gist), BLANKAFTER, NOVIEW);
#endif
add_to_funcs(flip_goto, MGOTOLINE,
N_("Go To Text"), WITHORSANS(whereis_gist), BLANKAFTER, VIEW);
@ -1091,7 +1106,10 @@ void shortcut_init(void)
N_("Pipe Text"), WITHORSANS(pipe_gist), BLANKAFTER, NOVIEW);
add_to_funcs(flip_execute, MEXECUTE,
N_("Read File"), WITHORSANS(readfile_gist), TOGETHER, NOVIEW);
N_("Read File"), WITHORSANS(readfile_gist), BLANKAFTER, NOVIEW);
add_to_funcs(cut_till_eof, MEXECUTE,
N_("Cut Till End"), WITHORSANS(cuttilleof_gist), BLANKAFTER, NOVIEW);
}
#endif
#ifdef ENABLE_BROWSER
@ -1161,10 +1179,13 @@ void shortcut_init(void)
#endif
#ifdef ENABLE_SPELLER
add_to_sclist(MMAIN, "^T", 0, do_spell, 0);
add_to_sclist(MEXECUTE, "^S", 0, do_spell, 0);
#endif
#ifdef ENABLE_COLOR
add_to_sclist(MMAIN, "M-B", 0, do_linter, 0);
add_to_sclist(MEXECUTE, "^L", 0, do_linter, 0);
add_to_sclist(MMAIN, "M-F", 0, do_formatter, 0);
add_to_sclist(MEXECUTE, "^O", 0, do_formatter, 0);
#endif
add_to_sclist(MMAIN, "^C", 0, do_cursorpos_void, 0);
add_to_sclist(MMAIN, "^_", 0, do_gotolinecolumn_void, 0);
@ -1301,11 +1322,13 @@ void shortcut_init(void)
add_to_sclist(MMOST, "M-V", 0, do_verbatim_input, 0);
#ifndef NANO_TINY
add_to_sclist(MMAIN, "M-T", 0, cut_till_eof, 0);
add_to_sclist(MEXECUTE, "^V", 0, cut_till_eof, 0);
add_to_sclist(MMAIN, "M-D", 0, do_wordlinechar_count, 0);
#endif
#ifdef ENABLE_JUSTIFY
if (!ISSET(VIEW_MODE))
add_to_sclist(MMAIN|MWHEREIS, "M-J", 0, do_full_justify, 0);
add_to_sclist(MEXECUTE, "^J", 0, do_full_justify, 0);
#endif
if (!ISSET(PRESERVE))
add_to_sclist(MMAIN|MBROWSER|MHELP, "^L", 0, total_refresh, 0);

View File

@ -38,6 +38,8 @@ extern bool started_curses;
extern bool we_are_running;
extern bool more_than_one;
extern bool ran_a_tool;
extern bool inhelp;
extern char *title;

View File

@ -1995,6 +1995,7 @@ void do_justify_void(void)
void do_full_justify(void)
{
do_justify(TRUE);
ran_a_tool = TRUE;
}
#endif /* ENABLE_JUSTIFY */
@ -2080,6 +2081,8 @@ bool fix_spello(const char *word)
#endif
edit_refresh();
put_cursor_at_end_of_answer();
/* Let the user supply a correctly spelled alternative. */
proceed = (do_prompt(FALSE, FALSE, MSPELL, word, NULL,
edit_refresh, _("Edit a replacement")) != -1);
@ -2473,6 +2476,8 @@ void do_spell(void)
const char *result_msg;
bool okay;
ran_a_tool = TRUE;
if (in_restricted_mode())
return;
@ -2544,6 +2549,8 @@ void do_linter(void)
lintstruct *lints = NULL, *tmplint = NULL, *curlint = NULL;
time_t last_wait = 0;
ran_a_tool = TRUE;
if (in_restricted_mode())
return;
@ -2878,6 +2885,8 @@ void do_formatter(void)
bool okay = FALSE;
const char *result_msg;
ran_a_tool = TRUE;
if (in_restricted_mode())
return;