aboutsummaryrefslogtreecommitdiff
path: root/modules/flyspell-and-abbrev.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-16 02:48:18 -0500
committerCraig Jennings <c@cjennings.net>2026-05-16 02:48:18 -0500
commita9a4d8c7148c115a242a7b35d16dd536f9c0c700 (patch)
tree3370202a1fd1a6e8eb7c14984bf602d0d37265d3 /modules/flyspell-and-abbrev.el
parent1c5a2ebab7c721d795ed9331afdb305fd683e172 (diff)
downloaddotemacs-a9a4d8c7148c115a242a7b35d16dd536f9c0c700.tar.gz
dotemacs-a9a4d8c7148c115a242a7b35d16dd536f9c0c700.zip
refactor(custom-editing): five hygiene fixes from the module-by-module re-review
- Guard `cj/duplicate-line-or-region' when COMMENT is non-nil but the current mode has no `comment-start' (e.g. fundamental-mode). Previously the function silently produced malformed output via `comment-region'; now it signals a clear `user-error'. - Factor the `find-file' advice install in external-open.el into `cj/external-open-install-advice'. Same idempotent shape (remove-then-add) but the intent is named. - Add `cj/--validate-decoration-char' in custom-comments.el and wire it into all six divider / border / box helpers. Rejects multi-char strings, empty strings, and control characters like newline/tab that would corrupt subsequent `M-q' flows. Updated the five nil-decoration ERT tests from `:type 'wrong-type-argument' (the old crash signal from `string-to-char' on nil) to `:type 'user-error', since the validator produces a clear message instead of a deep crash. - Extract `cj/--require-spell-checker' in flyspell-and-abbrev.el. Both `cj/flyspell-toggle' and `cj/flyspell-then-abbrev' now call the shared helper; the checker list lives in `cj/--spell-checker-executables', so adding nuspell or any other checker is a one-line edit. - Preserve trailing newlines in custom-ordering output. Both `cj/--arrayify' and `cj/--unarrayify' now detect a trailing newline on the input region and re-append it to the result, matching the pattern custom-text-enclose.el already uses.
Diffstat (limited to 'modules/flyspell-and-abbrev.el')
-rw-r--r--modules/flyspell-and-abbrev.el29
1 files changed, 17 insertions, 12 deletions
diff --git a/modules/flyspell-and-abbrev.el b/modules/flyspell-and-abbrev.el
index e29ad6e9f..e732ac469 100644
--- a/modules/flyspell-and-abbrev.el
+++ b/modules/flyspell-and-abbrev.el
@@ -43,6 +43,8 @@
;;; Code:
+(require 'cl-lib)
+
;; Forward declarations
(eval-when-compile (defvar org-dir))
(defvar flyspell-mode)
@@ -111,18 +113,26 @@
;; ------------------------------ Flyspell Toggle ------------------------------
;; easy toggling flyspell and also leverage the 'for-buffer-type' functionality.
+(defconst cj/--spell-checker-executables
+ '("aspell" "ispell" "hunspell")
+ "Spell-checker executables `cj/--require-spell-checker' looks for.")
+
+(defun cj/--require-spell-checker ()
+ "Signal `user-error' unless a known spell-checker is on PATH.
+Looked-up executables: `cj/--spell-checker-executables'. Single point
+of change when a new checker (e.g. nuspell) is added."
+ (unless (cl-some #'executable-find cj/--spell-checker-executables)
+ (user-error
+ "No spell checker found. Install one of: %s"
+ (mapconcat #'identity cj/--spell-checker-executables ", "))))
+
(defun cj/flyspell-toggle ()
"Turn Flyspell on if it is off, or off if it is on.
When turning on, it uses `cj/flyspell-on-for-buffer-type' so code-vs-text is
handled appropriately."
(interactive)
- ;; Check if spell checker is available
- (unless (or (executable-find "aspell")
- (executable-find "ispell")
- (executable-find "hunspell"))
- (user-error "No spell checker found. Install aspell, ispell, or hunspell"))
-
+ (cj/--require-spell-checker)
(if (bound-and-true-p flyspell-mode)
(progn ; flyspell is on, turn it off
(flyspell-mode -1)
@@ -208,12 +218,7 @@ Without prefix argument, it's created in the global abbrev table.
Press C-' repeatedly to step through misspellings one at a time."
(interactive "P")
- ;; Check if spell checker is available
- (unless (or (executable-find "aspell")
- (executable-find "ispell")
- (executable-find "hunspell"))
- (user-error "No spell checker found. Install aspell, ispell, or hunspell"))
-
+ (cj/--require-spell-checker)
;; Run flyspell-buffer only if buffer hasn't been checked yet
(unless (bound-and-true-p flyspell-mode)
(flyspell-buffer))