diff options
| author | Carsten Dominik | 1998-09-28 14:29:49 +0000 |
|---|---|---|
| committer | Carsten Dominik | 1998-09-28 14:29:49 +0000 |
| commit | 51d628c817d52ae1c71dd595bd9084fdf4c750a1 (patch) | |
| tree | a0c818346f38dfb51caf91a697d4ed38511de187 | |
| parent | 9eb580d27f243c3978a83794cf73968b3c3541d5 (diff) | |
| download | emacs-51d628c817d52ae1c71dd595bd9084fdf4c750a1.tar.gz emacs-51d628c817d52ae1c71dd595bd9084fdf4c750a1.zip | |
(reftex-finding-files): New customize group.
(reftex-texpath-environment-variables,
reftex-use-external-file-finders, reftex-external-file-finders,
reftex-search-unrecursed-path-first): New options.
(reftex-process-string, reftex-find-file-externally): New
functions.
(reftex-access-search-path): Execute shell commands to find the
search path.
(reftex-toggle-auto-view-crossref): When turning on, make sure
`reftex-auto-view-crossref' becomes non-nil.
(reftex-abbrev-regexp): Constant removed.
(reftex-convert-string): Abbrev regexp calculated locally.
| -rw-r--r-- | lisp/textmodes/reftex.el | 183 |
1 files changed, 144 insertions, 39 deletions
diff --git a/lisp/textmodes/reftex.el b/lisp/textmodes/reftex.el index d3ab77812ac..47389c63e7d 100644 --- a/lisp/textmodes/reftex.el +++ b/lisp/textmodes/reftex.el | |||
| @@ -162,10 +162,10 @@ | |||
| 162 | ;; developing it with their reports. In particular thanks to | 162 | ;; developing it with their reports. In particular thanks to |
| 163 | ;; | 163 | ;; |
| 164 | ;; F. Burstall, Alastair Burt, Soren Dayton, Stephen Eglen, | 164 | ;; F. Burstall, Alastair Burt, Soren Dayton, Stephen Eglen, |
| 165 | ;; Karl Eichwalder, Peter Galbraith, Dieter Kraft, Adrian Lanz, | 165 | ;; Karl Eichwalder, Peter Galbraith, Dieter Kraft, Kai Grossjohann, |
| 166 | ;; Rory Molinari, Laurent Mugnier, Sudeep Kumar Palat, Daniel Polani, | 166 | ;; Adrian Lanz, Rory Molinari, Laurent Mugnier, Sudeep Kumar Palat, |
| 167 | ;; Robin Socha, Richard Stanton, Allan Strand, Jan Vroonhof, | 167 | ;; Daniel Polani, Robin Socha, Richard Stanton, Allan Strand, |
| 168 | ;; Christoph Wedler, Alan Williams. | 168 | ;; Jan Vroonhof, Christoph Wedler, Alan Williams. |
| 169 | ;; | 169 | ;; |
| 170 | ;; Finally thanks to Uwe Bolick who first got me (some years ago) into | 170 | ;; Finally thanks to Uwe Bolick who first got me (some years ago) into |
| 171 | ;; supporting LaTeX labels and references with an Editor (which was | 171 | ;; supporting LaTeX labels and references with an Editor (which was |
| @@ -799,14 +799,6 @@ string to insert into the buffer." | |||
| 799 | "Support for referencing bibliographic data with BibTeX." | 799 | "Support for referencing bibliographic data with BibTeX." |
| 800 | :group 'reftex) | 800 | :group 'reftex) |
| 801 | 801 | ||
| 802 | (defcustom reftex-bibpath-environment-variables '("BIBINPUTS" "TEXBIB") | ||
| 803 | "*List of env vars which might contain the path to BibTeX database files. | ||
| 804 | Directories ending in `//' or `!!' will be expanded recursively when necessary | ||
| 805 | to find files." | ||
| 806 | :group 'reftex-citation-support | ||
| 807 | :set 'reftex-set-dirty | ||
| 808 | :type '(repeat (string :tag "Environment variable"))) | ||
| 809 | |||
| 810 | (defvar reftex-bibfile-ignore-list nil) ; compatibility | 802 | (defvar reftex-bibfile-ignore-list nil) ; compatibility |
| 811 | (defcustom reftex-bibfile-ignore-regexps nil | 803 | (defcustom reftex-bibfile-ignore-regexps nil |
| 812 | "*List of regular expressions to exclude files in \\bibliography{..}. | 804 | "*List of regular expressions to exclude files in \\bibliography{..}. |
| @@ -1020,6 +1012,77 @@ for X-Symbol, but may have other uses as well." | |||
| 1020 | :group 'reftex-referencing-labels | 1012 | :group 'reftex-referencing-labels |
| 1021 | :type 'hook) | 1013 | :type 'hook) |
| 1022 | 1014 | ||
| 1015 | ;; Finding Files -------------------------------------------------------- | ||
| 1016 | |||
| 1017 | (defgroup reftex-finding-files nil | ||
| 1018 | "Displaying cross references and citations." | ||
| 1019 | :group 'reftex) | ||
| 1020 | |||
| 1021 | (defcustom reftex-texpath-environment-variables '("TEXINPUTS") | ||
| 1022 | "*List of specifications how to retrieve the search path for TeX files. | ||
| 1023 | Several entries are possible. | ||
| 1024 | - If an element is the name of an environment variable, its content is used. | ||
| 1025 | - If an element starts with an exclamation mark, it is used as a command | ||
| 1026 | to retrieve the path. A typical command with the kpathsearch library would | ||
| 1027 | be `!kpsewhich -show-path=.tex'. | ||
| 1028 | - Otherwise the element itself is interpreted as a path. | ||
| 1029 | Multiple directories can be separated by the system dependent `path-separator'. | ||
| 1030 | Directories ending in `//' or `!!' will be expanded recursively. | ||
| 1031 | See also `reftex-use-external-file-finders'." | ||
| 1032 | :group 'reftex-finding-files | ||
| 1033 | :set 'reftex-set-dirty | ||
| 1034 | :type '(repeat (string :tag "Specification"))) | ||
| 1035 | |||
| 1036 | (defcustom reftex-bibpath-environment-variables '("BIBINPUTS" "TEXBIB") | ||
| 1037 | "*List of specifications how to retrieve search path for .bib database files. | ||
| 1038 | Several entries are possible. | ||
| 1039 | - If an element is the name of an environment variable, its content is used. | ||
| 1040 | - If an element starts with an exclamation mark, it is used as a command | ||
| 1041 | to retrieve the path. A typical command with the kpathsearch library would | ||
| 1042 | be `!kpsewhich -show-path=.bib'. | ||
| 1043 | - Otherwise the element itself is interpreted as a path. | ||
| 1044 | Multiple directories can be separated by the system dependent `path-separator'. | ||
| 1045 | Directories ending in `//' or `!!' will be expanded recursively. | ||
| 1046 | See also `reftex-use-external-file-finders'." | ||
| 1047 | :group 'reftex-citation-support | ||
| 1048 | :group 'reftex-finding-files | ||
| 1049 | :set 'reftex-set-dirty | ||
| 1050 | :type '(repeat (string :tag "Specification"))) | ||
| 1051 | |||
| 1052 | (defcustom reftex-search-unrecursed-path-first t | ||
| 1053 | "*Non-nil means, search all specified directories before trying recursion. | ||
| 1054 | Thus, in a path \".//:/tex/\", search first \"./\", then \"/tex/\" and then | ||
| 1055 | all subdirectories of \"./\". If this option is nil, the subdirectories of | ||
| 1056 | \"./\" are searched before \"/tex/\". This is mainly for speed - most of the | ||
| 1057 | time the recursive path is for the system files and not for the user files. | ||
| 1058 | Set this to nil if the default makes RefTeX finding files with equal names | ||
| 1059 | in wrong sequence." | ||
| 1060 | :group 'reftex-finding-files | ||
| 1061 | :type 'boolean) | ||
| 1062 | |||
| 1063 | (defcustom reftex-use-external-file-finders nil | ||
| 1064 | "*Non-nil means, use external programs to find files. | ||
| 1065 | Normally, RefTeX searches the paths given in the environment variables | ||
| 1066 | TEXINPUTS and BIBINPUTS to find TeX files and BibTeX database files. | ||
| 1067 | With this option turned on, it calls an external program specified in the | ||
| 1068 | option `reftex-external-file-finders' instead. As a side effect, | ||
| 1069 | the variables `reftex-texpath-environment-variables' and | ||
| 1070 | `reftex-bibpath-environment-variables' will be ignored." | ||
| 1071 | :group 'reftex-finding-files | ||
| 1072 | :type 'boolean) | ||
| 1073 | |||
| 1074 | (defcustom reftex-external-file-finders '(("tex" . "kpsewhich -format=.tex %f") | ||
| 1075 | ("bib" . "kpsewhich -format=.bib %f")) | ||
| 1076 | "*Association list with external programs to call for finding files. | ||
| 1077 | Each entry is a cons cell (TYPE . PROGRAM). | ||
| 1078 | Type is either \"tex\" or \"bib\". PROGRAM is the external program to use with | ||
| 1079 | any arguments. %f will be replaced by the name of the file to be found. | ||
| 1080 | Note that these commands will be executed directly, not via a shell. | ||
| 1081 | Only relevant when `reftex-use-external-file-finders' is non-nil." | ||
| 1082 | :group 'reftex-finding-files | ||
| 1083 | :type '(repeat (cons (string :tag "File type") | ||
| 1084 | (string :tag "Program ")))) | ||
| 1085 | |||
| 1023 | ;; Tuning the parser ---------------------------------------------------- | 1086 | ;; Tuning the parser ---------------------------------------------------- |
| 1024 | 1087 | ||
| 1025 | (defgroup reftex-optimizations-for-large-documents nil | 1088 | (defgroup reftex-optimizations-for-large-documents nil |
| @@ -1295,7 +1358,7 @@ construct: \\bbb [xxx] {aaa}." | |||
| 1295 | ;;; Define the formal stuff for a minor mode named RefTeX. | 1358 | ;;; Define the formal stuff for a minor mode named RefTeX. |
| 1296 | ;;; | 1359 | ;;; |
| 1297 | 1360 | ||
| 1298 | (defconst reftex-version "RefTeX version 3.38" | 1361 | (defconst reftex-version "RefTeX version 3.41" |
| 1299 | "Version string for RefTeX.") | 1362 | "Version string for RefTeX.") |
| 1300 | 1363 | ||
| 1301 | (defvar reftex-mode nil | 1364 | (defvar reftex-mode nil |
| @@ -1536,16 +1599,6 @@ on the menu bar. | |||
| 1536 | (defconst reftex-no-info-message | 1599 | (defconst reftex-no-info-message |
| 1537 | "%s: info not available, use `\\[reftex-view-crossref]' to get it.") | 1600 | "%s: info not available, use `\\[reftex-view-crossref]' to get it.") |
| 1538 | 1601 | ||
| 1539 | ;; The regular expression used to abbreviate words. | ||
| 1540 | (defconst reftex-abbrev-regexp | ||
| 1541 | (concat | ||
| 1542 | "\\`\\(" | ||
| 1543 | (make-string (nth 0 reftex-abbrev-parameters) ?.) | ||
| 1544 | "[" (nth 2 reftex-abbrev-parameters) "]*" | ||
| 1545 | "\\)" | ||
| 1546 | "[" (nth 3 reftex-abbrev-parameters) "]" | ||
| 1547 | (make-string (1- (nth 1 reftex-abbrev-parameters)) ?.))) | ||
| 1548 | |||
| 1549 | ;; Global variables used for communication between functions. | 1602 | ;; Global variables used for communication between functions. |
| 1550 | (defvar reftex-default-context-position nil) | 1603 | (defvar reftex-default-context-position nil) |
| 1551 | (defvar reftex-location-start nil) | 1604 | (defvar reftex-location-start nil) |
| @@ -2657,6 +2710,13 @@ IGNORE-WORDS List of words which should be removed from the string." | |||
| 2657 | 2710 | ||
| 2658 | (let* ((words0 (split-string string (or split-re "[ \t\n\r]"))) | 2711 | (let* ((words0 (split-string string (or split-re "[ \t\n\r]"))) |
| 2659 | (reftex-label-illegal-re (or illegal-re "\000")) | 2712 | (reftex-label-illegal-re (or illegal-re "\000")) |
| 2713 | (abbrev-re (concat | ||
| 2714 | "\\`\\(" | ||
| 2715 | (make-string (nth 0 reftex-abbrev-parameters) ?.) | ||
| 2716 | "[" (nth 2 reftex-abbrev-parameters) "]*" | ||
| 2717 | "\\)" | ||
| 2718 | "[" (nth 3 reftex-abbrev-parameters) "]" | ||
| 2719 | (make-string (1- (nth 1 reftex-abbrev-parameters)) ?.))) | ||
| 2660 | words word) | 2720 | words word) |
| 2661 | 2721 | ||
| 2662 | ;; Remove words from the ignore list or with funny characters | 2722 | ;; Remove words from the ignore list or with funny characters |
| @@ -2687,7 +2747,7 @@ IGNORE-WORDS List of words which should be removed from the string." | |||
| 2687 | (setq words | 2747 | (setq words |
| 2688 | (mapcar | 2748 | (mapcar |
| 2689 | (function | 2749 | (function |
| 2690 | (lambda (w) (if (string-match reftex-abbrev-regexp w) | 2750 | (lambda (w) (if (string-match abbrev-re w) |
| 2691 | (if dot | 2751 | (if dot |
| 2692 | (concat (match-string 1 w) ".") | 2752 | (concat (match-string 1 w) ".") |
| 2693 | (match-string 1 w)) | 2753 | (match-string 1 w)) |
| @@ -5195,6 +5255,8 @@ will display info in the echo area." | |||
| 5195 | nil) | 5255 | nil) |
| 5196 | (run-with-idle-timer | 5256 | (run-with-idle-timer |
| 5197 | reftex-idle-time t 'reftex-view-crossref-when-idle))) | 5257 | reftex-idle-time t 'reftex-view-crossref-when-idle))) |
| 5258 | (unless reftex-auto-view-crossref | ||
| 5259 | (setq reftex-auto-view-crossref t)) | ||
| 5198 | (message "Automatic display of crossref information was turned on"))) | 5260 | (message "Automatic display of crossref information was turned on"))) |
| 5199 | 5261 | ||
| 5200 | (defun reftex-start-itimer-once () | 5262 | (defun reftex-start-itimer-once () |
| @@ -5315,11 +5377,17 @@ will display info in the echo area." | |||
| 5315 | (defun reftex-find-tex-file (file master-dir &optional die) | 5377 | (defun reftex-find-tex-file (file master-dir &optional die) |
| 5316 | ;; Find FILE in MASTER-DIR or on reftex-tex-path. | 5378 | ;; Find FILE in MASTER-DIR or on reftex-tex-path. |
| 5317 | ;; FILE may be given with or without the .tex extension. | 5379 | ;; FILE may be given with or without the .tex extension. |
| 5318 | (let ((rec-values '(nil t)) path file1 old-path) | 5380 | (let ((rec-values (if reftex-search-unrecursed-path-first '(nil t) '(t))) |
| 5319 | (if (file-name-absolute-p file) | 5381 | path file1 old-path) |
| 5320 | (if (file-regular-p (concat file ".tex")) | 5382 | (cond |
| 5321 | (setq file1 (concat file ".tex")) | 5383 | ((file-name-absolute-p file) |
| 5322 | (if (file-regular-p file) (setq file1 file))) | 5384 | (if (file-regular-p (concat file ".tex")) |
| 5385 | (setq file1 (concat file ".tex")) | ||
| 5386 | (if (file-regular-p file) (setq file1 file)))) | ||
| 5387 | ((and reftex-use-external-file-finders | ||
| 5388 | (assoc "tex" reftex-external-file-finders)) | ||
| 5389 | (setq file1 (reftex-find-file-externally file "tex" master-dir))) | ||
| 5390 | (t | ||
| 5323 | (while (and (null file1) rec-values) | 5391 | (while (and (null file1) rec-values) |
| 5324 | (setq path (reftex-access-search-path | 5392 | (setq path (reftex-access-search-path |
| 5325 | "tex" (pop rec-values) master-dir file)) | 5393 | "tex" (pop rec-values) master-dir file)) |
| @@ -5329,16 +5397,23 @@ will display info in the echo area." | |||
| 5329 | path (cons master-dir path) | 5397 | path (cons master-dir path) |
| 5330 | file1 (or (reftex-find-file-on-path | 5398 | file1 (or (reftex-find-file-on-path |
| 5331 | (concat file ".tex") path master-dir) | 5399 | (concat file ".tex") path master-dir) |
| 5332 | (reftex-find-file-on-path file path master-dir)))))) | 5400 | (reftex-find-file-on-path file path master-dir))))))) |
| 5333 | (cond (file1 file1) | 5401 | (cond (file1 file1) |
| 5334 | (die (error "No such file: %s" file) nil) | 5402 | (die (error "No such file: %s" file) nil) |
| 5335 | (t (message "No such file: %s (ignored)" file) nil)))) | 5403 | (t (message "No such file: %s (ignored)" file) nil)))) |
| 5336 | 5404 | ||
| 5337 | (defun reftex-find-bib-file (file master-dir &optional die) | 5405 | (defun reftex-find-bib-file (file master-dir &optional die) |
| 5338 | ;; Find FILE in MASTER-DIR or on reftex-bib-path | 5406 | ;; Find FILE in MASTER-DIR or on reftex-bib-path. |
| 5339 | (let ((rec-values '(nil t)) path file1 old-path) | 5407 | ;; File must be given already with the .bib extension. |
| 5340 | (if (file-name-absolute-p file) | 5408 | (let ((rec-values (if reftex-search-unrecursed-path-first '(nil t) '(t))) |
| 5341 | (if (file-regular-p file) (setq file1 file)) | 5409 | path file1 old-path) |
| 5410 | (cond | ||
| 5411 | ((file-name-absolute-p file) | ||
| 5412 | (if (file-regular-p file) (setq file1 file))) | ||
| 5413 | ((and reftex-use-external-file-finders | ||
| 5414 | (assoc "bib" reftex-external-file-finders)) | ||
| 5415 | (setq file1 (reftex-find-file-externally file "bib" master-dir))) | ||
| 5416 | (t | ||
| 5342 | (while (and (null file1) rec-values) | 5417 | (while (and (null file1) rec-values) |
| 5343 | (setq path (reftex-access-search-path | 5418 | (setq path (reftex-access-search-path |
| 5344 | "bib" (pop rec-values) master-dir file)) | 5419 | "bib" (pop rec-values) master-dir file)) |
| @@ -5346,11 +5421,34 @@ will display info in the echo area." | |||
| 5346 | (not (eq old-path path))) | 5421 | (not (eq old-path path))) |
| 5347 | (setq old-path path | 5422 | (setq old-path path |
| 5348 | path (cons master-dir path) | 5423 | path (cons master-dir path) |
| 5349 | file1 (reftex-find-file-on-path file path master-dir))))) | 5424 | file1 (reftex-find-file-on-path file path master-dir)))))) |
| 5350 | (cond (file1 file1) | 5425 | (cond (file1 file1) |
| 5351 | (die (error "No such file: %s" file) nil) | 5426 | (die (error "No such file: %s" file) nil) |
| 5352 | (t (message "No such file: %s (ignored)" file) nil)))) | 5427 | (t (message "No such file: %s (ignored)" file) nil)))) |
| 5353 | 5428 | ||
| 5429 | (defun reftex-find-file-externally (file type &optional master-dir) | ||
| 5430 | ;; Use external program to find FILE. | ||
| 5431 | ;; The program is the association of TYPE in `reftex-external-file-finders'. | ||
| 5432 | ;; Interprete relative path definitions starting from MASTER-DIR. | ||
| 5433 | (let ((default-directory (or master-dir default-directory)) | ||
| 5434 | (prg (cdr (assoc type reftex-external-file-finders))) | ||
| 5435 | out) | ||
| 5436 | (if (string-match "%f" prg) | ||
| 5437 | (setq prg (replace-match file t t prg))) | ||
| 5438 | (setq out (apply 'reftex-process-string (split-string prg))) | ||
| 5439 | (if (string-match "[ \t\n]+\\'" out) | ||
| 5440 | (setq out (replace-match "" nil nil out))) | ||
| 5441 | (cond ((equal out "") nil) | ||
| 5442 | ((file-regular-p out) out) | ||
| 5443 | (t nil)))) | ||
| 5444 | |||
| 5445 | (defun reftex-process-string (program &rest args) | ||
| 5446 | "Execute PROGRAM with arguments ARGS and return its STDOUT as a string." | ||
| 5447 | (with-output-to-string | ||
| 5448 | (with-current-buffer | ||
| 5449 | standard-output | ||
| 5450 | (apply 'call-process program nil '(t nil) nil args)))) | ||
| 5451 | |||
| 5354 | (defun reftex-access-search-path (which &optional recurse master-dir file) | 5452 | (defun reftex-access-search-path (which &optional recurse master-dir file) |
| 5355 | ;; Access path from environment variables. WHICH is either "tex" or "bib". | 5453 | ;; Access path from environment variables. WHICH is either "tex" or "bib". |
| 5356 | ;; When RECURSE is t, expand path elements ending in `//' recursively. | 5454 | ;; When RECURSE is t, expand path elements ending in `//' recursively. |
| @@ -5362,11 +5460,18 @@ will display info in the echo area." | |||
| 5362 | (let* ((pathvar (intern (concat "reftex-" which "-path")))) | 5460 | (let* ((pathvar (intern (concat "reftex-" which "-path")))) |
| 5363 | (when (null (get pathvar 'status)) | 5461 | (when (null (get pathvar 'status)) |
| 5364 | ;; Get basic path from environment | 5462 | ;; Get basic path from environment |
| 5365 | (let ((env-vars (if (equal which "tex") (list "TEXINPUTS") | 5463 | (let ((env-vars (if (equal which "tex") |
| 5464 | reftex-texpath-environment-variables | ||
| 5366 | reftex-bibpath-environment-variables))) | 5465 | reftex-bibpath-environment-variables))) |
| 5367 | (set pathvar (reftex-parse-colon-path | 5466 | (set pathvar |
| 5368 | (mapconcat (lambda(x) (or (getenv x) "")) | 5467 | (reftex-parse-colon-path |
| 5369 | env-vars path-separator)))) | 5468 | (mapconcat |
| 5469 | (lambda(x) | ||
| 5470 | (if (string-match "^!" x) | ||
| 5471 | (apply 'reftex-process-string | ||
| 5472 | (split-string (substring x 1))) | ||
| 5473 | (or (getenv x) x))) | ||
| 5474 | env-vars path-separator)))) | ||
| 5370 | (put pathvar 'status 'split) | 5475 | (put pathvar 'status 'split) |
| 5371 | ;; Check if we have recursive elements | 5476 | ;; Check if we have recursive elements |
| 5372 | (let ((path (symbol-value pathvar)) dir rec) | 5477 | (let ((path (symbol-value pathvar)) dir rec) |