mirror of
https://github.com/vale981/apheleia
synced 2025-03-05 09:31:40 -05:00
* Fix infinite loop with rebinding after-save-hook (fixes #27) * Satisfy linter * Add docstring for new var * Update changelog * apheleia-format-buffer is asynchronous * Update apheleia.el Co-authored-by: Radon Rosborough <radon.neon@gmail.com>
This commit is contained in:
parent
8a1e68441c
commit
1ee7f3bc79
2 changed files with 20 additions and 12 deletions
|
@ -9,8 +9,11 @@ The format is based on [Keep a Changelog].
|
||||||
|
|
||||||
### Bugs fixed
|
### Bugs fixed
|
||||||
* Prettier now respects `.prettierignore` ([#21]).
|
* Prettier now respects `.prettierignore` ([#21]).
|
||||||
|
* Apheleia's global mode should no longer trigger warnings about a locally
|
||||||
|
let-bound `after-save-hook` ([#27]).
|
||||||
|
|
||||||
[#21]: https://github.com/raxod502/apheleia/issues/21
|
[#21]: https://github.com/raxod502/apheleia/issues/21
|
||||||
|
[#27]: https://github.com/raxod502/apheleia/issues/27
|
||||||
|
|
||||||
## 1.1.1 (released 2020-07-16)
|
## 1.1.1 (released 2020-07-16)
|
||||||
### Formatters
|
### Formatters
|
||||||
|
|
17
apheleia.el
17
apheleia.el
|
@ -348,10 +348,7 @@ mark the buffer as visiting FILENAME."
|
||||||
(lambda (format &rest args)
|
(lambda (format &rest args)
|
||||||
(unless (equal format "Saving file %s...")
|
(unless (equal format "Saving file %s...")
|
||||||
(apply message format args)))))
|
(apply message format args)))))
|
||||||
;; Avoid infinite loop.
|
(write-file (or filename buffer-file-name))))
|
||||||
(let ((after-save-hook
|
|
||||||
(remq #'apheleia--format-after-save after-save-hook)))
|
|
||||||
(write-file (or filename buffer-file-name)))))
|
|
||||||
|
|
||||||
(defun apheleia--create-rcs-patch (old-buffer new-buffer callback)
|
(defun apheleia--create-rcs-patch (old-buffer new-buffer callback)
|
||||||
"Generate RCS patch from text in OLD-BUFFER to text in NEW-BUFFER.
|
"Generate RCS patch from text in OLD-BUFFER to text in NEW-BUFFER.
|
||||||
|
@ -629,19 +626,27 @@ changes), CALLBACK, if provided, is invoked with no arguments."
|
||||||
;; Handle recursive references.
|
;; Handle recursive references.
|
||||||
(defvar apheleia-mode)
|
(defvar apheleia-mode)
|
||||||
|
|
||||||
|
;; Prevent infinite loop.
|
||||||
|
(defvar apheleia--format-after-save-in-progress nil
|
||||||
|
"Prevent apheleia--format-after-save from being called recursively.
|
||||||
|
This will be locally bound to t while apheleia--format-after-save is
|
||||||
|
operating, to prevent an infinite loop.")
|
||||||
|
|
||||||
;; Autoload because the user may enable `apheleia-mode' without
|
;; Autoload because the user may enable `apheleia-mode' without
|
||||||
;; loading Apheleia; thus this function may be invoked as an autoload.
|
;; loading Apheleia; thus this function may be invoked as an autoload.
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun apheleia--format-after-save ()
|
(defun apheleia--format-after-save ()
|
||||||
"Run code formatter for current buffer if any configured, then save."
|
"Run code formatter for current buffer if any configured, then save."
|
||||||
|
(unless apheleia--format-after-save-in-progress
|
||||||
(when apheleia-mode
|
(when apheleia-mode
|
||||||
(when-let ((command (apheleia--get-formatter-command)))
|
(when-let ((command (apheleia--get-formatter-command)))
|
||||||
(apheleia-format-buffer
|
(apheleia-format-buffer
|
||||||
command
|
command
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(with-demoted-errors "Apheleia: %s"
|
(with-demoted-errors "Apheleia: %s"
|
||||||
(apheleia--write-file-silently buffer-file-name)
|
(let ((apheleia--format-after-save-in-progress t))
|
||||||
(run-hooks 'apheleia-post-format-hook)))))))
|
(apheleia--write-file-silently buffer-file-name))
|
||||||
|
(run-hooks 'apheleia-post-format-hook))))))))
|
||||||
|
|
||||||
;; Use `progn' to force the entire minor mode definition to be copied
|
;; Use `progn' to force the entire minor mode definition to be copied
|
||||||
;; into the autoloads file, so that the minor mode can be enabled
|
;; into the autoloads file, so that the minor mode can be enabled
|
||||||
|
|
Loading…
Add table
Reference in a new issue