>From address@hidden Tue Oct 03 18:27:18 2017 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [PATCH] Use `TeX-search-files-by-type' to assist input \includegraphics X-Mercurial-Node: 9b9492ece766243fe64ba0a9f8ad1a948f7c9eca X-Mercurial-Series-Index: 1 X-Mercurial-Series-Total: 1 Message-Id: X-Mercurial-Series-Id: User-Agent: Mercurial-patchbomb/4.3.1 Date: Tue, 03 Oct 2017 18:27:18 +0900 From: Ikumi Keita To: dummy * style/graphicx.el (LaTeX-includegraphics-extensions-list): New function. (LaTeX-includegraphics-extensions): Delegate most of its role to the above new function and become its wrapper. (LaTeX-includegraphics-global-files): New variable. (LaTeX-includegraphics-read-file-TeX): Use `TeX-search-files-by-type' rather than `TeX-search-files' and cache global value in the above new variable. Reflect the option `LaTeX-includegraphics-strip-extension-flag'. * tex.el (TeX-search-files-type-alist): Remove `graphics' entry, which is supplied in latex-mode by `LaTeX-search-files-type-alist'. (TeX-normal-mode): Add `LaTeX-includegraphics-global-files' to list of variables to be cleared. diff --git a/style/graphicx.el b/style/graphicx.el --- a/style/graphicx.el +++ b/style/graphicx.el @@ -105,65 +105,84 @@ LaTeX-graphicx-key-val-options)) optional))) +(defun LaTeX-includegraphics-extensions-list () + "Return appropriate extensions for input files to \\includegraphics. +Return value is a list of regexps." + (let ((temp (copy-sequence LaTeX-includegraphics-extensions))) + (cond (;; 'default TeX-engine: + (eq TeX-engine 'default) + (if ;; we want to produce a pdf + (if TeX-PDF-mode + ;; Return t if default compiler produces PDF, + ;; nil for "Dvips" or "Dvipdfmx" + (not (TeX-PDF-from-DVI)) + ;; t if pdftex is used in dvi-mode + TeX-DVI-via-PDFTeX) + ;; We're using pdflatex in pdf-mode + (delete-dups + (append LaTeX-includegraphics-pdftex-extensions + temp)) + ;; We're generating a .dvi to process with dvips or dvipdfmx + (progn + (dolist (x '("jpe?g" "pdf" "png")) + (setq temp (delete x temp))) + (delete-dups + (append LaTeX-includegraphics-dvips-extensions + temp))))) + ;; Running luatex in pdf or dvi-mode: + ((eq TeX-engine 'luatex) + (if TeX-PDF-mode + (delete-dups + (append LaTeX-includegraphics-pdftex-extensions + temp)) + (progn + (dolist (x '("jpe?g" "pdf" "png")) + (setq temp (delete x temp))) + (delete-dups + (append LaTeX-includegraphics-dvips-extensions + temp))))) + ;; Running xetex in any mode: + ((eq TeX-engine 'xetex) + (delete-dups (append LaTeX-includegraphics-xetex-extensions + temp))) + ;; For anything else + (t + temp)))) + (defun LaTeX-includegraphics-extensions (&optional list) - "Return appropriate extensions for input files to \\includegraphics." - (let* ((temp (copy-sequence LaTeX-includegraphics-extensions)) - (LaTeX-includegraphics-extensions - (cond (;; 'default TeX-engine: - (eq TeX-engine 'default) - (if ;; we want to produce a pdf - (if TeX-PDF-mode - ;; Return t if default compiler produces PDF, - ;; nil for "Dvips" or "Dvipdfmx" - (not (TeX-PDF-from-DVI)) - ;; t if pdftex is used in dvi-mode - TeX-DVI-via-PDFTeX) - ;; We're using pdflatex in pdf-mode - (delete-dups - (append LaTeX-includegraphics-pdftex-extensions - temp)) - ;; We're generating a .dvi to process with dvips or dvipdfmx - (progn - (dolist (x '("jpe?g" "pdf" "png")) - (setq temp (delete x temp))) - (delete-dups - (append LaTeX-includegraphics-dvips-extensions - temp))))) - ;; Running luatex in pdf or dvi-mode: - ((eq TeX-engine 'luatex) - (if TeX-PDF-mode - (delete-dups - (append LaTeX-includegraphics-pdftex-extensions - temp)) - (progn - (dolist (x '("jpe?g" "pdf" "png")) - (setq temp (delete x temp))) - (delete-dups - (append LaTeX-includegraphics-dvips-extensions - temp))))) - ;; Running xetex in any mode: - ((eq TeX-engine 'xetex) - (delete-dups (append LaTeX-includegraphics-xetex-extensions - temp))) - ;; For anything else - (t - temp)))) - (concat "\\." - (mapconcat 'identity - (or list LaTeX-includegraphics-extensions) - "$\\|\\.") - "$"))) + "Return appropriate extensions for input files to \\includegraphics. +Return value is a single regexp. +Optional argument LIST if non-nil is used as list of regexps of +extensions to be matched." + (unless list + (setq list (LaTeX-includegraphics-extensions-list))) + (concat "\\." (mapconcat #'identity list "$\\|\\.") "$")) + +(defvar LaTeX-includegraphics-global-files nil + "List of the non-local TeX input files. +Initialized once at the first time you prompt for an input file. +May be reset with `\\[universal-argument] \\[TeX-normal-mode]'.") (defun LaTeX-includegraphics-read-file-TeX () "Read image file for \\includegraphics. Offers all graphic files found in the TeX search path. See `LaTeX-includegraphics-read-file' for more." - (completing-read - "Image file: " - (TeX-delete-dups-by-car - (mapcar 'list - (TeX-search-files nil LaTeX-includegraphics-extensions t t))) - nil nil nil)) + (let ((LaTeX-includegraphics-extensions + (LaTeX-includegraphics-extensions-list))) + (unless LaTeX-includegraphics-global-files + (message "Searching for graphic files...") + (setq LaTeX-includegraphics-global-files + (TeX-search-files-by-type + 'graphics 'global t + LaTeX-includegraphics-strip-extension-flag)) + (message "Searching for graphic files...done")) + (completing-read + "Image file: " + (append + (TeX-search-files-by-type 'graphics 'local t + LaTeX-includegraphics-strip-extension-flag) + LaTeX-includegraphics-global-files) + nil nil nil))) (defun LaTeX-includegraphics-read-file-relative () "Read image file for \\includegraphics. diff --git a/tex.el b/tex.el --- a/tex.el +++ b/tex.el @@ -4656,7 +4656,6 @@ (defvar TeX-search-files-type-alist '((texinputs "${TEXINPUTS}" ("tex/") TeX-file-extensions) (docs "${TEXDOCS}" ("doc/") TeX-doc-extensions) - (graphics "${TEXINPUTS}" ("tex/") LaTeX-includegraphics-extensions) (bibinputs "${BIBINPUTS}" ("bibtex/bib/") BibTeX-file-extensions) (bstinputs "${BSTINPUTS}" ("bibtex/bst/") BibTeX-style-extensions)) "Alist of filetypes with locations and file extensions. @@ -6153,7 +6152,8 @@ BibLaTeX-global-style-files nil TeX-Biber-global-files nil TeX-global-input-files nil - LaTeX-global-class-files nil)) + LaTeX-global-class-files nil + LaTeX-includegraphics-global-files nil)) (let ((TeX-auto-save t)) (if (buffer-modified-p) (save-buffer)