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.
|
# The order is important for compilation.
|
||||||
for_compile := \
|
for_compile := \
|
||||||
|
apheleia-utils.el \
|
||||||
apheleia-formatter-context.el \
|
apheleia-formatter-context.el \
|
||||||
apheleia-log.el \
|
apheleia-log.el \
|
||||||
apheleia-formatters.el \
|
apheleia-formatters.el \
|
||||||
apheleia-rcs.el \
|
apheleia-rcs.el \
|
||||||
apheleia-utils.el \
|
|
||||||
apheleia.el
|
apheleia.el
|
||||||
for_checkdoc := *.el
|
for_checkdoc := *.el
|
||||||
for_checkindent := *.el
|
for_checkindent := *.el
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
;;; apheleia-formatter-context.el --- Formatter ctx -*- lexical-binding: t -*-
|
;;; apheleia-formatter-context.el --- Formatter ctx -*- lexical-binding: t -*-
|
||||||
|
|
||||||
|
;; SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
;;; Commentary:
|
;;; Commentary:
|
||||||
|
|
||||||
;; This file defines a helper for encapsulating common state for a formatter
|
;; This file defines a helper for encapsulating common state for a formatter
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
;;; apheleia-formatters.el --- Run formatters -*- lexical-binding: t -*-
|
;;; apheleia-formatters.el --- Run formatters -*- lexical-binding: t -*-
|
||||||
|
|
||||||
|
;; SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
;;; Commentary:
|
;;; Commentary:
|
||||||
|
|
||||||
;; This module defines a series of functions for running a formatter process
|
;; 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)))
|
(format " *apheleia-%s-stdout*" name)))
|
||||||
(stderr (generate-new-buffer
|
(stderr (generate-new-buffer
|
||||||
(format " *apheleia-%s-stderr*" name)))
|
(format " *apheleia-%s-stderr*" name)))
|
||||||
(log-name (apheliea-log--buffer-name name)))
|
(log-name (apheleia-log--buffer-name name)))
|
||||||
(condition-case-unless-debug e
|
(condition-case-unless-debug e
|
||||||
(progn
|
(progn
|
||||||
(setq apheleia--current-process
|
(setq apheleia--current-process
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
;;; apheleia-log.el --- Log utilities -*- lexical-binding: t -*-
|
;;; apheleia-log.el --- Log utilities -*- lexical-binding: t -*-
|
||||||
|
|
||||||
|
;; SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
;;; Commentary:
|
;;; Commentary:
|
||||||
|
|
||||||
;; Helpers for `apheleia' logging.
|
;; Helpers for `apheleia' logging.
|
||||||
|
@ -51,7 +53,7 @@ This points into a log buffer.")
|
||||||
(pop-to-buffer (marker-buffer apheleia--last-error-marker))
|
(pop-to-buffer (marker-buffer apheleia--last-error-marker))
|
||||||
(goto-char 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."
|
"Get the name of the log buffer for FORMATTER."
|
||||||
(format "%s*apheleia-%s-log*"
|
(format "%s*apheleia-%s-log*"
|
||||||
(if apheleia-hide-log-buffers
|
(if apheleia-hide-log-buffers
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
;;; apheleia-rcs.el --- Apply RCS patches -*- lexical-binding: t -*-
|
;;; apheleia-rcs.el --- Apply RCS patches -*- lexical-binding: t -*-
|
||||||
|
|
||||||
|
;; SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
;;; Commentary:
|
;;; Commentary:
|
||||||
|
|
||||||
;; A library to apply a RCS patch to an Emacs buffer while minimising the
|
;; 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."
|
for documentation on the RCS patch format."
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(while (not (= (point) (point-max)))
|
(while (not (eobp))
|
||||||
(unless (looking-at "$\\|\\([ad]\\)\\([0-9]+\\) \\([0-9]+\\)")
|
(unless (looking-at "$\\|\\([ad]\\)\\([0-9]+\\) \\([0-9]+\\)")
|
||||||
(error "Malformed RCS patch: %S" (point)))
|
(error "Malformed RCS patch: %S" (point)))
|
||||||
(forward-line)
|
(forward-line)
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
;;; apheleia-utils.el --- Formatter helpers. -*- lexical-binding: t -*-
|
;;; apheleia-utils.el --- Formatter helpers. -*- lexical-binding: t -*-
|
||||||
|
|
||||||
|
;; SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
;;; Commentary:
|
;;; Commentary:
|
||||||
|
|
||||||
;; Helper functions for defining apheleia formatters.
|
;; Helper functions for defining apheleia formatters.
|
||||||
|
|
16
apheleia.el
16
apheleia.el
|
@ -177,17 +177,17 @@ similar task."
|
||||||
(defvar apheleia-mode)
|
(defvar apheleia-mode)
|
||||||
|
|
||||||
;; Prevent infinite loop.
|
;; Prevent infinite loop.
|
||||||
(defvar apheleia--format-after-save-in-progress nil
|
(defvar apheleia-format-after-save-in-progress nil
|
||||||
"Prevent `apheleia--format-after-save' from being called recursively.
|
"Prevent `apheleia-format-after-save' from being called recursively.
|
||||||
This will be locally bound to t while `apheleia--format-after-save' is
|
This will be locally bound to t while `apheleia-format-after-save' is
|
||||||
operating, to prevent an infinite loop.")
|
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
|
(unless apheleia-format-after-save-in-progress
|
||||||
(when (and apheleia-mode (not (buffer-narrowed-p)))
|
(when (and apheleia-mode (not (buffer-narrowed-p)))
|
||||||
(when-let ((formatters (apheleia--get-formatters)))
|
(when-let ((formatters (apheleia--get-formatters)))
|
||||||
(apheleia-format-buffer
|
(apheleia-format-buffer
|
||||||
|
@ -195,7 +195,7 @@ operating, to prevent an infinite loop.")
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(with-demoted-errors "Apheleia: %s"
|
(with-demoted-errors "Apheleia: %s"
|
||||||
(when buffer-file-name
|
(when buffer-file-name
|
||||||
(let ((apheleia--format-after-save-in-progress t))
|
(let ((apheleia-format-after-save-in-progress t))
|
||||||
(apheleia--save-buffer-silently)))
|
(apheleia--save-buffer-silently)))
|
||||||
(run-hooks 'apheleia-post-format-hook))))))))
|
(run-hooks 'apheleia-post-format-hook))))))))
|
||||||
|
|
||||||
|
@ -211,8 +211,8 @@ It is customized by means of the variables `apheleia-mode-alist'
|
||||||
and `apheleia-formatters'."
|
and `apheleia-formatters'."
|
||||||
:lighter apheleia-mode-lighter
|
:lighter apheleia-mode-lighter
|
||||||
(if apheleia-mode
|
(if apheleia-mode
|
||||||
(add-hook 'after-save-hook #'apheleia--format-after-save nil 'local)
|
(add-hook 'after-save-hook #'apheleia-format-after-save nil 'local)
|
||||||
(remove-hook 'after-save-hook #'apheleia--format-after-save 'local)))
|
(remove-hook 'after-save-hook #'apheleia-format-after-save 'local)))
|
||||||
|
|
||||||
(defvar-local apheleia-inhibit nil
|
(defvar-local apheleia-inhibit nil
|
||||||
"Do not enable `apheleia-mode' automatically if non-nil.
|
"Do not enable `apheleia-mode' automatically if non-nil.
|
||||||
|
|
Loading…
Add table
Reference in a new issue