From e535ec0a4b55bebe5bc364c3379b964d5021bfd1 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 1 Apr 2021 16:53:49 -0500 Subject: Add function `dumb-auto-format' that checks with apheleia first In adding `dumb-auto-format', I've removed `acdw/reformat-buffer' because it's not complex enough or stand-alone enough to keep as its own function. 21 guns. --- init.el | 13 ++++++++++--- lisp/acdw.el | 7 ------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/init.el b/init.el index 0f235b3..023faa3 100644 --- a/init.el +++ b/init.el @@ -729,14 +729,21 @@ if ripgrep is installed, otherwise `consult-grep'." ;;;;; Formatting (setup (:straight (apheleia :host github :repo "raxod502/apheleia")) - (apheleia-global-mode +1)) + (apheleia-global-mode +1) + + ;; Use a dumb formatter on modes that `apheleia' doesn't work for. + (defun dumb-auto-format () + "Run `indent-region' in buffers that don't have an + `apheleia' formatter set." + (unless (apheleia--get-formatter-command) + (indent-region (point-min) (point-max)))) + (add-hook 'before-save-hook #'dumb-auto-format)) ;;;;; Emacs lisp (setup emacs-lisp-mode (:option eval-expression-print-length nil eval-expression-print-level nil - lisp-indent-function #'lisp-indent-function) - (:local-hook before-save-hook acdw/reindent-buffer)) + lisp-indent-function #'lisp-indent-function)) (setup (:straight macrostep) (define-key emacs-lisp-mode-map (kbd "C-c e") #'macrostep-expand)) diff --git a/lisp/acdw.el b/lisp/acdw.el index 8096a70..0203f3b 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el @@ -58,13 +58,6 @@ Ready for use with `after-focus-change-function'." (run-at-time sunset-time (* 60 60 24) sunset-command) (run-at-time "12:00am" (* 60 60 24) sunset-command))) -;;;; Re-indent a buffer -(defun acdw/reindent-buffer () - "Call `indent-region' on the whole buffer." - (interactive) - (save-excursion - (indent-region (point-min) (point-max)))) - ;;; Garbage collection hacks (defconst acdw/gc-cons-threshold-basis (* 800 1024) -- cgit 1.4.1-21-gabe81