mirror of
https://github.com/vale981/apheleia
synced 2025-03-04 17:11:40 -05:00
[#1] Allow passing filename directly to formatter
This commit is contained in:
parent
f2ae6c7f29
commit
ad5f79f5b3
1 changed files with 19 additions and 11 deletions
30
apheleia.el
30
apheleia.el
|
@ -380,6 +380,12 @@ argument, a buffer containing the output of the formatter."
|
||||||
project-dir)))))
|
project-dir)))))
|
||||||
(when (file-executable-p binary)
|
(when (file-executable-p binary)
|
||||||
(setcar command binary)))))
|
(setcar command binary)))))
|
||||||
|
(when (memq 'file command)
|
||||||
|
(setq command (mapcar (lambda (arg)
|
||||||
|
(if (eq arg 'file)
|
||||||
|
buffer-file-name
|
||||||
|
arg))
|
||||||
|
command)))
|
||||||
(when (memq 'input command)
|
(when (memq 'input command)
|
||||||
(let ((input-fname (make-temp-file
|
(let ((input-fname (make-temp-file
|
||||||
"apheleia" nil
|
"apheleia" nil
|
||||||
|
@ -411,7 +417,7 @@ argument, a buffer containing the output of the formatter."
|
||||||
|
|
||||||
(defcustom apheleia-formatters
|
(defcustom apheleia-formatters
|
||||||
'((black . ("black" "-"))
|
'((black . ("black" "-"))
|
||||||
(prettier . (npx "prettier" input))
|
(prettier . (npx "prettier" file))
|
||||||
(gofmt . ("gofmt")))
|
(gofmt . ("gofmt")))
|
||||||
"Alist of code formatting commands.
|
"Alist of code formatting commands.
|
||||||
The keys may be any symbols you want, and the values are
|
The keys may be any symbols you want, and the values are
|
||||||
|
@ -515,16 +521,18 @@ buffer. With a prefix argument, prompt always.
|
||||||
In Lisp code, COMMAND is similar to what you pass to
|
In Lisp code, COMMAND is similar to what you pass to
|
||||||
`make-process', except as follows. Normally, the contents of the
|
`make-process', except as follows. Normally, the contents of the
|
||||||
current buffer are passed to the command on stdin, and the output
|
current buffer are passed to the command on stdin, and the output
|
||||||
is read from stdout. However, if you use the symbol `input' as
|
is read from stdout. However, if you use the symbol `file' as one
|
||||||
one of the elements of COMMAND, then the contents of the current
|
of the elements of COMMAND, then the filename of the current
|
||||||
buffer are written to a temporary file and its name is
|
buffer is substituted for it. If you instead use the symbol
|
||||||
substituted for `input'. Also, if you use the symbol `output' as
|
`input' as one of the elements of COMMAND, then the contents of
|
||||||
one of the elements of COMMAND, then it is substituted with the
|
the current buffer are written to a temporary file and its name
|
||||||
name of a temporary file. In that case, it is expected that the
|
is substituted for `input'. Also, if you use the symbol `output'
|
||||||
command writes to that file, and the file is then read into an
|
as one of the elements of COMMAND, then it is substituted with
|
||||||
Emacs buffer. Finally, if you use the symbol `npx' as one of the
|
the name of a temporary file. In that case, it is expected that
|
||||||
elements of COMMAND, then the first string element of COMMAND is
|
the command writes to that file, and the file is then read into
|
||||||
resolved inside node_modules/.bin if such a directory exists
|
an Emacs buffer. Finally, if you use the symbol `npx' as one of
|
||||||
|
the elements of COMMAND, then the first string element of COMMAND
|
||||||
|
is resolved inside node_modules/.bin if such a directory exists
|
||||||
anywhere above the current `default-directory'.
|
anywhere above the current `default-directory'.
|
||||||
|
|
||||||
In any case, after the formatter finishes running, the diff
|
In any case, after the formatter finishes running, the diff
|
||||||
|
|
Loading…
Add table
Reference in a new issue