dropping a feature: remove the ability to use the 'formatter' command
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.
Этот коммит содержится в:
родитель
94b4f07281
Коммит
975b491235
@ -986,11 +986,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.)
|
||||
|
||||
@item formatter @var{program} [@var{arg} @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{|}),
|
||||
@ -1034,8 +1029,7 @@ to @code{icolor}.
|
||||
@item extendsyntax @var{name} @var{command} [@var{arg} @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},
|
||||
@code{magic}, @code{comment}, @code{linter}, or @code{formatter} command
|
||||
to an already
|
||||
@code{magic}, @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).
|
||||
|
||||
@ -1164,7 +1158,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
|
||||
|
@ -341,11 +341,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),
|
||||
@ -391,7 +386,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).
|
||||
@ -514,7 +509,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
|
||||
|
23
src/global.c
23
src/global.c
@ -655,9 +655,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 */
|
||||
|
||||
@ -754,10 +751,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
|
||||
}
|
||||
|
||||
@ -1349,21 +1342,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 */
|
||||
|
||||
@ -1795,7 +1781,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;
|
||||
|
@ -229,8 +229,6 @@ typedef struct syntaxtype {
|
||||
/* The list of libmagic results that this syntax applies to. */
|
||||
char *linter;
|
||||
/* The command with which to lint this type of file. */
|
||||
char *formatter;
|
||||
/* The formatting command (for programming languages mainly). */
|
||||
#ifdef ENABLE_COMMENT
|
||||
char *comment;
|
||||
/* The line comment prefix (and postfix) for this type of file. */
|
||||
|
@ -323,8 +323,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);
|
||||
@ -555,7 +555,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);
|
||||
|
@ -300,7 +300,6 @@ void parse_syntax(char *ptr)
|
||||
live_syntax->headers = NULL;
|
||||
live_syntax->magics = NULL;
|
||||
live_syntax->linter = NULL;
|
||||
live_syntax->formatter = NULL;
|
||||
#ifdef ENABLE_COMMENT
|
||||
live_syntax->comment = mallocstrcpy(NULL, GENERAL_COMMENT_CHARACTER);
|
||||
#endif
|
||||
@ -834,7 +833,7 @@ void grab_and_store(const char *kind, char *ptr, regexlisttype **storage)
|
||||
}
|
||||
}
|
||||
|
||||
/* Gather and store the string after a comment/linter/formatter command. */
|
||||
/* Gather and store the string after a comment/linter command. */
|
||||
void pick_up_name(const char *kind, char *ptr, char **storage)
|
||||
{
|
||||
if (!opensyntax) {
|
||||
@ -985,12 +984,6 @@ void parse_rcfile(FILE *rcstream, bool syntax_only)
|
||||
parse_colors(ptr, NANO_REG_EXTENDED | REG_ICASE);
|
||||
else if (strcasecmp(keyword, "linter") == 0)
|
||||
pick_up_name("linter", ptr, &live_syntax->linter);
|
||||
else if (strcasecmp(keyword, "formatter") == 0)
|
||||
#ifdef ENABLE_SPELLER
|
||||
pick_up_name("formatter", ptr, &live_syntax->formatter);
|
||||
#else
|
||||
;
|
||||
#endif
|
||||
else if (syntax_only && (strcasecmp(keyword, "set") == 0 ||
|
||||
strcasecmp(keyword, "unset") == 0 ||
|
||||
strcasecmp(keyword, "bind") == 0 ||
|
||||
|
113
src/text.c
113
src/text.c
@ -3303,119 +3303,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
|
||||
|
@ -3334,11 +3334,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);
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user