* fix: only process when there is output to return
scalafmt only returns stdout when there are errors, this could also help
in other cases where a formatter returns incorrectly.
Ideally, this would also be improved by basic error checking heuristics
to work out if we need to update the buffer.
* Update changelog
Co-authored-by: Radon Rosborough <radon@intuitiveexplanations.com>
Co-authored-by: Radon Rosborough <radon.neon@gmail.com>
* Use :connection-type pipe when creating local processes
This is helpful because some formatters, rather than having an option
to enable reading from stdin, simply check whether their input comes
from a pipe or terminal.
Should close#118
* Document changes
* Break long lines
* Link to PR
Co-authored-by: Radon Rosborough <radon@intuitiveexplanations.com>
* Run bean-format on stdin (fixing incorrect 'filepath use)
'filepath is supposed to indicate that the formatter doesn’t actually
read from the named file, meaning it’s safe to use on a modified
buffer.
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
* Allow formatter using 'filepath on a modified buffer
Fixes#109.
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
* Add links to changelog
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
Co-authored-by: Radon Rosborough <radon.neon@gmail.com>
* feat: add phpcs & introduce scripts/formatters
Add phpcs as a supported formatter, and include support for
apheleia-defined scripts for more troublesome formatters
* Revert Emacs version requirement
* More quoting
* Adjust language in documentation
* Thanks checkdoc, lol
Co-authored-by: Radon Rosborough <radon.neon@gmail.com>
* [#33] Support remote buffers and files
CLOSES#33
Adds support for formatting remote files.
The new `apheleia-remote-algorithm` option configures this. The default
behaviour is consistent with what we had before, with `apheleia`
aborting a formatting when dealing with a remote file/buffer.
Users can customise apheleia to run the formatter on the remote machine,
in which case any temporary files or other checks such as `npx` will be
fully handled on the remote machine.
Users can also make apheleia run the formatter on the local machine.
This works exactly like one would expect, except if the formatter
requires access to the physical file (meaning it uses 'file in
`apheleia-formatters`) because the file isn't available on the local
machine.
This PR also fixes a bug in apheleia where `input-fname` was assigned in
local let scope, instead of being returned by `apheleia--format-command`,
meaning any formatters using a 'input file weren't cleaned up after
formatting.
* Cleanup + run diffs on remote as well
* Fix diff uses correct file path for remote files
If a file being diffed is remote, but the program is being run locally,
then we create a temporary file on the current machine.
* Make a few style changes
* Drop support for Emacs 25
* Fix GitHub Actions triggers
* Don't run tests on Emacs 25 either
* Make apheleia run synchronously when running on remote
Also added a metadata field to function based formatters.
* feat: Suppress meaningless messages while formatting synchronously
Also fixed any linter complaints.
* bug: Make running formatter locally on remote buffer synchronous
More re-entrant tramp issues.
* Update apheleia.el
* review: Replace custom temp-file logic with make-nearby-temp-file
* review: Revamp functional formatter interface
* refactor: Rework remote file handling implementation
+ Reordered parameters to ensure remote always comes before callback.
+ Updated some docstrings.
* bug: Re-add apheleia--make-temp-file
We don't always want to create a temporary file on the remote, only when
apheleia-remote-algorithm is 'remote.
* bug: Prevent repeat diff-file invocation with 2 files
Previously we always made a temp-file for diffing the formatted and
unformatted buffer leading to a bug when trying to send stdin to the
formatter process. Now we only perform this check when running both
locally and remotely.
* Update changelog
Co-authored-by: Radon Rosborough <radon.neon@gmail.com>
* Define apheleia-formatter as a safe-local-variable
This adds support for variables from .dir-locals for users that are
using the setting enable-local-variables :safe or it won't ask for those
who have it set to t.
* Update changelog
Co-authored-by: Radon Rosborough <radon.neon@gmail.com>
* Rename apheleia-hide-log-buffer to apheleia-hide-log-buffers.
* Rename apheleia-verbose to apheleia-log-only-errors (note, meaning
is inverted).
* Add apheleia-hide-old-log-entries.
* Include more information in log and format it more neatly.
* Convert log buffer to special-mode and attempt to keep point at the
end (although this is not working for an undetermined reason).
* [#62] Support functions as formatters
Closes#62.
Lets you use a lisp function as a formatter. This gives apheleia a lot
more flexibility in regards to what constitutes a formatter. For example
you can now plug an external language server or another tool as a
formatter for use with apheleia.
Here's a very basic example of using indent-line-function with apheleia
after merging this commit. Note: this doesn't take into account any
special local variables in the original buffer such as lisp-body-indent.
It's really just for demonstration purposes and as a proof of concept.
```lisp
(defun apheleia-indent-region+ (orig scratch callback)
(with-current-buffer scratch
(setq-local indent-line-function
(buffer-local-value 'indent-line-function orig))
(indent-region (point-min)
(point-max))
(funcall callback scratch)))
(push '(indent-region . apheleia-indent-region+) apheleia-formatters)
(push '(elisp-mode . indent-region) apheleia-mode-alist)
(push '(lisp-interaction-mode . indent-region) apheleia-mode-alist)
```
* Fix misc-bugs + prevent race conditions
* Update docstring
* Reword a bit
* Add to README
Co-authored-by: Radon Rosborough <radon.neon@gmail.com>
* Run the same formatter in multiple buffers in parallel (#64) (#65)
Previously when apheleia formatted a buffer it created a stdout and
stderr buffer for each formatter, but it reused this buffer each time
that formatter would run. This makes sense if we only ever format one
buffer at a time (meaning we don't format a new buffer until the
previous buffer has been formatted) such as when calling
`apheleia-format-buffer` interactively (since the interval for running a
formatter is likely far below hitting a key combination for this
command). But this assumption falls apart when using `apheleia-mode` and
`apheleia--format-after-save`.
Now a lot of files could be saved, triggering the same formatters again
and again, within a short period of each other. Apheleia used to keep
track of the current formatter process and kill it when a newer
formatter is attempted, but this also kills all but the last buffer
called by `apheleia--format-after-save`.
With this commit we still have separate stdout and stderr buffers for
each formatter, but we *always* create a new one when attempting a
format. There is a new buffer type, a log buffer, which is populated
with a formatter processes stderr when it fails. We also still have a
`apheleia--current-process` variable, but instead of being global, it's
local to the current buffer being formatted. We now kill it if starting
a new format in the current buffer, but two separate buffers can call
the same formatter with no issue.
* Mark change as bugfix in changelog
* Add to docstring
* Remove no longer needed code
* Re-wrap docstring
* Remove newline
* Change spelling
* Use correct buffer when checking (buffer-size)
Co-authored-by: Radon Rosborough <radon.neon@gmail.com>
* Evaluate any non-special args in apheleia-formatters (#55)
Allows you to place snippets of elisp within a formatter command that
will be evaluated and substituted in place when apheleia decides to run
that command.
* Update apheleia.el
Co-authored-by: Radon Rosborough <radon.neon@gmail.com>
* Support multiple formatters (#31)
Closes#31
This commit makes it so apheleia can run multiple formatters one after
the other and use the resultant output to format the current buffer.
This works somewhat like a pipeline. The output of one formatter becomes
the input to the next formatter until all formatters have run and then
an RCS patch is built from the resultant output and applied to the
current buffer.
Note: For convenience we internally represent the users configuration as
a list of formatters even when it may only be one. For example if the
user has configured `(python-mode . black)` in apheleia-mode-alist then
internally we interpret that as a formatter list of `(black)` instead of
`black` as we did previously.
* Support multiple formatters (#31)
Closes#31
This commit makes it so apheleia can run multiple formatters one after
the other and use the resultant output to format the current buffer.
This works somewhat like a pipeline. The output of one formatter becomes
the input to the next formatter until all formatters have run and then
an RCS patch is built from the resultant output and applied to the
current buffer.
Note: For convenience we internally represent the users configuration as
a list of formatters even when it may only be one. For example if the
user has configured `(python-mode . black)` in apheleia-mode-alist then
internally we interpret that as a formatter list of `(black)` instead of
`black` as we did previously.
* Make some changes
* Make some changes
* Error when a (not-first) formatter uses file or filepath
* Prevent formatter recieving stdin when using `file'
Co-authored-by: Radon Rosborough <radon.neon@gmail.com>
* Fix rustfmt dumping child modules' content into file
rustfmt by default analyses all files dependent on the current file,
too. The out put of --emit stdout contain all child modules. Apheleia
would happily dump that into the currently edited buffer (even though
the content came from another file.)
The unstable option --skip-children prevents that. It's as yet
untested! I've only made a couple of quick sanity checks.
* Fix long line