Subject: Re: bug#78841: reftex-get-bibfile-list fails to detect biblatex if there's no buffer for the main file

From: Stefan Monnier <[email-masked]>
Date: Sat, 28 Jun 2025 19:33:16 -0400

>> Arne, we have a bug report for AUCTeX where I found that the function
>> `latexenc-find-file-coding-system' can't deal with `TeX-master' or
>> `tex-main-file' set to a constant string in the init file and not as
>> file local variable.  I'm not really familiar with your code, but the
>> following small change is reported to fix the issue, at least for
>> AUCTeX:
> My apologies, my last proposal was broken, please consider the one
> attached.
>
> Best, Arash
>
> diff --git a/lisp/international/latexenc.el b/lisp/international/latexenc.el
> index 1b735810ee4..805a74c52c5 100644
> --- a/lisp/international/latexenc.el
> +++ b/lisp/international/latexenc.el
> @@ -144,17 +144,26 @@ latexenc-find-file-coding-system
>  				       (file-name-directory (nth 1 arg-list))
>  				     default-directory))
>  		latexenc-main-file)
> -            ;; Is there a TeX-master or tex-main-file in the local variables
> -            ;; section?
> +            ;; Is there a TeX-master or tex-main-file in the local
> +            ;; variables section or is it globally set to a constant
> +            ;; string?
>              (unless latexenc-dont-use-TeX-master-flag
>                (goto-char (point-max))
>  	      (search-backward "\n\^L" (max (- (point-max) 3000) (point-min))
>                                 'move)
>  	      (search-forward "Local Variables:" nil t)
> -              (when (re-search-forward
> -                     "^%+ *\\(TeX-master\\|tex-main-file\\): *\"\\(.+\\)\""
> -                     nil t)
> -                (let ((file (match-string 2)))
> +              (when (or (re-search-forward
> +                         "^%+ *\\(TeX-master\\|tex-main-file\\): *\"\\(.+\\)\""
> +                         nil t)
> +                        (and (bound-and-true-p TeX-master)
> +                             (stringp (default-value 'TeX-master)))
> +                        (and (bound-and-true-p tex-main-file)
> +                             (stringp (default-value 'tex-main-file))))
> +                (let ((file (or (match-string 2)
> +                                (and (boundp 'TeX-master)
> +                                     (default-value 'TeX-master))
> +                                (and (boundp 'tex-main-file)
> +                                     (default-value 'tex-main-file)))))
>                    (dolist (ext `("" ,(if (boundp 'TeX-default-extension)
>                                           (concat "." TeX-default-extension)
>                                         "")

LGTM.
This said, I don't think we need `default-value`.
And we can presumably simplify the above to

             (let ((file (if (re-search-forward
                              "^%+ *\\(TeX-master\\|tex-main-file\\): *\"\\(.+\\)\""
                              nil t)
                             (match-string 2)
                           (or (bound-and-true-p TeX-master)
                               (bound-and-true-p tex-main-file)))))
               (when (stringp file)
                 (dolist ...)))

- Stefan