Skip to content

Commit

Permalink
Apply some code review suggestions from MELPA (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
raxod502 authored Nov 18, 2023
1 parent ddea9be commit 0e9a838
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions apheleia-formatter-context.el
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion apheleia-formatters.el
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion apheleia-log.el
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
;;; apheleia-log.el --- Log utilities -*- lexical-binding: t -*-

;; SPDX-License-Identifier: MIT

;;; Commentary:

;; Helpers for `apheleia' logging.
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion apheleia-rcs.el
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions apheleia-utils.el
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
;;; apheleia-utils.el --- Formatter helpers. -*- lexical-binding: t -*-

;; SPDX-License-Identifier: MIT

;;; Commentary:

;; Helper functions for defining apheleia formatters.
Expand Down
16 changes: 8 additions & 8 deletions apheleia.el
Original file line number Diff line number Diff line change
Expand Up @@ -177,25 +177,25 @@ 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
formatters
(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))))))))

Expand All @@ -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.
Expand Down

0 comments on commit 0e9a838

Please sign in to comment.