diff --git a/tex-buf.el b/tex-buf.el index 510722cb..b25eaa46 100644 --- a/tex-buf.el +++ b/tex-buf.el @@ -82,7 +82,7 @@ Return non-nil if document needs to be re-TeX'ed." (if (string-equal name "") (setq name (TeX-master-file))) - (TeX-check-files (concat name "." (TeX-output-extension)) + (TeX-check-files (concat name "." (TeX-output-extension)) ;; TODO: This might need changing when TeX-output-dir is set (cons name (TeX-style-list)) TeX-file-extensions)) @@ -826,7 +826,7 @@ omitted) and `TeX-region-file'." ;; comparison. (if (string-equal (expand-file-name name) (expand-file-name (TeX-region-file))) - (TeX-check-files (concat name "." (TeX-output-extension)) + (TeX-check-files (concat name "." (TeX-output-extension)) ;; TODO: This might need changing when TeX-output-dir is set ;; Each original will be checked for all dirs ;; in `TeX-check-path' so this needs to be just ;; a filename without directory. diff --git a/tex.el b/tex.el index b2bbbbf7..4598196a 100644 --- a/tex.el +++ b/tex.el @@ -188,7 +188,7 @@ If nil, none is specified." ;; `TeX-expand-list-builtin' for a description of the % escapes (defcustom TeX-command-list - '(("TeX" "%(PDF)%(tex) %(file-line-error) %`%(extraopts) %S%(PDFout)%(mode)%' %t" + '(("TeX" "%(PDF)%(tex) %(file-line-error) %`%(extraopts) %(output-dir) %S%(PDFout)%(mode)%' %t" TeX-run-TeX nil (plain-tex-mode ams-tex-mode texinfo-mode) :help "Run plain TeX") ("LaTeX" "%`%l%(mode)%' %T" @@ -399,7 +399,7 @@ The executable `latex' is LaTeX version 2e." (defcustom LaTeX-command-style ;; They have all been combined in LaTeX 2e. - '(("" "%(PDF)%(latex) %(file-line-error) %(extraopts) %S%(PDFout)")) + '(("" "%(PDF)%(latex) %(file-line-error) %(extraopts) %(output-dir) %S%(PDFout)")) "List of style options and LaTeX commands. If the first element (a regular expression) matches the name of one of @@ -566,6 +566,10 @@ string." ("%(cntxcom)" ConTeXt-expand-command) ("%(execopts)" ConTeXt-expand-options) ("%(extraopts)" (lambda () TeX-command-extra-options)) + ("%(output-dir)" (lambda () (if (not TeX-output-dir) "" + (if (not (file-exists-p TeX-output-dir)) + (make-directory TeX-output-dir)) + (concat "--output-directory=\"" TeX-output-dir "\"")))) ("%S" TeX-source-correlate-expand-options) ("%dS" TeX-source-specials-view-expand-options) ("%cS" TeX-source-specials-view-expand-client) @@ -1261,7 +1265,7 @@ viewer." (require 'url-util) (let* ((uri (concat "file://" (url-encode-url (expand-file-name - (concat file "." (TeX-output-extension)))))) + (TeX-active-master (TeX-output-extension)))))) (owner (dbus-call-method :session (format "org.%s.%s.Daemon" de app) (format "/org/%s/%s/Daemon" de app) @@ -2274,40 +2278,45 @@ Used as a default in TeX, LaTeX and docTeX mode.") (autoload 'dired-mark-pop-up "dired") +(defun TeX--clean-extensions-regexp (&optional arg) + "Returns a regexp to match extensions that should be cleaned by TeX-clean. +If the optional argument ARG is non-nil then output files are included" + (when-let ((mode-prefix (TeX-mode-prefix)) + (suffixes (append (symbol-value + (intern (concat mode-prefix + "-clean-intermediate-suffixes"))) + (when arg + (symbol-value + (intern (concat mode-prefix + "-clean-output-suffixes"))))))) + (mapconcat 'identity suffixes "\\|"))) + (defun TeX-clean (&optional arg) "Delete generated files associated with current master and region files. If prefix ARG is non-nil, not only remove intermediate but also output files." (interactive "P") - (let* ((mode-prefix (TeX-mode-prefix)) - (suffixes (append (symbol-value - (intern (concat mode-prefix - "-clean-intermediate-suffixes"))) - (when arg - (symbol-value - (intern (concat mode-prefix - "-clean-output-suffixes")))))) - (master (TeX-active-master)) - (master-dir (file-name-directory master)) - (regexp (concat "\\(" - (regexp-quote (file-name-nondirectory master)) "\\|" - (regexp-quote (TeX-region-file nil t)) - "\\)" - "\\(" - (mapconcat 'identity suffixes "\\|") - "\\)\\'" - "\\|" (regexp-quote (TeX-region-file t t)))) - (files (when regexp - (directory-files (or master-dir ".") nil regexp)))) + (let* ((master (TeX-master-output-file)) + (master-dir (file-name-directory master)) + (regexp (concat "\\(" + (regexp-quote (file-name-nondirectory master)) "\\|" + (regexp-quote (TeX-region-file nil t)) + "\\)" + "\\(" + (TeX--clean-extensions-regexp arg) + "\\)\\'" + "\\|" (regexp-quote (TeX-region-file t t)))) + (files (when (and regexp (or (not master-dir) (file-exists-p master-dir))) + (directory-files (or master-dir ".") nil regexp)))) (if files - (when (or (not TeX-clean-confirm) - (dired-mark-pop-up " *Deletions*" 'delete - (if (> (length files) 1) - files - (cons t files)) - 'y-or-n-p "Delete files? ")) - (dolist (file files) - (delete-file (concat master-dir file)))) + (when (or (not TeX-clean-confirm) + (dired-mark-pop-up " *Deletions*" 'delete + (if (> (length files) 1) + files + (cons t files)) + 'y-or-n-p "Delete files? ")) + (dolist (file files) + (delete-file (concat master-dir file)))) (message "No files to be deleted")))) ;;; Master File @@ -2403,6 +2412,28 @@ this variable to \"\"." 'path)) (TeX-add-local-master)))))) +(defun TeX-master-output-file (&optional extension) + "Returns an output file based on `TeX-output-dir' in the +master-file, opening it if necessary. if the optional argument +EXTENSION is non-nil it is appended as an extension to the output +file. If EXTENSION is t then (TeX-output-extension) is used." + (interactive) + (if (eq extension t) + (setq extension (TeX-output-extension))) + (let ((file (TeX-master-file t)) name) + (with-current-buffer + (or (find-buffer-visiting file) + (find-file-noselect file)) + (when TeX-output-dir + ;; Expand file name in case the master directory is different from the + ;; current directory + (setq name (concat (expand-file-name TeX-output-dir) "/" + (TeX-master-file))))) + (if name + (if extension (concat name "." extension) + name) + (TeX-master-file extension)))) + (defun TeX-master-file (&optional extension nondirectory ask) "Set and return the name of the master file for the current document. @@ -2463,7 +2494,11 @@ name of master file if it cannot be determined otherwise." ;; Ask the user (but add it as a local variable). (ask (TeX-master-file-ask))))) - (let ((name (if (stringp TeX-master) + (if (and TeX-output-dir + (when-let (reg (TeX--clean-extensions-regexp t)) + (string-match-p reg (concat "." extension)))) + (TeX-master-output-file extension) + (let ((name (if (stringp TeX-master) TeX-master my-name))) @@ -2481,7 +2516,7 @@ name of master file if it cannot be determined otherwise." (if extension (concat name "." extension) - name)))) + name))))) (defun TeX-master-directory () "Directory of master file." @@ -2563,6 +2598,16 @@ be relative to that." :group 'TeX-file :type 'string) +(defcustom TeX-output-dir nil + "The directory where the output files will be generated. The + directory cannot start with a `.'. + +If this variable is nil, AUCTeX will assume that the output +directory is the same as the directory of TeX-master." + :group 'TeX-file + :type '(string :format "%v")) +(put 'TeX-output-dir 'safe-local-variable 'stringp-or-null-p) + (defcustom TeX-style-local "style" "*Directory containing hand generated TeX information.