Skip to content

Commit

Permalink
fix purcell#25 hook for post-processing formatter output
Browse files Browse the repository at this point in the history
  • Loading branch information
wyuenho committed May 26, 2020
1 parent dc6278a commit 453ba9f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions reformatter.el
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
(require 'ansi-color)

;;;###autoload
(cl-defmacro reformatter-define (name &key program args (mode t) lighter keymap group (exit-code-success-p 'zerop))
(cl-defmacro reformatter-define (name &key program args (mode t) lighter keymap group (exit-code-success-p 'zerop) (output-post-processor 'identity))
"Define a reformatter command with NAME.
When called, the reformatter will use PROGRAM and any ARGS to
Expand Down Expand Up @@ -129,10 +129,17 @@ The macro accepts the following keyword arguments:
which accepts an integer process exit code, and returns non-nil
if that exit code is considered successful. This could be a
lambda, quoted symbol or sharp-quoted symbol. If not supplied,
the code is considered successful if it is `zerop'."
the code is considered successful if it is `zerop'.
:output-post-processor
If provided, this is a function that takes the output PROGRAM,
do some arbitrary processing to it, and then return the final
output. If not supplied, the output is returned as is."
(declare (indent defun))
(cl-assert (symbolp name))
(cl-assert (functionp exit-code-success-p))
(cl-assert (functionp output-post-processor))
(cl-assert program)
;; Note: we skip using `gensym' here because the macro arguments are only
;; referred to once below, but this may have to change later.
Expand Down Expand Up @@ -198,7 +205,7 @@ DISPLAY-ERRORS, shows a buffer if the formatting fails."
;; disruption to marker positions and the
;; undo list
(narrow-to-region beg end)
(reformatter-replace-buffer-contents-from-file out-file))
(reformatter-replace-buffer-contents-from-file (funcall ,output-post-processor out-file)))
;; if there is no errors the error-buffer shouldn't be kept open
(delete-windows-on error-buffer))
(if display-errors
Expand Down

0 comments on commit 453ba9f

Please sign in to comment.