diff options
| -rw-r--r-- | modules/latex-config.el | 9 | ||||
| -rw-r--r-- | tests/test-latex-config--latexmk-wiring.el | 62 |
2 files changed, 69 insertions, 2 deletions
diff --git a/modules/latex-config.el b/modules/latex-config.el index 0db21f2f2..f2a586704 100644 --- a/modules/latex-config.el +++ b/modules/latex-config.el @@ -63,7 +63,10 @@ single entry." :ensure auctex :defer t :hook - (TeX-mode-hook . (lambda () (setq TeX-command-default "latexmk"))) ; use latexmk by default + ;; Name the mode, not the hook: use-package appends "-hook" to any symbol not + ;; ending in "-mode", so `TeX-mode' becomes `TeX-mode-hook' while the literal + ;; `TeX-mode-hook' would expand to the unbound `TeX-mode-hook-hook'. + (TeX-mode . (lambda () (setq TeX-command-default "latexmk"))) ; use latexmk by default (LaTeX-mode . (lambda () (TeX-fold-mode 1))) ; automatically activate TeX-fold-mode. (LaTeX-mode . flyspell-mode) ; turn on flyspell-mode by default (LaTeX-mode . TeX-PDF-mode) @@ -78,7 +81,9 @@ single entry." (setq-default TeX-master t)) ; Assume the file is the master file itself (use-package auctex-latexmk - :defer t + ;; Load with AUCTeX, not deferred: `:defer t' has no autoload trigger here, so + ;; `auctex-latexmk-setup' never runs and "latexmk" never joins TeX-command-list. + :after tex :config (auctex-latexmk-setup) (setq auctex-latexmk-inherit-TeX-PDF-mode t)) diff --git a/tests/test-latex-config--latexmk-wiring.el b/tests/test-latex-config--latexmk-wiring.el new file mode 100644 index 000000000..30b8f29de --- /dev/null +++ b/tests/test-latex-config--latexmk-wiring.el @@ -0,0 +1,62 @@ +;;; test-latex-config--latexmk-wiring.el --- latexmk activation guards -*- lexical-binding: t; -*- + +;;; Commentary: +;; Guards the two breaks that kept the latexmk workflow from activating: +;; 1. The :hook entry that sets `TeX-command-default' must target the real +;; `TeX-mode-hook'. use-package appends "-hook" to any hook symbol not +;; ending in "-mode", so the mode name `TeX-mode' is required; the literal +;; `TeX-mode-hook' expands to the nonexistent `TeX-mode-hook-hook'. +;; 2. `auctex-latexmk' must load so `auctex-latexmk-setup' runs. `:defer t' +;; with no trigger never fires; `:after tex' loads it when AUCTeX loads. +;; +;; The forms are read from the source and macroexpanded, so the test fails the +;; way the live config failed -- against the actual declaration. + +;;; Code: + +(require 'ert) +(require 'seq) +(require 'use-package) + +(defun test-latex-config--forms () + "Return the top-level forms in latex-config.el." + (let ((file (expand-file-name "modules/latex-config.el" user-emacs-directory)) + (forms '())) + (with-temp-buffer + (insert-file-contents file) + (goto-char (point-min)) + (condition-case nil + (while t (push (read (current-buffer)) forms)) + (end-of-file nil))) + (nreverse forms))) + +(defun test-latex-config--use-package-form (package) + "Return the (use-package PACKAGE ...) top-level form from latex-config.el." + (seq-find (lambda (form) + (and (consp form) + (eq (car form) 'use-package) + (eq (cadr form) package))) + (test-latex-config--forms))) + +(ert-deftest test-latex-config-tex-hook-targets-real-hook () + "Regression: the latexmk-default :hook expands to `TeX-mode-hook', not the +unbound `TeX-mode-hook-hook' use-package builds from a non-mode hook symbol." + (let* ((form (test-latex-config--use-package-form 'tex)) + (expansion (format "%S" (macroexpand-all form)))) + (should form) + ;; The hook symbol is followed by whitespace before its lambda, so anchor + ;; on that to distinguish `TeX-mode-hook' from the broken `...-hook-hook'. + (should (string-match-p "TeX-mode-hook[ )]" expansion)) + (should-not (string-match-p "TeX-mode-hook-hook" expansion)))) + +(ert-deftest test-latex-config-auctex-latexmk-loads-after-tex () + "Regression: auctex-latexmk uses `:after tex' so `auctex-latexmk-setup' runs; +a bare `:defer t' with no trigger would never load it." + (let ((form (test-latex-config--use-package-form 'auctex-latexmk))) + (should form) + (should (member :after form)) + (should (eq (cadr (member :after form)) 'tex)) + (should-not (member :defer form)))) + +(provide 'test-latex-config--latexmk-wiring) +;;; test-latex-config--latexmk-wiring.el ends here |
