diff --git a/font-latex.el b/font-latex.el index 8fc567e2..92eb7046 100644 --- a/font-latex.el +++ b/font-latex.el @@ -1353,7 +1353,13 @@ triggers Font Lock to recognize the change." ;; Make sure fontification will be refreshed if a user sets variables ;; influencing fontification in her file-local variables section. - (add-hook 'hack-local-variables-hook #'font-latex-after-hacking-local-variables t t)) + (add-hook 'hack-local-variables-hook #'font-latex-after-hacking-local-variables t t) + + ;; We may be using the mode programmatically to extract data, and we + ;; then need this to be set up first so that a command like + ;; `xref-find-references' doesn't bug out when matching hits in + ;; files that Emacs isn't visiting. + (font-lock-set-defaults)) (defun font-latex-update-font-lock (&optional _syntactic-kws) "Tell font-lock about updates of fontification rules. diff --git a/latex.el b/latex.el index 3abb00f2..a7f236e8 100644 --- a/latex.el +++ b/latex.el @@ -8068,6 +8068,7 @@ runs the hooks in `docTeX-mode-hook'." TeX-comment-start-regexp "\\(?:%\\(?:<[^>]+>\\)?\\)") (setq TeX-base-mode-name "docTeX") (TeX-set-mode-name) + (setq font-lock-set-defaults nil) (funcall TeX-install-font-lock)) ;; Enable LaTeX abbrevs in docTeX mode buffer.