[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/2] general: make five tools accessible through the Execute-Comm
From: |
Benno Schulenberg |
Subject: |
[PATCH 1/2] general: make five tools accessible through the Execute-Command prompt |
Date: |
Fri, 22 May 2020 14:45:23 +0200 |
Instead of creating a special Tools menu (which would be strange and
unlike anything that nano currently has), add the five functions that
affect the whole buffer to the Execute-Command prompt. 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 be a two-keystroke function.
---
src/cut.c | 2 ++
src/files.c | 6 ++++++
src/global.c | 37 ++++++++++++++++++++++++++++++-------
src/proto.h | 2 ++
src/text.c | 9 +++++++++
5 files changed, 49 insertions(+), 7 deletions(-)
diff --git a/src/cut.c b/src/cut.c
index 435a9919..c6fb451b 100644
--- a/src/cut.c
+++ b/src/cut.c
@@ -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
&&
diff --git a/src/files.c b/src/files.c
index 8eb46a31..dde7ac55 100644
--- a/src/files.c
+++ b/src/files.c
@@ -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. */
diff --git a/src/global.c b/src/global.c
index 309933f2..0cbe4dfc 100644
--- a/src/global.c
+++ b/src/global.c
@@ -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;
@@ -849,11 +852,6 @@ void shortcut_init(void)
add_to_funcs(flip_goto, MWHEREIS,
N_("Go To Line"), WITHORSANS(gotoline_gist), TOGETHER, 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. */
@@ -1053,6 +1051,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_("Spelling"), 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
+#if defined(ENABLE_COLOR) && defined(ENABLE_SPELLER)
+ 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);
@@ -1092,10 +1107,13 @@ void shortcut_init(void)
N_("Execute Command"), WITHORSANS(execute_gist),
TOGETHER, NOVIEW);
add_to_funcs(flip_pipe, MEXECUTE,
- N_("Pipe Text"), WITHORSANS(pipe_gist), TOGETHER,
NOVIEW);
+ 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
@@ -1165,11 +1183,14 @@ 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);
#ifdef ENABLE_SPELLER
add_to_sclist(MMAIN, "M-F", 0, do_formatter, 0);
+ add_to_sclist(MEXECUTE, "^O", 0, do_formatter, 0);
#endif
#endif
add_to_sclist(MMAIN, "^C", 0, do_cursorpos_void, 0);
@@ -1307,11 +1328,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);
diff --git a/src/proto.h b/src/proto.h
index 78172809..afe1bc6a 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -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;
diff --git a/src/text.c b/src/text.c
index 088f3012..44d5e3c3 100644
--- a/src/text.c
+++ b/src/text.c
@@ -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;
@@ -2879,6 +2886,8 @@ void do_formatter(void)
bool okay = FALSE;
const char *result_msg;
+ ran_a_tool = TRUE;
+
if (in_restricted_mode())
return;
--
2.25.4
- [PATCH 1/2] general: make five tools accessible through the Execute-Command prompt,
Benno Schulenberg <=