Commit graph

112 commits

Author SHA1 Message Date
Ellis Kenyő
e01ced3ac9
Guard against missing formatters (#126)
Fixes #122
2022-09-11 09:18:30 +01:00
Radon Rosborough
46d373f4bd
[#103] Specify --parser in Prettier (#107)
Closes #103
2022-09-10 17:24:54 -07:00
Ellis Kenyő
8ff45766fa
Ignore narrowed buffers (#127)
Fixes #124

Co-authored-by: Radon Rosborough <radon@intuitiveexplanations.com>
Co-authored-by: Radon Rosborough <radon.neon@gmail.com>
2022-09-10 17:06:06 -07:00
Ellis Kenyő
4555ace65b
Only format when the buffer is live (#125)
* fix: only format when the buffer is live

Fixes #123

* Update changelog

Co-authored-by: Radon Rosborough <radon@intuitiveexplanations.com>
2022-09-10 16:37:13 -07:00
Ellis Kenyő
9b745df2fa
Add emacs-lisp formatting (#102)
* feat: add emacs-lisp formatting

* Disable indent-tabs-mode

* Add stub file for installation

* Fix lint errors

* fix: correctly format based on previous mode

* Formatting

* Fix weird indent

* Add checkindent target

* Update changelog

* Long line

* Empty commit

* fix ci

* revert changelog reformatting

* more changelog

* more

Co-authored-by: Radon Rosborough <radon.neon@gmail.com>
Co-authored-by: Radon Rosborough <radon@intuitiveexplanations.com>
2022-09-03 11:22:35 -07:00
Ellis Kenyő
4d59a9b696
Add elm-format (#100)
* feat: add elm-format

* fix: master => main

* Update elm-format.bash

Co-authored-by: Radon Rosborough <radon.neon@gmail.com>
2022-09-03 10:57:40 -07:00
Ellis Kenyő
04366a90df
Only process when there is output to return (#116)
* 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>
2022-08-21 15:21:21 -07:00
Leo Gaskin
ebb62564a8
Use :connection-type pipe when creating local processes (#119)
* 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>
2022-08-21 14:47:20 -07:00
Anders Kaseorg
0c5e40e8bc
Allow formatter using 'filepath on a modified buffer (#110)
* 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>
2022-08-14 16:28:01 -07:00
Ellis Kenyő
ac6f733d7b
Add bean-format (#101)
* feat: add bean-format

* fix: apt => apt-get

Co-authored-by: Radon Rosborough <radon.neon@gmail.com>

* fix: pip => pip3

Co-authored-by: Radon Rosborough <radon.neon@gmail.com>

* Update changelog

Co-authored-by: Radon Rosborough <radon.neon@gmail.com>
2022-06-20 14:51:17 -07:00
Kisaragi Hiu
2fa9dd97ed
Add stylua (#105) 2022-06-20 14:21:27 -07:00
Radon Rosborough
67853e98b1 Use spaces instead of tabs in shfmt 2022-06-04 15:39:09 -07:00
Radon Rosborough
18ccacc5cf Release version 3.0 2022-06-01 10:37:53 -07:00
michzappa
cececba08f
Add nixfmt (#98)
* Add nixfmt

* Update CHANGELOG.md

* Update CHANGELOG.md

* Update CHANGELOG.md

Co-authored-by: Radon Rosborough <radon.neon@gmail.com>
2022-05-15 21:36:47 -07:00
Ellis Kenyő
363d634c5c
Add ktlint (#97)
* feat: add ktlint

* Apply suggestions from code review

Co-authored-by: Radon Rosborough <radon.neon@gmail.com>
2022-05-13 09:23:57 -07:00
Ellis Kenyő
b5dbab53ea
Add shfmt (#90)
* feat: add shfmt

Add support for shfmt

* Handle multiple architectures

Co-authored-by: Radon Rosborough <radon.neon@gmail.com>
2022-05-12 12:52:57 -07:00
Ellis Kenyő
982df5a2e0
Add phpcs & introduce scripts/formatters (#87)
* 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>
2022-05-11 16:26:33 -07:00
Ellis Kenyő
83179060f2
Use ocamlformat for caml-mode too (#94)
* fix: use ocamlformat for caml-mode too

* Update changelog

Co-authored-by: Radon Rosborough <radon.neon@gmail.com>
2022-05-11 16:26:22 -07:00
Radon Rosborough
a0737fd695 Update to reflect IP transfer 2022-05-09 15:58:41 -07:00
dalu
50da8cd1a9
Dart format support (#89)
* Dart format support

* fix: different architexture

* Update changelog

* Improve installation

Co-authored-by: Radon Rosborough <radon.neon@gmail.com>
2022-05-01 14:51:27 -07:00
Radon Rosborough
9804f241ac [#86] Update outdated docstring
Closes #86
2022-04-17 11:59:32 -07:00
Mohsin Kaleem
806210414b
Support formatting remote files with Tramp (#76)
* [#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>
2022-04-10 14:21:50 -07:00
Radon Rosborough
84b04329d7 Release version 2.0 2022-04-10 13:54:40 -07:00
Terje Larsen
75074a2f11
Define apheleia-formatter as a safe-local-variable (#74)
* 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>
2022-01-14 15:29:26 -08:00
Radon Rosborough
53f243b111
Add formatter tests (#72)
Closes #24
Builds on #25 by @PrimaryCanary
2022-01-05 15:35:12 -08:00
Radon Rosborough
41fa1f70ee [#58] Do not change the mode when saving
Closes #58
2022-01-04 21:07:17 -08:00
Radon Rosborough
c073299a56 [#52] Fix handling of non-file buffers 2022-01-04 20:57:39 -08:00
Radon Rosborough
4da2898ffd Fix broken handling of filepath 2022-01-04 20:51:29 -08:00
Radon Rosborough
cbffa9298c [#23] Support in-place formatters 2022-01-04 16:21:10 -08:00
Radon Rosborough
826d462bd5 [#47] Clean up stderr processes 2022-01-04 16:08:28 -08:00
Radon Rosborough
a7e1b82777 [#46] Add apheleia-goto-error 2022-01-04 15:56:12 -08:00
Radon Rosborough
38fb69019f [#69] More logging improvements, new hook 2022-01-04 15:32:38 -08:00
Radon Rosborough
54844c3988 [#69] Improvements to Apheleia logging
* 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).
2022-01-03 20:12:52 -08:00
Radon Rosborough
e1dbc1b1c0 [#68] Add fish-indent 2022-01-02 16:51:44 -08:00
Radon Rosborough
38fb75d6c8 Alphabetize 2022-01-02 16:50:26 -08:00
Radon Rosborough
d3304b018c Fix rustfmt, show log by default 2022-01-02 16:41:20 -08:00
Radon Rosborough
cb8823dab7 Merge tag 'v1.2' 2021-12-27 20:23:35 -08:00
Radon Rosborough
443f5aeb1a Release version 1.2 2021-12-27 20:21:35 -08:00
Radon Rosborough
f0309b17bb [#60] Get coding-system from stdin conditionally 2021-12-27 12:35:58 -08:00
Mohsin Kaleem
2e98165137
[#62] Support functions as formatters (#63)
* [#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>
2021-12-27 10:00:21 -08:00
Mohsin Kaleem
e700c78a5d
Run the same formatter in multiple buffers in parallel (#64) (#65) (#65)
* 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>
2021-12-26 12:52:52 -08:00
Mohsin Kaleem
2cf903e9a2
Support non-file buffers (#52) (#59)
* Support non-file buffers (#52)

Closes #52

* Apply suggestions from code review

* Oops, my bad

Co-authored-by: Radon Rosborough <radon.neon@gmail.com>
2021-11-21 10:45:50 -08:00
Radon Rosborough
8e0605cc29 [#58] Don't run clang-format in php-mode 2021-11-15 17:32:48 -08:00
Radon Rosborough
5b36008ed6 Enable clang-format in c++-mode too 2021-11-04 20:56:14 -07:00
Mohsin Kaleem
1b7f2cf996
Evaluate any non-special args in apheleia-formatters (#55) (#56)
* 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>
2021-10-31 10:57:44 -07:00
Asif Mahmud Shimon
0c88ad95b8
strip trailing CR (#54)
* strip trailing CR

* updated changelog for pr #54

Co-authored-by: Asif Mahmmud Shimon <shimon.technext@gmail.com>
2021-10-31 10:55:26 -07:00
Mohsin Kaleem
1bf7db7477
Support multiple formatters (#31) (#51)
* 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>
2021-10-24 18:28:18 -07:00
Justin Smestad
8b9d576f2f
Add prettier-ruby (#49)
Co-authored-by: Radon Rosborough <radon.neon@gmail.com>
2021-10-03 11:18:03 -07:00
Justin Smestad
a1e8462dd3
Elixir support (#48)
* Add elixir formatter

* Fix format for elixir to use stdout

* Add CHANGELOG entry
2021-10-03 11:10:22 -07:00
Aleksandar Dimitrov
f46d65c179
Fix rustfmt dumping child modules' content into file (#45)
* 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
2021-10-03 11:09:38 -07:00