[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Nano-devel] [PATCH] dropping a feature: remove the ability to use the '
From: |
Benno Schulenberg |
Subject: |
[Nano-devel] [PATCH] dropping a feature: remove the ability to use the 'formatter' command |
Date: |
Tue, 10 Jul 2018 16:34:44 +0200 |
Since the last version, the user can filter an entire buffer through
an external command. This external command can also be a formatting
program, so there is no longer any need for this specific and special
formatter command.
---
doc/nano.texi | 10 +----
doc/nanorc.5 | 9 +---
src/global.c | 23 ++--------
src/proto.h | 5 +--
src/text.c | 113 --------------------------------------------------
src/winio.c | 7 ++--
6 files changed, 13 insertions(+), 154 deletions(-)
diff --git a/doc/nano.texi b/doc/nano.texi
index 5f2267ea..fd9911fa 100644
--- a/doc/nano.texi
+++ b/doc/nano.texi
@@ -993,11 +993,6 @@ on the system and will be silently ignored otherwise.)
Use the given @var{program} to do a syntax check on the current buffer.
(This overrides the speller function.)
address@hidden formatter @var{program} address@hidden @dots{}]
-Use the given @var{program} to automatically reformat the text in
-the current buffer --- useful for a programming language like Go.
-(This overrides the speller and linter functions.)
-
@item comment "@var{string}"
Use the given string for commenting and uncommenting lines.
If the string contains a vertical bar or pipe character (@t{|}),
@@ -1041,8 +1036,7 @@ to @code{icolor}.
@item extendsyntax @var{name} @var{command} address@hidden @dots{}]
Extend the syntax previously defined as "@var{name}" with another
@var{command}.
This allows you to add a new @code{color}, @code{icolor}, @code{header},
address@hidden, @code{comment}, @code{linter}, or @code{formatter} command
-to an already
address@hidden, @code{comment}, or @code{linter} command to an already
defined syntax --- useful when you want to slightly improve a syntax defined
in one of the system-installed files (which normally are not writable).
@@ -1162,7 +1156,7 @@ Shows the current cursor position: the line, column, and
character positions.
Counts the number of words, lines and characters in the current buffer.
@item speller
-Invokes a spell-checking program (or linting program, or formatter program,
+Invokes a spell-checking program (or linting program,
if the active syntax defines such a thing).
@item justify
diff --git a/doc/nanorc.5 b/doc/nanorc.5
index 12a9fd73..1b6d5956 100644
--- a/doc/nanorc.5
+++ b/doc/nanorc.5
@@ -345,11 +345,6 @@ system and will be silently ignored otherwise.)
Use the given \fIprogram\fR to run a syntax check on the current buffer.
(This overrides the speller function.)
.TP
-.BI formatter " program " \fR[ "arg " \fR...]
-Use the given \fIprogram\fR to automatically reformat the text in
-the current buffer -- useful in a programming language like Go.
-(This overrides the speller and linter functions.)
-.TP
.BI "comment """ string """
Use the given \fIstring\fR for commenting and uncommenting lines.
If the string contains a vertical bar or pipe character (\fB|\fR),
@@ -395,7 +390,7 @@ to \fBicolor\fP.
.BI extendsyntax " name command " \fR[ "arg " \fR...]
Extend the syntax previously defined as \fIname\fR with another
\fIcommand\fR. This allows adding a new \fBcolor\fP, \fBicolor\fP,
-\fBheader\fP, \fBmagic\fP, \fBcomment\fP, \fBlinter\fP, or \fBformatter\fP
+\fBheader\fP, \fBmagic\fP, \fBcomment\fP, or \fBlinter\fP
command to an already defined syntax -- useful when you want to
slightly improve a syntax defined in one of the system-installed
files (which normally are not writable).
@@ -510,7 +505,7 @@ Shows the current cursor position: the line, column, and
character positions.
Counts the number of words, lines and characters in the current buffer.
.TP
.B speller
-Invokes a spell-checking program (or linting program, or formatter program,
+Invokes a spell-checking program (or linting program,
if the active syntax defines such a thing).
.TP
.B linter
diff --git a/src/global.c b/src/global.c
index fc5fad35..1453a20a 100644
--- a/src/global.c
+++ b/src/global.c
@@ -675,9 +675,6 @@ void shortcut_init(void)
const char *lint_gist = N_("Invoke the linter, if available");
const char *prevlint_gist = N_("Go to previous linter msg");
const char *nextlint_gist = N_("Go to next linter msg");
-#ifdef ENABLE_SPELLER
- const char *formatter_gist = N_("Invoke formatter, if available");
-#endif
#endif
#endif /* ENABLE_HELP */
@@ -783,10 +780,6 @@ void shortcut_init(void)
#ifdef ENABLE_COLOR
add_to_funcs(do_linter, MMAIN,
N_("To Linter"), WITHORSANS(lint_gist),
TOGETHER, NOVIEW);
-#ifdef ENABLE_SPELLER
- add_to_funcs(do_formatter, MMAIN,
- N_("Formatter"), WITHORSANS(formatter_gist),
BLANKAFTER, NOVIEW);
-#endif
#endif
}
@@ -1379,21 +1372,14 @@ void replace_scs_for(void (*oldfunc)(void), void
(*newfunc)(void))
s->func = newfunc;
}
-void set_lint_or_format_shortcuts(void)
+void set_linter_shortcut(void)
{
- if (openfile->syntax->formatter) {
- replace_scs_for(do_spell, do_formatter);
- replace_scs_for(do_linter, do_formatter);
- } else {
- replace_scs_for(do_spell, do_linter);
- replace_scs_for(do_formatter, do_linter);
- }
+ replace_scs_for(do_spell, do_linter);
}
-void set_spell_shortcuts(void)
+void set_speller_shortcut(void)
{
- replace_scs_for(do_formatter, do_spell);
- replace_scs_for(do_linter, do_spell);
+ replace_scs_for(do_linter, do_spell);
}
#endif /* ENABLE_COLOR && ENABLE_SPELLER */
@@ -1825,7 +1811,6 @@ void thanks_for_all_the_fish(void)
free(sint->name);
free(sint->linter);
- free(sint->formatter);
while (sint->extensions != NULL) {
regexlisttype *item = sint->extensions;
diff --git a/src/proto.h b/src/proto.h
index 02c639ef..6d397c11 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -322,8 +322,8 @@ void assign_keyinfo(sc *s, const char *keystring, const int
keycode);
void print_sclist(void);
void shortcut_init(void);
#ifdef ENABLE_COLOR
-void set_lint_or_format_shortcuts(void);
-void set_spell_shortcuts(void);
+void set_linter_shortcut(void);
+void set_speller_shortcut(void);
#endif
const subnfunc *sctofunc(const sc *s);
const char *flagtostr(int flag);
@@ -558,7 +558,6 @@ void do_spell(void);
#endif
#ifdef ENABLE_COLOR
void do_linter(void);
-void do_formatter(void);
#endif
#ifndef NANO_TINY
void do_wordlinechar_count(void);
diff --git a/src/text.c b/src/text.c
index 8ed330d3..b1277437 100644
--- a/src/text.c
+++ b/src/text.c
@@ -3310,119 +3310,6 @@ void do_linter(void)
free(tmplint);
}
}
-
-#ifdef ENABLE_SPELLER
-/* Run a formatter for the current syntax. This expects the formatter
- * to be non-interactive and operate on a file in-place, which we'll
- * pass it on the command line. */
-void do_formatter(void)
-{
- bool status;
- FILE *temp_file;
- int format_status;
- ssize_t lineno_save = openfile->current->lineno;
- size_t current_x_save = openfile->current_x;
- size_t pww_save = openfile->placewewant;
- bool was_at_eol = (openfile->current->data[openfile->current_x] ==
'\0');
- pid_t pid_format;
- static char **formatargs = NULL;
- char *temp, *finalstatus = NULL;
-
- if (openfile->totsize == 0) {
- statusbar(_("Finished"));
- return;
- }
-
- temp = safe_tempfile(&temp_file);
-
- if (temp == NULL) {
- statusline(ALERT, _("Error writing temp file: %s"),
strerror(errno));
- return;
- }
-
-#ifndef NANO_TINY
- /* We're not supporting partial formatting, oi vey. */
- openfile->mark = NULL;
-#endif
- status = write_file(temp, temp_file, TRUE, OVERWRITE, TRUE);
-
- if (!status) {
- statusline(ALERT, _("Error writing temp file: %s"),
strerror(errno));
- free(temp);
- return;
- }
-
- blank_bottombars();
- statusbar(_("Invoking formatter, please wait"));
-
- construct_argument_list(&formatargs, openfile->syntax->formatter, temp);
-
- /* Start a new process for the formatter. */
- if ((pid_format = fork()) == 0) {
- /* Start the formatting program; we are using $PATH. */
- execvp(formatargs[0], formatargs);
-
- /* Should not be reached, if the formatter is found! */
- exit(1);
- }
-
- /* If we couldn't fork, get out. */
- if (pid_format < 0) {
- statusbar(_("Could not fork"));
- unlink(temp);
- free(temp);
- return;
- }
-
-#ifndef NANO_TINY
- /* Block SIGWINCHes so the formatter doesn't get any. */
- allow_sigwinch(FALSE);
-#endif
-
- /* Wait for the formatter to finish. */
- wait(&format_status);
-
- if (!WIFEXITED(format_status) || WEXITSTATUS(format_status) != 0)
- finalstatus = invocation_error(openfile->syntax->formatter);
- else {
- /* Replace the text of the current buffer with the formatted
text. */
- replace_buffer(temp);
-
- /* Restore the cursor position. */
- goto_line_posx(lineno_save, current_x_save);
- if (was_at_eol || openfile->current_x >
strlen(openfile->current->data))
- openfile->current_x = strlen(openfile->current->data);
- openfile->placewewant = pww_save;
- adjust_viewport(STATIONARY);
-
- set_modified();
-
-#ifndef NANO_TINY
- /* Flush the undo stack, to avoid a mess or crash when
- * the user tries to undo things in reformatted lines. */
- discard_until(NULL, openfile, FALSE);
-#endif
- finalstatus = _("Finished formatting");
- }
-
- unlink(temp);
- free(temp);
-
-#ifndef NANO_TINY
- /* Unblock SIGWINCHes again. */
- allow_sigwinch(TRUE);
-#endif
-
- statusbar(finalstatus);
-
- /* If there were error messages, allow the user some time to read them.
*/
- if (WIFEXITED(format_status) && WEXITSTATUS(format_status) == 2)
- sleep(4);
-
- /* If there were any messages, clear them off. */
- total_refresh();
-}
-#endif /* ENABLE_SPELLER */
#endif /* ENABLE_COLOR */
#ifndef NANO_TINY
diff --git a/src/winio.c b/src/winio.c
index 281488a8..fcb82721 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -3312,11 +3312,10 @@ void total_refresh(void)
void display_main_list(void)
{
#if defined(ENABLE_COLOR) && defined(ENABLE_SPELLER)
- if (openfile->syntax &&
- (openfile->syntax->formatter ||
openfile->syntax->linter))
- set_lint_or_format_shortcuts();
+ if (openfile->syntax && openfile->syntax->linter)
+ set_linter_shortcut();
else
- set_spell_shortcuts();
+ set_speller_shortcut();
#endif
bottombars(MMAIN);
--
2.17.1
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Nano-devel] [PATCH] dropping a feature: remove the ability to use the 'formatter' command,
Benno Schulenberg <=