mirror of
https://github.com/vale981/apheleia
synced 2025-03-04 09:01:42 -05:00
Apply some code review suggestions from MELPA (#246)
https://github.com/melpa/melpa/pull/8809#issuecomment-1807218549
This commit is contained in:
parent
ddea9bea70
commit
0e9a838bdd
7 changed files with 22 additions and 12 deletions
2
Makefile
2
Makefile
|
@ -9,11 +9,11 @@ TAG ?= latest
|
|||
|
||||
# The order is important for compilation.
|
||||
for_compile := \
|
||||
apheleia-utils.el \
|
||||
apheleia-formatter-context.el \
|
||||
apheleia-log.el \
|
||||
apheleia-formatters.el \
|
||||
apheleia-rcs.el \
|
||||
apheleia-utils.el \
|
||||
apheleia.el
|
||||
for_checkdoc := *.el
|
||||
for_checkindent := *.el
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
;;; apheleia-formatter-context.el --- Formatter ctx -*- lexical-binding: t -*-
|
||||
|
||||
;; SPDX-License-Identifier: MIT
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; This file defines a helper for encapsulating common state for a formatter
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
;;; apheleia-formatters.el --- Run formatters -*- lexical-binding: t -*-
|
||||
|
||||
;; SPDX-License-Identifier: MIT
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; This module defines a series of functions for running a formatter process
|
||||
|
@ -552,7 +554,7 @@ command succeeds provided that its exit status is 0."
|
|||
(format " *apheleia-%s-stdout*" name)))
|
||||
(stderr (generate-new-buffer
|
||||
(format " *apheleia-%s-stderr*" name)))
|
||||
(log-name (apheliea-log--buffer-name name)))
|
||||
(log-name (apheleia-log--buffer-name name)))
|
||||
(condition-case-unless-debug e
|
||||
(progn
|
||||
(setq apheleia--current-process
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
;;; apheleia-log.el --- Log utilities -*- lexical-binding: t -*-
|
||||
|
||||
;; SPDX-License-Identifier: MIT
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; Helpers for `apheleia' logging.
|
||||
|
@ -51,7 +53,7 @@ This points into a log buffer.")
|
|||
(pop-to-buffer (marker-buffer apheleia--last-error-marker))
|
||||
(goto-char apheleia--last-error-marker))
|
||||
|
||||
(defun apheliea-log--buffer-name (formatter)
|
||||
(defun apheleia-log--buffer-name (formatter)
|
||||
"Get the name of the log buffer for FORMATTER."
|
||||
(format "%s*apheleia-%s-log*"
|
||||
(if apheleia-hide-log-buffers
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
;;; apheleia-rcs.el --- Apply RCS patches -*- lexical-binding: t -*-
|
||||
|
||||
;; SPDX-License-Identifier: MIT
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; A library to apply a RCS patch to an Emacs buffer while minimising the
|
||||
|
@ -74,7 +76,7 @@ See <https://tools.ietf.org/doc/tcllib/html/rcs.html#section4>
|
|||
for documentation on the RCS patch format."
|
||||
(save-excursion
|
||||
(goto-char (point-min))
|
||||
(while (not (= (point) (point-max)))
|
||||
(while (not (eobp))
|
||||
(unless (looking-at "$\\|\\([ad]\\)\\([0-9]+\\) \\([0-9]+\\)")
|
||||
(error "Malformed RCS patch: %S" (point)))
|
||||
(forward-line)
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
;;; apheleia-utils.el --- Formatter helpers. -*- lexical-binding: t -*-
|
||||
|
||||
;; SPDX-License-Identifier: MIT
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; Helper functions for defining apheleia formatters.
|
||||
|
|
16
apheleia.el
16
apheleia.el
|
@ -177,17 +177,17 @@ similar task."
|
|||
(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
|
||||
(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
|
||||
;; loading Apheleia; thus this function may be invoked as an autoload.
|
||||
;;;###autoload
|
||||
(defun apheleia--format-after-save ()
|
||||
(defun apheleia-format-after-save ()
|
||||
"Run code formatter for current buffer if any configured, then save."
|
||||
(unless apheleia--format-after-save-in-progress
|
||||
(unless apheleia-format-after-save-in-progress
|
||||
(when (and apheleia-mode (not (buffer-narrowed-p)))
|
||||
(when-let ((formatters (apheleia--get-formatters)))
|
||||
(apheleia-format-buffer
|
||||
|
@ -195,7 +195,7 @@ operating, to prevent an infinite loop.")
|
|||
(lambda ()
|
||||
(with-demoted-errors "Apheleia: %s"
|
||||
(when buffer-file-name
|
||||
(let ((apheleia--format-after-save-in-progress t))
|
||||
(let ((apheleia-format-after-save-in-progress t))
|
||||
(apheleia--save-buffer-silently)))
|
||||
(run-hooks 'apheleia-post-format-hook))))))))
|
||||
|
||||
|
@ -211,8 +211,8 @@ It is customized by means of the variables `apheleia-mode-alist'
|
|||
and `apheleia-formatters'."
|
||||
:lighter apheleia-mode-lighter
|
||||
(if apheleia-mode
|
||||
(add-hook 'after-save-hook #'apheleia--format-after-save nil 'local)
|
||||
(remove-hook 'after-save-hook #'apheleia--format-after-save 'local)))
|
||||
(add-hook 'after-save-hook #'apheleia-format-after-save nil 'local)
|
||||
(remove-hook 'after-save-hook #'apheleia-format-after-save 'local)))
|
||||
|
||||
(defvar-local apheleia-inhibit nil
|
||||
"Do not enable `apheleia-mode' automatically if non-nil.
|
||||
|
|
Loading…
Add table
Reference in a new issue