From b007a9b808d3cf360d03f3d7597119c2fe2cd6e8 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Mon, 25 May 2026 15:11:04 -0500 Subject: 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. --- modules/latex-config.el | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'modules') 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 ---------------------------- -- cgit v1.2.3