CVSROOT: /cvsroot/auctex Module name: auctex Changes by: Ralf Angeli <angeli> 11/01/22 16:24:30
Index: tex.el =================================================================== RCS file: /cvsroot/auctex/auctex/tex.el,v retrieving revision 5.671 retrieving revision 5.672 diff -u -b -r5.671 -r5.672 --- tex.el 5 Dec 2010 20:48:13 -0000 5.671 +++ tex.el 22 Jan 2011 16:24:29 -0000 5.672 @@ -1,8 +1,8 @@ ;;; tex.el --- Support for TeX documents. ;; Copyright (C) 1985, 1986, 1987, 1991, 1993, 1994, 1996, 1997, 1999, -;; 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 -;; Free Software Foundation, Inc. +;; 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, +;; 2011 Free Software Foundation, Inc. ;; Maintainer: [email protected] ;; Keywords: tex @@ -2063,61 +2063,50 @@ (setq answers (cons entry answers)))) answers)) -(defun TeX-macro-global () - "Return directories containing the site's TeX macro and style files." - (or (TeX-tree-expand '("$SYSTEXMF" "$TEXMFLOCAL" "$TEXMFMAIN" "$TEXMFDIST") - "latex" '("/tex/" "/bibtex/bst/")) - '("/usr/share/texmf/tex/" "/usr/share/texmf/bibtex/bst/"))) - -(defun TeX-macro-private () - "Return directories containing the user's TeX macro and style files." - (TeX-tree-expand '("$TEXMFHOME") "latex" '("/tex/" "/bibtex/bst/"))) - -(defun TeX-tree-expand (trees program subdirs) - "Return directories corresponding to the TeX trees TREES. -This is done calling `kpsewhich' where PROGRAM is passed as the -parameter for --progname. SUBDIRS are subdirectories which are -appended to the directories of the TeX trees." +(defun TeX-tree-expand (vars program &optional subdirs) + "Return directories corresponding to the kpathsea variables VARS. +This is done calling `kpsewhich --expand-path' for each variable. +PROGRAM is passed as the parameter for --progname. SUBDIRS are +subdirectories which are appended to the directories of the TeX +trees. Only existing directories are returned." (let (path-list path exit-status input-dir-list) (condition-case nil - (catch 'success - (dotimes (i (safe-length trees)) - (setq path (with-output-to-string - (setq exit-status - (call-process - "kpsewhich" nil - (list standard-output nil) nil - "--progname" program - "--expand-braces" (nth i trees))))) - (if (zerop exit-status) - (progn (add-to-list 'path-list path) - (when (zerop i) (throw 'success nil))) + (dolist (var vars) (setq path (with-output-to-string - (setq exit-status - (call-process + (setq exit-status (call-process "kpsewhich" nil (list standard-output nil) nil "--progname" program - "--expand-path" (nth i trees))))) - (when (zerop exit-status) (add-to-list 'path-list path))))) + "--expand-path" var)))) + (when (zerop exit-status) + (add-to-list 'path-list path t))) (error nil)) (dolist (elt path-list) - (let ((separators (if (string-match "^[A-Za-z]:" elt) - "[\n\r;]" - "[\n\r:]"))) + (let ((separators (if (string-match ";" elt) "[\n\r;]" "[\n\r:]"))) (dolist (item (condition-case nil (split-string elt separators t) ;; COMPATIBILITY for XEmacs <= 21.4.15 (error (delete "" (split-string elt separators))))) - (when (string-match "^!+" item) - (setq item (substring item (match-end 0) (length item)))) - (when (string-match "/+$" item) - (setq item (substring item 0 (match-beginning 0)))) + (if subdirs (dolist (subdir subdirs) - (when (file-exists-p (file-name-as-directory (concat item subdir))) - (add-to-list 'input-dir-list (concat item subdir))))))) + (setq path (file-name-as-directory (concat item subdir))) + (when (file-exists-p path) + (add-to-list 'input-dir-list path t))) + (setq path (file-name-as-directory item)) + (when (file-exists-p path) + (add-to-list 'input-dir-list path t)))))) input-dir-list)) +(defun TeX-macro-global () + "Return directories containing the site's TeX macro and style files." + (or (TeX-tree-expand '("$SYSTEXMF" "$TEXMFLOCAL" "$TEXMFMAIN" "$TEXMFDIST") + "latex" '("/tex/" "/bibtex/bst/")) + '("/usr/share/texmf/tex/" "/usr/share/texmf/bibtex/bst/"))) + +(defun TeX-macro-private () + "Return directories containing the user's TeX macro and style files." + (TeX-tree-expand '("$TEXMFHOME") "latex" '("/tex/" "/bibtex/bst/"))) + (defcustom TeX-macro-global (TeX-macro-global) "Directories containing the site's TeX macro and style files." :group 'TeX-file @@ -3104,6 +3093,24 @@ :group 'TeX-file :type 'directory) +(defcustom TeX-ignore-file + "\\(^\\|[/\\]\\)\\(\\.\\|\\.\\.\\|RCS\\|SCCS\\|CVS\\|babel\\..*\\)$" + "Regular expression matching file names to ignore. + +These files or directories will not be considered when searching for +TeX files in a directory." + :group 'TeX-parse + :type 'regexp) + +(defcustom TeX-file-recurse t + "Whether to search TeX directories recursively. +nil means do not recurse, a positive integer means go that far deep in the +directory hierarchy, t means recurse indefinitely." + :group 'TeX-parse + :type '(choice (const :tag "On" t) + (const :tag "Off" nil) + (integer :tag "Depth" :value 1))) + ;;;###autoload (defun TeX-auto-generate (tex auto) "Generate style file for TEX and store it in AUTO. @@ -3217,6 +3224,22 @@ "theenumv" "document" "par" "do" "expandafter") "List of symbols to ignore when scanning a TeX style file.") +(defcustom TeX-auto-regexp-list 'TeX-auto-full-regexp-list + "List of regular expressions used for parsing the current file." + :type '(radio (variable-item TeX-auto-empty-regexp-list) + (variable-item TeX-auto-full-regexp-list) + (variable-item plain-TeX-auto-regexp-list) + (variable-item LaTeX-auto-minimal-regexp-list) + (variable-item LaTeX-auto-label-regexp-list) + (variable-item LaTeX-auto-regexp-list) + (symbol :tag "Other") + (repeat :tag "Specify" + (group (regexp :tag "Match") + (sexp :tag "Groups") + symbol))) + :group 'TeX-parse) + (make-variable-buffer-local 'TeX-auto-regexp-list) + (defun TeX-auto-add-regexp (regexp) "Add REGEXP to `TeX-auto-regexp-list' if not already a member." (if (symbolp TeX-auto-regexp-list) @@ -3417,26 +3440,8 @@ (add-to-list 'TeX-auto-symbol elt)) (add-to-list 'TeX-auto-symbol symbol))))) -;;; Utilities -;; -;; Some of these functions has little to do with TeX, but nonetheless we -;; should use the "TeX-" prefix to avoid name clashes. -(defcustom TeX-auto-regexp-list 'TeX-auto-full-regexp-list - "*List of regular expressions used for parsing the current file." - :type '(radio (variable-item TeX-auto-empty-regexp-list) - (variable-item TeX-auto-full-regexp-list) - (variable-item plain-TeX-auto-regexp-list) - (variable-item LaTeX-auto-minimal-regexp-list) - (variable-item LaTeX-auto-label-regexp-list) - (variable-item LaTeX-auto-regexp-list) - (symbol :tag "Other") - (repeat :tag "Specify" - (group (regexp :tag "Match") - (sexp :tag "Groups") - symbol))) - :group 'TeX-parse) - (make-variable-buffer-local 'TeX-auto-regexp-list) +;;; File Extensions (defgroup TeX-file-extension nil "File extensions recognized by AUCTeX." @@ -3459,6 +3464,11 @@ (make-variable-buffer-local 'TeX-default-extension) +(defvar TeX-doc-extenstions + '("dvi" "pdf" "ps" "txt" "html" "dvi.gz" "pdf.gz" "ps.gz" "txt.gz" "html.gz" + "dvi.bz2" "pdf.bz2" "ps.bz2" "txt.bz2" "html.bz2") + "File extensions of documentation files.") + (defcustom docTeX-default-extension "dtx" "*Default extension for docTeX files." :group 'TeX-file-extension @@ -3482,23 +3492,6 @@ :group 'TeX-file-extension :type '(repeat (string :format "%v"))) -(defcustom TeX-ignore-file "\\(^\\|[/\\]\\)\\(\\.\\|\\.\\.\\|RCS\\|SCCS\\|CVS\\|babel\\..*\\)$" - "Regular expression matching file names to ignore. - -These files or directories will not be considered when searching for -TeX files in a directory." - :group 'TeX-parse - :type 'regexp) - -(defcustom TeX-file-recurse t - "*Whether to search TeX directories recursively. -nil means do not recurse, a positive integer means go that far deep in the -directory hierarchy, t means recurse indefinitely." - :group 'TeX-parse - :type '(choice (const :tag "On" t) - (const :tag "Off" nil) - (integer :tag "Depth" :value 1))) - (defun TeX-match-extension (file &optional extensions) "Return non-nil if FILE has one of EXTENSIONS. @@ -3541,6 +3534,23 @@ (file-name-nondirectory strip) strip))) + +;;; File Searching + +(defun TeX-tree-roots () + "Return a list of available TeX tree roots." + (let (list) + (dolist (dir (TeX-tree-expand '("$TEXMFHOME" "$TEXMFMAIN" "$TEXMFLOCAL" + "$TEXMFDIST") "latex")) + (when (file-readable-p dir) + (add-to-list 'list dir t))) + list)) + +(defcustom TeX-tree-roots (TeX-tree-roots) + "List of all available TeX tree root directories." + :group 'TeX-file + :type '(repeat directory)) + (defcustom TeX-kpathsea-path-delimiter t "Path delimiter for kpathsea output. t means autodetect, nil means kpathsea is disabled." @@ -3550,77 +3560,44 @@ (const :tag "Autodetect" t) (const :tag "Off" nil))) -(defcustom TeX-kpathsea-format-alist - '(("tex" "${TEXINPUTS.latex}" TeX-file-extensions) - ("sty" "${TEXINPUTS.latex}" '("sty")) - ("dvi" "${TEXDOCS}" '("dvi" "pdf" "ps" "txt" "html" - "dvi.gz" "pdf.gz" "ps.gz" "txt.gz" "html.gz" - "dvi.bz2" "pdf.bz2" "ps.bz2" "txt.bz2" "html.bz2")) - ("eps" "${TEXINPUTS}" LaTeX-includegraphics-extensions) - ("pdf" "${TEXINPUTS}" LaTeX-includegraphics-extensions) - ("png" "${TEXINPUTS}" LaTeX-includegraphics-extensions) - ("jpg" "${TEXINPUTS}" LaTeX-includegraphics-extensions) - ("jpeg" "${TEXINPUTS}" LaTeX-includegraphics-extensions) - ("bib" "$BIBINPUTS" BibTeX-file-extensions) - ("bst" "$BSTINPUTS" BibTeX-style-extensions)) - "Formats to search for expansion using kpathsea. -The key of the alist represents the name of the format. The -first element of the cdr of the alist is string to expand by the -respective kpathsea program and the second element is a list of -file extensions to match." - :group 'TeX-file - :type '(alist :key-type string :value-type (group string sexp))) - -;; FIXME: Despite the first parameter named `extensions', -;; `TeX-search-files-kpathsea' basically treats this as a format -;; specifier. Only the first element in the respective list will be -;; used to determine the search paths and file extensions with the -;; help of `TeX-kpathsea-format-alist'. Out of these differences -;; arises a need to unify the behavior of `TeX-search-files' and -;; `TeX-search-files-kpathsea' and their treatment of parameters. -;; Additionally `TeX-search-files-kpathsea' should be made more -;; general to work with other platforms and TeX systems as well. -(defun TeX-search-files-kpathsea (extensions nodir strip) - "The kpathsea-enabled version of `TeX-search-files'. -Except for DIRECTORIES (a kpathsea string), the arguments for -EXTENSIONS, NODIR and STRIP are explained there." +;; We keep this function in addition to `TeX-search-files' because it +;; is faster. Since it does not look further into subdirectories, +;; this comes at the price of finding a smaller number of files. +(defun TeX-search-files-kpathsea (var extensions scope nodir strip) + "Return a list of files in directories determined by expanding VAR. +Only files which match EXTENSIONS are returned. SCOPE defines +the scope for the search and can be `local' or `global' besides +nil. If NODIR is non-nil, remove directory part. If STRIP is +non-nil, remove file extension." (and TeX-kpathsea-path-delimiter (catch 'no-kpathsea - (let* ((format-spec (assoc (car extensions) - TeX-kpathsea-format-alist)) - (dirs (with-output-to-string - (unless (zerop - (call-process - "kpsewhich" nil (list standard-output nil) - nil - (concat - "-expand-path=" - (nth 1 format-spec)))) + (let* ((dirs (if (eq scope 'local) + "." + (with-output-to-string + (unless (zerop (call-process + "kpsewhich" nil + (list standard-output nil) nil + (concat "-expand-path=" var))) (if (eq TeX-kpathsea-path-delimiter t) (throw 'no-kpathsea (setq TeX-kpathsea-path-delimiter nil)) - (error "kpsewhich error"))))) + (error "kpsewhich error")))))) result) (when (eq TeX-kpathsea-path-delimiter t) (setq TeX-kpathsea-path-delimiter - (cond ((string-match ";" dirs) - ";") - ((string-match ":" dirs) - ":")))) + (if (string-match ";" dirs) ";" ":"))) (unless TeX-kpathsea-path-delimiter (throw 'no-kpathsea nil)) - (setq dirs (split-string dirs (concat "[\n\r" + (setq dirs (delete "" (split-string + dirs (concat "[\n\r" TeX-kpathsea-path-delimiter - "]+"))) - (setq extensions (concat "\\." - (regexp-opt (eval (nth 2 format-spec)) t) - "\\'")) - (setq result - (apply #'append - (mapcar - (lambda(x) (directory-files x - (not nodir) - extensions)) + "]+")))) + (if (eq scope 'global) + (delete "." dirs)) + (setq extensions (concat "\\." (regexp-opt extensions t) "\\'") + result (apply #'append (mapcar (lambda (x) + (directory-files + x (not nodir) extensions)) dirs))) (if strip (mapcar (lambda(x) @@ -3637,13 +3614,10 @@ If optional argument DIRECTORIES is set, search in those directories. Otherwise, search in all TeX macro directories. If optional argument EXTENSIONS is not set, use `TeX-file-extensions'" - (if (null extensions) + (when (null extensions) (setq extensions TeX-file-extensions)) - (or (TeX-search-files-kpathsea extensions nodir strip) - (progn - (if (null directories) - (setq directories - (cons "./" (append TeX-macro-private TeX-macro-global)))) + (when (null directories) + (setq directories (cons "./" (append TeX-macro-private TeX-macro-global)))) (let (match (TeX-file-recurse (cond ((symbolp TeX-file-recurse) TeX-file-recurse) @@ -3668,15 +3642,89 @@ (append match (TeX-search-files (list (file-name-as-directory file)) - extensions - nodir strip))))) + extensions nodir strip))))) ((TeX-match-extension file extensions) - (setq match (cons (TeX-strip-extension file - extensions - nodir - (not strip)) + (setq match (cons (TeX-strip-extension + file extensions nodir (not strip)) match)))))))) - match)))) + match)) + +;; The variables `TeX-macro-private' and `TeX-macro-global' are not +;; used for specifying the directories because the number of +;; directories to be searched should be limited as much as possible +;; and the TeX-macro-* variables are just too broad for this. +(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. +Each element of the alist consists of a symbol expressing the +filetype, a variable which can be expanded on kpathsea-based +systems into the directories where files of the given type +reside, a list of absolute directories, relative directories +below the root of a TDS-compliant TeX tree or a list of variables +with either type of directories as an alternative for +non-kpathsea-based systems and a list of extensions to be matched +upon a file search. Note that the directories have to end with a +directory separator. + +Each AUCTeX mode should set the variable buffer-locally with a +more specific value. See `LateX-search-files-type-alist' for an +example.") + +(defun TeX-search-files-by-type (filetype &optional scope nodir strip) + "Return a list of files in TeX's search path with type FILETYPE. +FILETYPE is a symbol used to choose the search paths and +extensions. See `TeX-search-file-type-alist' for supported +symbols. + +The optional argument SCOPE sets the scope for the search. +Besides nil the symbols `local' and `global' are accepted. +`local' means to search in the current directory only, `global' +in the global directories only and nil in both. + +If optional argument NODIR is non-nil, remove directory part. + +If optional argument STRIP is non-nil, remove file extension." + (let* ((spec (assq filetype TeX-search-files-type-alist)) + (kpse-var (nth 1 spec)) + (rawdirs (nth 2 spec)) + (exts (nth 3 spec)) + expdirs dirs local-files) + (setq exts (if (symbolp exts) (eval exts) exts)) + (or (TeX-search-files-kpathsea kpse-var exts scope nodir strip) + (progn + (unless (eq scope 'global) + (setq local-files + (let ((TeX-file-recurse nil)) + (TeX-search-files '("./") exts nodir strip)))) + (if (eq scope 'local) + local-files + (if (null TeX-tree-roots) + (error "No TeX trees available; configure `TeX-tree-roots'") + ;; Expand variables. + (dolist (rawdir rawdirs) + (if (symbolp rawdir) + (setq expdirs (append expdirs (eval rawdir))) + (add-to-list 'expdirs rawdir t))) + (delete-dups expdirs) + ;; Assumption: Either all paths are absolute or all are relative. + (if (file-name-absolute-p (car expdirs)) + (setq dirs expdirs) + ;; Append relative TDS subdirs to all TeX tree roots. + (dolist (root TeX-tree-roots) + (dolist (dir expdirs) + (add-to-list 'dirs (concat (file-name-as-directory root) + dir) t))))) + (append local-files (TeX-search-files dirs exts nodir strip))))))) + + +;;; Utilities +;; +;; Some of these functions has little to do with TeX, but nonetheless we +;; should use the "TeX-" prefix to avoid name clashes. (defun TeX-car-string-lessp (s1 s2) "Compare the cars of S1 and S2 in lexicographic order. _______________________________________________ auctex-diffs mailing list [email protected] http://lists.gnu.org/mailman/listinfo/auctex-diffs
