diff --git a/tex.el b/tex.el index c6228917..d1069688 100644 --- a/tex.el +++ b/tex.el @@ -2423,15 +2423,14 @@ name of master file if it cannot be determined otherwise." ;; Otherwise drop it. (setq name (TeX-strip-extension name)))) - (let* ((output-dir (and (or (stringp TeX-master) - (buffer-file-name)) ;; otherwise `name' is "" - (TeX-master-output-dir nondirectory - (concat name "." TeX-default-extension)))) - (reg (and output-dir (TeX--clean-extensions-regexp t))) - (is-output-ext - (and reg (or (string-match-p reg (concat "." extension)) - (string= "prv" extension))))) - (if is-output-ext + (let* ((reg (TeX--clean-extensions-regexp t)) + (is-output-ext (and reg + (or (string-match-p reg (concat "." extension)) + (string= "prv" extension)))) + (output-dir (and is-output-ext + (TeX-master-output-dir nondirectory + (concat name "." TeX-default-extension))))) + (if output-dir ;; If output extesnion, use output-dir (directory is already removed) ;; in TeX-master-output-dir (setq name (concat output-dir (file-name-nondirectory name))) @@ -2535,22 +2534,27 @@ directory is the same as the directory of TeX-master." :type 'string) (defun TeX-master-output-dir (&optional relative-to-master master-file) - (with-current-buffer - (find-file-noselect (or master-file (TeX-master-file t)) t) - (let ((out-dir (and TeX-output-dir - (file-name-as-directory - (abbreviate-file-name - (substitute-in-file-name - (expand-file-name - TeX-output-dir - (file-name-directory buffer-file-name)))))))) - ;; Make sure the directory exists - (when out-dir - (unless (file-exists-p out-dir) - (make-directory (file-name-as-directory out-dir) t)) - (if relative-to-master - (file-relative-name out-dir) - out-dir))))) + (let* ((master-file (or master-file (TeX-master-file t))) + (master-buffer + (or (get-file-buffer master-file) + (and (file-exists-p master-file) + (find-file-noselect master-file t))))) + (when master-buffer + (with-current-buffer master-buffer + (let ((out-dir (and TeX-output-dir + (file-name-as-directory + (abbreviate-file-name + (substitute-in-file-name + (expand-file-name + TeX-output-dir + (file-name-directory buffer-file-name)))))))) + ;; Make sure the directory exists + (when out-dir + (unless (file-exists-p out-dir) + (make-directory (file-name-as-directory out-dir) t)) + (if relative-to-master + (file-relative-name out-dir) + out-dir))))))) (defcustom TeX-style-local "style" "Directory containing hand generated TeX information.