When the formatter is an npx command, setcar is used to expand the
binary file path to node_modules/.bin. But setcar overwrites the
underlying list, so the expanded path is set into
apheleia-formatters. (The list was processed by remq before setcar,
but remq seems to return the cdr if only the first element is
removed.) This is undesirable because when working on multiple NPM
packages, each package may have a formatter of different version.
* Add support for rust-ts-mode
* Add new builtin go-, ruby- and yaml- treesit-modes
Modes taken from NEWS.29 emacs29 release notes
* Add new PR number to changelog entry for ts-modes
Per https://github.com/mvdan/sh/issues/963 we should not invoke shfmt
on zsh files. However, Emacs represents all shell scripts using
sh-mode, so in order to enable shfmt by default, we will need a
feature to make the usage of a formatter conditional on another
variable (in this case sh-shell). Until Apheleia supports this
feature, removing shfmt by default (it can still be enabled by the
user, or run manually).
* feat: add support for new tsx-ts-mode in emacs 29
from emacs docs:
> tsx-ts-mode is an autoloaded, interactive and natively compiled
function defined in typescript-ts-mode.el.gz.
Signature
(tsx-ts-mode)
Documentation
Major mode for editing TypeScript.
In addition to any hooks its parent mode typescript-ts-base-mode
might have run, this mode runs the hook tsx-ts-mode-hook, as the
final or penultimate step during initialization.
* update changelog
* Fix broken link in changelog
Co-authored-by: Radon Rosborough <radon@intuitiveexplanations.com>
-------
<!--
To expedite the pull request process, please see the contributor guide
for my projects:
<https://github.com/raxod502/contributor-guide>
-->
Co-authored-by: Radon Rosborough <radon@intuitiveexplanations.com>
<!--
To expedite the pull request process, please see the contributor guide
for my projects:
<https://github.com/raxod502/contributor-guide>
-->
Co-authored-by: Radon Rosborough <radon@intuitiveexplanations.com>
When formatting command is defined with symbol `inplace`, it doesn't
work.
I'm using [casey/just](https://github.com/casey/just) (v1.5.0).
It doesn't support formatting of `stdin`, but it supports in-place
formatting with command `just --unstable --fmt --justfile
/tmp/justfile`. So I've added a list to to `apheleia-formatters` custom
variable:
```elisp
(add-to-list 'apheleia-formatters
'(just . ("just" "--unstable" "--fmt" "--justfile" inplace))
"APPEND:non-nil")
```
Minimal `justfile` before formatting (there is one space before `echo`):
```make
rule:
echo test
```
Expected formatting result (there are four spaces before `echo`):
```make
rule:
echo test
```
Without this pull request there are no visible changes after
<kbd>C-u</kbd> <kbd>M-x</kbd> `apheleia-format-buffer` <kbd>RET</kbd>
`just` <kbd>RET</kbd>. When this pull request is applied, formatting
proceed as expected.
Co-authored-by: Radon Rosborough <radon@intuitiveexplanations.com>
There are just too many Elisp files that are indented in nonstandard
ways for this to be an okay default, I think. And to make matters
worse, Elisp indentation varies depending on what is loaded into the
current environment (due to macros, etc), meaning that your
indentation may become broken if you happen to edit a file with the
wrong libraries loaded.
* 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>