diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-25 15:11:04 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-25 15:11:04 -0500 |
| commit | b007a9b808d3cf360d03f3d7597119c2fe2cd6e8 (patch) | |
| tree | 0a890f19804f7e9ed01d682d4855689432c2a147 /modules | |
| parent | fda029f8f96d9ce7ac8276ceb3475cd9a3bbe797 (diff) | |
| download | dotemacs-b007a9b808d3cf360d03f3d7597119c2fe2cd6e8.tar.gz dotemacs-b007a9b808d3cf360d03f3d7597119c2fe2cd6e8.zip | |
fix(latex): make PDF-viewer selection idempotent
cj/--latex-select-pdf-viewer runs on every LaTeX-mode buffer and was blindly pushing an (output-pdf VIEWER) entry onto TeX-view-program-selection, so each LaTeX buffer opened in a session stacked another duplicate. The head still won, so the viewer worked, but the list grew and the docstring's idempotency claim was false. I drop any existing output-pdf entry before consing the chosen viewer, which also makes "wins over any default" actually true.
Added a test file (the module had none) covering selection, preference order, the PDF-Tools fallback, idempotency, and default override, with executable-find mocked so the run doesn't depend on which viewers are installed.
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/latex-config.el | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/modules/latex-config.el b/modules/latex-config.el index 8636e2cd..0db21f2f 100644 --- a/modules/latex-config.el +++ b/modules/latex-config.el @@ -44,15 +44,18 @@ (declare-function pdf-view-mode "pdf-view") (defun cj/--latex-select-pdf-viewer () - "Push the first available external PDF viewer onto `TeX-view-program-selection'. -Falls back to PDF Tools when no external viewer is on PATH. The new -selection is consed onto the head of the alist so it wins over any -default. Idempotent: re-running picks the same viewer." + "Select the first available external PDF viewer for `output-pdf'. +Falls back to PDF Tools when no external viewer is on PATH. Any existing +`output-pdf' entry is dropped first, then the chosen viewer is consed onto +the head so it wins over any default. Idempotent: re-running leaves a +single entry." (let* ((found (cl-find-if (lambda (entry) (executable-find (car entry))) cj/--latex-pdf-viewer-candidates)) (viewer-name (if found (cdr found) "PDF Tools"))) - (push (list 'output-pdf viewer-name) TeX-view-program-selection))) + (setq TeX-view-program-selection + (cons (list 'output-pdf viewer-name) + (assq-delete-all 'output-pdf TeX-view-program-selection))))) ;; ----------------------------- Auctex And Related ---------------------------- |
