annotate lisp/textmodes/reftex-ref.el @ 111422:2eee976277c5

Silence reftex compilation. * lisp/textmodes/reftex-toc.el (reftex-toc-do-promote) (reftex-toc-promote-prepare): Pass `delta' as an explicit argument. (reftex-toc-promote-action): Doc fix. * lisp/textmodes/reftex-sel.el (reftex-select-item): Give local variables `prompt', `data' a prefix. (reftex-select-post-command-hook, reftex-select-callback) (reftex-select-mouse-accept, reftex-select-read-cite): Update for above name changes. * lisp/textmodes/reftex-ref.el (reftex-reference): Rename local variable `refstyle' to reftex-refstyle. (reftex-offer-label-menu): Update for above name change. * lisp/textmodes/reftex-sel.el (reftex-select-toggle-varioref): Update for `refstyle' name change.
author Glenn Morris <rgm@gnu.org>
date Sat, 06 Nov 2010 12:11:38 -0700
parents 280c8ae2476d
children e19cfb89c13c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38422
7a94f1c588c4 Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 37998
diff changeset
1 ;;; reftex-ref.el --- code to create labels and references with RefTeX
74509
f7702c5f335d Update copyright years.
Glenn Morris <rgm@gnu.org>
parents: 69094
diff changeset
2
f7702c5f335d Update copyright years.
Glenn Morris <rgm@gnu.org>
parents: 69094
diff changeset
3 ;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 105813
diff changeset
4 ;; 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
27035
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
5
46612
7522419c4db0 Updated to reftex 4.17
Carsten Dominik <dominik@science.uva.nl>
parents: 38422
diff changeset
6 ;; Author: Carsten Dominik <dominik@science.uva.nl>
76672
690423f53b08 * textmodes/reftex.el: Add maintainer address.
David Kastrup <dak@gnu.org>
parents: 75347
diff changeset
7 ;; Maintainer: auctex-devel@gnu.org
69094
bfd5c5e60410 Version number change only
Carsten Dominik <dominik@science.uva.nl>
parents: 68648
diff changeset
8 ;; Version: 4.31
110015
280c8ae2476d Add "Package:" file headers to denote built-in packages.
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
9 ;; Package: reftex
27035
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
10
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
11 ;; This file is part of GNU Emacs.
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
12
94670
f4a69fedbd46 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
27035
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
94670
f4a69fedbd46 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
15 ;; the Free Software Foundation, either version 3 of the License, or
f4a69fedbd46 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
16 ;; (at your option) any later version.
27035
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
17
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
18 ;; GNU Emacs is distributed in the hope that it will be useful,
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
21 ;; GNU General Public License for more details.
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
22
083669ed376a Supply licensing info.
Richard M. Stallman <rms@gnu.org>
parents: 26910
diff changeset
23 ;; You should have received a copy of the GNU General Public License
94670
f4a69fedbd46 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
25
38422
7a94f1c588c4 Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 37998
diff changeset
26 ;;; Commentary:
7a94f1c588c4 Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 37998
diff changeset
27
7a94f1c588c4 Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 37998
diff changeset
28 ;;; Code:
7a94f1c588c4 Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 37998
diff changeset
29
26910
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
30 (eval-when-compile (require 'cl))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
31 (provide 'reftex-ref)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
32 (require 'reftex)
62467
35f6599373fc * textmodes/reftex-vars.el (reftex-cite-format-builtin): Support
Carsten Dominik <dominik@science.uva.nl>
parents: 60918
diff changeset
33 (require 'reftex-parse)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
34 ;;;
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
35
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
36 (defun reftex-label-location (&optional bound)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
37 "Return the environment or macro which determines the label type at point.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
38 If optional BOUND is an integer, limit backward searches to that point."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
39
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
40 (let* ((loc1 (reftex-what-macro reftex-label-mac-list bound))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
41 (loc2 (reftex-what-environment reftex-label-env-list bound))
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
42 (loc3 (reftex-what-special-env 1 bound))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
43 (p1 (or (cdr loc1) 0))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
44 (p2 (or (cdr loc2) 0))
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
45 (p3 (or (cdr loc3) 0))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
46 (pmax (max p1 p2 p3)))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
47
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
48 (setq reftex-location-start pmax)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
49 (cond
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
50 ((= p1 pmax)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
51 ;; A macro. Default context after macro name.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
52 (setq reftex-default-context-position (+ p1 (length (car loc1))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
53 (or (car loc1) "section"))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
54 ((= p2 pmax)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
55 ;; An environment. Default context after \begin{name}.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
56 (setq reftex-default-context-position (+ p2 8 (length (car loc2))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
57 (or (car loc2) "section"))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
58 ((= p3 pmax)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
59 ;; A special. Default context right there.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
60 (setq reftex-default-context-position p3)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
61 (setq loc3 (car loc3))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
62 (cond ((null loc3) "section")
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
63 ((symbolp loc3) (symbol-name loc3))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
64 ((stringp loc3) loc3)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
65 (t "section")))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
66 (t ;; This should not happen, I think?
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
67 "section"))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
68
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
69 (defun reftex-label-info-update (cell)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
70 ;; Update information about just one label in a different file.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
71 ;; CELL contains the old info list
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
72 (let* ((label (nth 0 cell))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
73 (typekey (nth 1 cell))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
74 ;; (text (nth 2 cell))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
75 (file (nth 3 cell))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
76 (comment (nth 4 cell))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
77 (note (nth 5 cell))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
78 (buf (reftex-get-file-buffer-force
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
79 file (not (eq t reftex-keep-temporary-buffers)))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
80 (if (not buf)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
81 (list label typekey "" file comment "LOST LABEL. RESCAN TO FIX.")
105813
df4934f25eef * textmodes/two-column.el (2C-split):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104768
diff changeset
82 (with-current-buffer buf
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
83 (save-restriction
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
84 (widen)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
85 (goto-char 1)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
86
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
87 (if (or (re-search-forward
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
88 (format reftex-find-label-regexp-format
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
89 (regexp-quote label)) nil t)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
90 (re-search-forward
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
91 (format reftex-find-label-regexp-format2
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
92 (regexp-quote label)) nil t))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
93
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
94 (progn
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
95 (backward-char 1)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
96 (append (reftex-label-info label file) (list note)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
97 (list label typekey "" file "LOST LABEL. RESCAN TO FIX.")))))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
98
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
99 (defun reftex-label-info (label &optional file bound derive env-or-mac)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
100 ;; Return info list on LABEL at point.
59534
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
101 (let* ((prefix (if (string-match "^[a-zA-Z0-9]+:" label)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
102 (match-string 0 label)))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
103 (typekey (cdr (assoc prefix reftex-prefix-to-typekey-alist)))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
104 (file (or file (buffer-file-name)))
59534
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
105 (trust reftex-trust-label-prefix)
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
106 (in-comment (reftex-in-comment)))
59534
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
107 (if (and typekey
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
108 (cond ((eq trust t) t)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
109 ((null trust) nil)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
110 ((stringp trust) (string-match trust typekey))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
111 ((listp trust) (member typekey trust))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
112 (t nil)))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
113 (list label typekey
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
114 (reftex-nicify-text (reftex-context-substring))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
115 file in-comment)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
116 (let* ((env-or-mac (or env-or-mac (reftex-label-location bound)))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
117 (typekey (nth 1 (assoc env-or-mac reftex-env-or-mac-alist)))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
118 (parse (nth 2 (assoc env-or-mac reftex-env-or-mac-alist)))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
119 (text (reftex-short-context env-or-mac parse reftex-location-start
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
120 derive)))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
121 (list label typekey text file in-comment)))))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
122
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
123 ;;; Creating labels ---------------------------------------------------------
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
124
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
125 (defun reftex-label (&optional environment no-insert)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
126 "Insert a unique label. Return the label.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
127 If ENVIRONMENT is given, don't bother to find out yourself.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
128 If NO-INSERT is non-nil, do not insert label into buffer.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
129 With prefix arg, force to rescan document first.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
130 When you are prompted to enter or confirm a label, and you reply with
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
131 just the prefix or an empty string, no label at all will be inserted.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
132 A new label is also recorded into the label list.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
133 This function is controlled by the settings of reftex-insert-label-flags."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
134
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
135 (interactive)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
136
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
137 ;; Ensure access to scanning info and rescan buffer if prefix are is '(4).
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
138 (reftex-access-scan-info current-prefix-arg)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
139
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
140 ;; Find out what kind of environment this is and abort if necessary.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
141 (if (or (not environment)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
142 (not (assoc environment reftex-env-or-mac-alist)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
143 (setq environment (reftex-label-location)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
144 (unless environment
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
145 (error "Can't figure out what kind of label should be inserted"))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
146
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
147 ;; Ok, go ahead.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
148 (catch 'exit
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
149 (let* ((entry (assoc environment reftex-env-or-mac-alist))
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
150 (typekey (nth 1 entry))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
151 (format (nth 3 entry))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
152 (macro-cell (reftex-what-macro 1))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
153 (entry1 (assoc (car macro-cell) reftex-env-or-mac-alist))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
154 label naked prefix valid default force-prompt rescan-is-useful)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
155 (when (and (or (nth 5 entry) (nth 5 entry1))
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
156 (memq (preceding-char) '(?\[ ?\{)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
157 ;; This is an argument of a label macro. Insert naked label.
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
158 (setq naked t format "%s"))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
159
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
160 (setq prefix (or (cdr (assoc typekey reftex-typekey-to-prefix-alist))
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
161 (concat typekey "-")))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
162 ;; Replace any escapes in the prefix
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
163 (setq prefix (reftex-replace-prefix-escapes prefix))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
164
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
165 ;; Make a default label.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
166 (cond
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
167
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
168 ((reftex-typekey-check typekey (nth 0 reftex-insert-label-flags))
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
169 ;; Derive a label from context.
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
170 (setq reftex-active-toc (reftex-last-assoc-before-elt
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
171 'toc (car (reftex-where-am-I))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
172 (symbol-value reftex-docstruct-symbol)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
173 (setq default (reftex-no-props
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
174 (nth 2 (reftex-label-info " " nil nil t))))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
175 ;; Catch the cases where the is actually no context available.
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
176 (if (or (string-match "NO MATCH FOR CONTEXT REGEXP" default)
60918
58a53f588384 * textmodes/refbib.el, textmodes/refer.el, textmodes/reftex-cite.el,
Werner LEMBERG <wl@gnu.org>
parents: 59534
diff changeset
177 (string-match "INVALID VALUE OF PARSE" default)
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
178 (string-match "SECTION HEADING NOT FOUND" default)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
179 (string-match "HOOK ERROR" default)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
180 (string-match "^[ \t]*$" default))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
181 (setq default prefix
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
182 force-prompt t) ; need to prompt
111422
2eee976277c5 Silence reftex compilation.
Glenn Morris <rgm@gnu.org>
parents: 110015
diff changeset
183 (setq default
2eee976277c5 Silence reftex compilation.
Glenn Morris <rgm@gnu.org>
parents: 110015
diff changeset
184 (concat prefix
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
185 (funcall reftex-string-to-label-function default)))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
186
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
187 ;; Make it unique.
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
188 (setq default (reftex-uniquify-label default nil "-"))))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
189
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
190 ((reftex-typekey-check typekey (nth 1 reftex-insert-label-flags))
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
191 ;; Minimal default: the user will be prompted.
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
192 (setq default prefix))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
193
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
194 (t
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
195 ;; Make an automatic label.
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
196 (setq default (reftex-uniquify-label prefix t))))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
197
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
198 ;; Should we ask the user?
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
199 (if (or (reftex-typekey-check typekey
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
200 (nth 1 reftex-insert-label-flags)) ; prompt
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
201 force-prompt)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
202
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
203 (while (not valid)
62467
35f6599373fc * textmodes/reftex-vars.el (reftex-cite-format-builtin): Support
Carsten Dominik <dominik@science.uva.nl>
parents: 60918
diff changeset
204 ;; iterate until we get a valid label
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
205
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
206 (setq label (read-string
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
207 (if naked "Naked Label: " "Label: ")
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
208 default))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
209
62467
35f6599373fc * textmodes/reftex-vars.el (reftex-cite-format-builtin): Support
Carsten Dominik <dominik@science.uva.nl>
parents: 60918
diff changeset
210 ;; Lets make sure that this is a valid label
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
211 (cond
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
212
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
213 ((string-match (concat "\\`\\(" (regexp-quote prefix)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
214 "\\)?[ \t]*\\'")
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
215 label)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
216 ;; No label at all, please
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
217 (message "No label inserted.")
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
218 (throw 'exit nil))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
219
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
220 ;; Test if label contains strange characters
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
221 ((string-match reftex-label-illegal-re label)
60918
58a53f588384 * textmodes/refbib.el, textmodes/refer.el, textmodes/reftex-cite.el,
Werner LEMBERG <wl@gnu.org>
parents: 59534
diff changeset
222 (message "Label \"%s\" contains invalid characters" label)
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
223 (ding)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
224 (sit-for 2))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
225
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
226 ;; Look it up in the label list
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
227 ((setq entry (assoc label
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
228 (symbol-value reftex-docstruct-symbol)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
229 (ding)
111422
2eee976277c5 Silence reftex compilation.
Glenn Morris <rgm@gnu.org>
parents: 110015
diff changeset
230 (if (y-or-n-p
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
231 (format "Label '%s' exists. Use anyway? " label))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
232 (setq valid t)))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
233
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
234 ;; Label is ok
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
235 (t
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
236 (setq valid t))))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
237 (setq label default))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
238
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
239 ;; Insert the label into the label list
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
240 (let* ((here-I-am-info
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
241 (save-excursion
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
242 (if (and (or naked no-insert)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
243 (integerp (cdr macro-cell)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
244 (goto-char (cdr macro-cell)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
245 (reftex-where-am-I)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
246 (here-I-am (car here-I-am-info))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
247 (note (if (cdr here-I-am-info)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
248 ""
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
249 "POSITION UNCERTAIN. RESCAN TO FIX."))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
250 (file (buffer-file-name))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
251 (text nil)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
252 (tail (memq here-I-am (symbol-value reftex-docstruct-symbol))))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
253
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
254 (or (cdr here-I-am-info) (setq rescan-is-useful t))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
255
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
256 (when tail
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
257 (push (list label typekey text file nil note) (cdr tail))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
258 (put reftex-docstruct-symbol 'modified t)))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
259
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
260 ;; Insert the label into the buffer
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
261 (unless no-insert
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
262 (insert
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
263 (if reftex-format-label-function
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
264 (funcall reftex-format-label-function label format)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
265 (format format label)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
266 (if (and reftex-plug-into-AUCTeX
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
267 (fboundp 'LaTeX-add-labels))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
268 ;; Tell AUCTeX about this
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
269 (LaTeX-add-labels label)))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
270
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
271 ;; Delete the corresponding selection buffers to force update on next use.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
272 (when reftex-auto-update-selection-buffers
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
273 (reftex-erase-buffer (reftex-make-selection-buffer-name typekey))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
274 (reftex-erase-buffer (reftex-make-selection-buffer-name " ")))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
275
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
276 (when (and rescan-is-useful reftex-allow-automatic-rescan)
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
277 (reftex-parse-one))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
278
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
279 ;; return value of the function is the label
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
280 label)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
281
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
282 (defun reftex-string-to-label (string)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
283 "Convert a string (a sentence) to a label.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
284 Uses `reftex-derive-label-parameters' and `reftex-label-illegal-re'. It
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
285 also applies `reftex-translate-to-ascii-function' to the string."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
286 (when (and reftex-translate-to-ascii-function
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
287 (fboundp reftex-translate-to-ascii-function))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
288 (setq string (funcall reftex-translate-to-ascii-function string)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
289 (apply 'reftex-convert-string string
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
290 "[-~ \t\n\r,;]+" reftex-label-illegal-re nil nil
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
291 reftex-derive-label-parameters))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
292
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
293 (defun reftex-latin1-to-ascii (string)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
294 ;; Translate the upper 128 chars in the Latin-1 charset to ASCII equivalents
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
295 (let ((tab "@@@@@@@@@@@@@@@@@@'@@@@@@@@@@@@@ icLxY|S\"ca<--R-o|23'uq..1o>423?AAAAAAACEEEEIIIIDNOOOOOXOUUUUYP3aaaaaaaceeeeiiiidnooooo:ouuuuypy")
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
296 (emacsp (not (featurep 'xemacs))))
111422
2eee976277c5 Silence reftex compilation.
Glenn Morris <rgm@gnu.org>
parents: 110015
diff changeset
297 (mapconcat
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
298 (lambda (c)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
299 (cond ((and (> c 127) (< c 256)) ; 8 bit Latin-1
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
300 (char-to-string (aref tab (- c 128))))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
301 ((and emacsp ; Not for XEmacs
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
302 (> c 2175) (< c 2304)) ; Mule Latin-1
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
303 (char-to-string (aref tab (- c 2176))))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
304 (t (char-to-string c))))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
305 string "")))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
306
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
307 (defun reftex-replace-prefix-escapes (prefix)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
308 ;; Replace %escapes in a label prefix
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
309 (save-match-data
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
310 (let (letter (num 0) replace)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
311 (while (string-match "\\%\\([a-zA-Z]\\)" prefix num)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
312 (setq letter (match-string 1 prefix))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
313 (setq replace
59534
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
314 (save-match-data
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
315 (cond
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
316 ((equal letter "f")
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
317 (file-name-sans-extension
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
318 (file-name-nondirectory (buffer-file-name))))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
319 ((equal letter "F")
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
320 (let ((masterdir (file-name-directory (reftex-TeX-master-file)))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
321 (file (file-name-sans-extension (buffer-file-name))))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
322 (if (string-match (concat "\\`" (regexp-quote masterdir))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
323 file)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
324 (substring file (length masterdir))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
325 file)))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
326 ((equal letter "m")
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
327 (file-name-sans-extension
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
328 (file-name-nondirectory (reftex-TeX-master-file))))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
329 ((equal letter "M")
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
330 (file-name-nondirectory
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
331 (substring (file-name-directory (reftex-TeX-master-file))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
332 0 -1)))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
333 ((equal letter "u")
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
334 (or (user-login-name) ""))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
335 ((equal letter "S")
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
336 (let* (macro level-exp level)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
337 (save-excursion
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
338 (save-match-data
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
339 (when (re-search-backward reftex-section-regexp nil t)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
340 (setq macro (reftex-match-string 2)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
341 level-exp (cdr (assoc macro reftex-section-levels-all))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
342 level (if (symbolp level-exp)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
343 (abs (save-match-data
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
344 (funcall level-exp)))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
345 (abs level-exp))))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
346 (cdr (or (assoc macro reftex-section-prefixes)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
347 (assoc level reftex-section-prefixes)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
348 (assq t reftex-section-prefixes)
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
349 (list t "sec:")))))))
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
350 (t ""))))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
351 (setq num (1- (+ (match-beginning 1) (length replace)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
352 prefix (replace-match replace nil nil prefix)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
353 prefix)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
354
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
355 (defun reftex-uniquify-label (label &optional force separator)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
356 ;; Make label unique by appending a number.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
357 ;; Optional FORCE means, force appending a number, even if label is unique.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
358 ;; Optional SEPARATOR is a string to stick between label and number.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
359
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
360 ;; Ensure access to scanning info
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
361 (reftex-access-scan-info)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
362
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
363 (cond
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
364 ((and (not force)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
365 (not (assoc label (symbol-value reftex-docstruct-symbol))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
366 label)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
367 (t
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
368 (let* ((label-numbers (assq 'label-numbers
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
369 (symbol-value reftex-docstruct-symbol)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
370 (label-numbers-alist (cdr label-numbers))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
371 (cell (or (assoc label label-numbers-alist)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
372 (car (setcdr label-numbers
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
373 (cons (cons label 0)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
374 label-numbers-alist)))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
375 (num (1+ (cdr cell)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
376 (sep (or separator "")))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
377 (while (assoc (concat label sep (int-to-string num))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
378 (symbol-value reftex-docstruct-symbol))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
379 (incf num))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
380 (setcdr cell num)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
381 (concat label sep (int-to-string num))))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
382
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
383 ;;; Referencing labels ------------------------------------------------------
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
384
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
385 ;; Help string for the reference label menu
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
386 (defconst reftex-select-label-prompt
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
387 "Select: [n]ext [p]revious [r]escan [ ]context e[x]tern [q]uit RET [?]HELP+more")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
388
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
389 (defconst reftex-select-label-help
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
390 " n / p Go to next/previous label (Cursor motion works as well)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
391 C-c C-n/p Go to next/previous section heading.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
392 b / l Jump back to previous selection / Reuse last referenced label.
37998
706af946b1e7 * reftex-ref.el (reftex-select-label-help): Added "z" key
Carsten Dominik <dominik@science.uva.nl>
parents: 34402
diff changeset
393 z Jump to a specific section, e.g. '3 z' jumps to section 3.
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
394 g / s Update menu / Switch label type.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
395 r / C-u r Reparse document / Reparse entire document.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
396 x Switch to label menu of external document (with LaTeX package `xr').
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
397 F t c Toggle: [F]ile borders, [t]able of contents, [c]ontext
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
398 # % Toggle: [#] label counters, [%] labels in comments
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
399 SPC / f Show full context in other window / Toggle follow mode.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
400 . Show insertion point in other window.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
401 v / V Toggle \\ref <-> \\vref / Rotate \\ref <=> \\fref <=> \\Fref
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
402 TAB Enter a label with completion.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
403 m , - + Mark entry. `,-+' also assign a separator.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
404 a / A Put all marked entries into one/many \\ref commands.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
405 q / RET Quit without referencing / Accept current label (also on mouse-2).")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
406
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
407 (defun reftex-reference (&optional type no-insert cut)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
408 "Make a LaTeX reference. Look only for labels of a certain TYPE.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
409 With prefix arg, force to rescan buffer for labels. This should only be
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
410 necessary if you have recently entered labels yourself without using
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
411 reftex-label. Rescanning of the buffer can also be requested from the
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
412 label selection menu.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
413 The function returns the selected label or nil.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
414 If NO-INSERT is non-nil, do not insert \\ref command, just return label.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
415 When called with 2 C-u prefix args, disable magic word recognition."
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
416
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
417 (interactive)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
418
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
419 ;; check for active recursive edits
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
420 (reftex-check-recursive-edit)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
421
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
422 ;; Ensure access to scanning info and rescan buffer if prefix are is '(4)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
423 (reftex-access-scan-info current-prefix-arg)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
424
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
425 (unless type
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
426 ;; guess type from context
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
427 (if (and reftex-guess-label-type
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
428 (setq type (reftex-guess-label-type)))
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
429 (setq cut (cdr type)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
430 type (car type))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
431 (setq type (reftex-query-label-type))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
432
111422
2eee976277c5 Silence reftex compilation.
Glenn Morris <rgm@gnu.org>
parents: 110015
diff changeset
433 (let* ((reftex-refstyle
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
434 (cond ((reftex-typekey-check type reftex-vref-is-default) "\\vref")
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
435 ((reftex-typekey-check type reftex-fref-is-default) "\\fref")
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
436 (t "\\ref")))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
437 (reftex-format-ref-function reftex-format-ref-function)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
438 (form "\\ref{%s}")
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
439 label labels sep sep1)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
440
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
441 ;; Have the user select a label
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
442 (set-marker reftex-select-return-marker (point))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
443 (setq labels (save-excursion
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
444 (reftex-offer-label-menu type)))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
445 (reftex-ensure-compiled-variables)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
446 (set-marker reftex-select-return-marker nil)
47050
904fd28be439 Update to RefTeX 4.19
Carsten Dominik <dominik@science.uva.nl>
parents: 46683
diff changeset
447 ;; If the first entry is the symbol 'concat, concat all labels.
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
448 ;; We keep the cdr of the first label for typekey etc information.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
449 (if (eq (car labels) 'concat)
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
450 (setq labels (list (list (mapconcat 'car (cdr labels) ",")
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
451 (cdr (nth 1 labels))))))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
452 (setq type (nth 1 (car labels))
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
453 form (or (cdr (assoc type reftex-typekey-to-format-alist))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
454 form))
111422
2eee976277c5 Silence reftex compilation.
Glenn Morris <rgm@gnu.org>
parents: 110015
diff changeset
455
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
456 (cond
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
457 (no-insert
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
458 ;; Just return the first label
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
459 (car (car labels)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
460 ((null labels)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
461 (message "Quit")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
462 nil)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
463 (t
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
464 (while labels
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
465 (setq label (car (car labels))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
466 sep (nth 2 (car labels))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
467 sep1 (cdr (assoc sep reftex-multiref-punctuation))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
468 labels (cdr labels))
111422
2eee976277c5 Silence reftex compilation.
Glenn Morris <rgm@gnu.org>
parents: 110015
diff changeset
469 (when cut
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
470 (backward-delete-char cut)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
471 (setq cut nil))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
472
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
473 ;; remove ~ if we do already have a space
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
474 (when (and (= ?~ (string-to-char form))
59534
9bad65481674 2005-01-14 Carsten Dominik <dominik@science.uva.nl>
Carsten Dominik <dominik@science.uva.nl>
parents: 52401
diff changeset
475 (member (preceding-char) '(?\ ?\t ?\n ?~)))
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
476 (setq form (substring form 1)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
477 ;; do we have a special format?
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
478 (setq reftex-format-ref-function
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
479 (cond
111422
2eee976277c5 Silence reftex compilation.
Glenn Morris <rgm@gnu.org>
parents: 110015
diff changeset
480 ((string= reftex-refstyle "\\vref") 'reftex-format-vref)
2eee976277c5 Silence reftex compilation.
Glenn Morris <rgm@gnu.org>
parents: 110015
diff changeset
481 ((string= reftex-refstyle "\\fref") 'reftex-format-fref)
2eee976277c5 Silence reftex compilation.
Glenn Morris <rgm@gnu.org>
parents: 110015
diff changeset
482 ((string= reftex-refstyle "\\Fref") 'reftex-format-Fref)
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
483 (t reftex-format-ref-function)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
484 ;; ok, insert the reference
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
485 (if sep1 (insert sep1))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
486 (insert
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
487 (if reftex-format-ref-function
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
488 (funcall reftex-format-ref-function label form)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
489 (format form label label)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
490 ;; take out the initial ~ for good
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
491 (and (= ?~ (string-to-char form))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
492 (setq form (substring form 1))))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
493 (message "")
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
494 label))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
495
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
496 (defun reftex-guess-label-type ()
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
497 ;; Examine context to guess what a \ref might want to reference.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
498 (let ((words reftex-words-to-typekey-alist)
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
499 (case-fold-search t)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
500 (bound (max (point-min) (- (point) 35)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
501 matched cell)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
502 (save-excursion
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
503 (while (and (setq cell (pop words))
111422
2eee976277c5 Silence reftex compilation.
Glenn Morris <rgm@gnu.org>
parents: 110015
diff changeset
504 (not (setq matched
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
505 (re-search-backward (car cell) bound t))))))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
506 (if matched
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
507 (cons (cdr cell) (- (match-end 0) (match-end 1)))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
508 nil)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
509
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
510 (defvar reftex-select-label-map)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
511 (defun reftex-offer-label-menu (typekey)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
512 ;; Offer a menu with the appropriate labels.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
513 (let* ((buf (current-buffer))
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
514 (xr-data (assq 'xr (symbol-value reftex-docstruct-symbol)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
515 (xr-alist (cons (cons "" (buffer-file-name)) (nth 1 xr-data)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
516 (xr-index 0)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
517 (here-I-am (car (reftex-where-am-I)))
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
518 (here-I-am1 here-I-am)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
519 (toc (reftex-typekey-check typekey reftex-label-menu-flags 0))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
520 (files (reftex-typekey-check typekey reftex-label-menu-flags 7))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
521 (context (not (reftex-typekey-check
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
522 typekey reftex-label-menu-flags 3)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
523 (counter (reftex-typekey-check
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
524 typekey reftex-label-menu-flags 2))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
525 (follow (reftex-typekey-check
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
526 typekey reftex-label-menu-flags 4))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
527 (commented (nth 5 reftex-label-menu-flags))
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
528 (prefix "")
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
529 selection-buffers
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
530 offset rtn key data last-data entries)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
531
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
532 (unwind-protect
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
533 (catch 'exit
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
534 (while t
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
535 (save-window-excursion
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
536 (delete-other-windows)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
537 (setq reftex-call-back-to-this-buffer buf
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
538 reftex-latex-syntax-table (syntax-table))
104768
17d2ae0948e2 Remove unnecessary bindings of default-major-mode (all are followed by
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
539 (if reftex-use-multiple-selection-buffers
17d2ae0948e2 Remove unnecessary bindings of default-major-mode (all are followed by
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
540 (switch-to-buffer-other-window
105813
df4934f25eef * textmodes/two-column.el (2C-split):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104768
diff changeset
541 (with-current-buffer buf
104768
17d2ae0948e2 Remove unnecessary bindings of default-major-mode (all are followed by
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
542 (reftex-make-selection-buffer-name typekey)))
17d2ae0948e2 Remove unnecessary bindings of default-major-mode (all are followed by
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
543 (switch-to-buffer-other-window "*RefTeX Select*")
17d2ae0948e2 Remove unnecessary bindings of default-major-mode (all are followed by
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
544 (reftex-erase-buffer))
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
545 (unless (eq major-mode 'reftex-select-label-mode)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
546 (reftex-select-label-mode))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
547 (add-to-list 'selection-buffers (current-buffer))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
548 (setq truncate-lines t)
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
549 (setq mode-line-format
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
550 (list "---- " 'mode-line-buffer-identification
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
551 " " 'global-mode-string " (" mode-name ")"
111422
2eee976277c5 Silence reftex compilation.
Glenn Morris <rgm@gnu.org>
parents: 110015
diff changeset
552 " S<" 'reftex-refstyle ">"
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
553 " -%-"))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
554 (cond
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
555 ((= 0 (buffer-size))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
556 (let ((buffer-read-only nil))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
557 (message "Creating Selection Buffer...")
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
558 (setq offset (reftex-insert-docstruct
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
559 buf
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
560 toc
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
561 typekey
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
562 nil ; index
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
563 files
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
564 context
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
565 counter
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
566 commented
111422
2eee976277c5 Silence reftex compilation.
Glenn Morris <rgm@gnu.org>
parents: 110015
diff changeset
567 (or here-I-am offset)
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
568 prefix
111422
2eee976277c5 Silence reftex compilation.
Glenn Morris <rgm@gnu.org>
parents: 110015
diff changeset
569 nil ; no a toc buffer
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
570 ))))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
571 (here-I-am
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
572 (setq offset (reftex-get-offset buf here-I-am typekey)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
573 (t (setq offset t)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
574 (setq buffer-read-only t)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
575 (setq offset (or offset t))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
576
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
577 (setq here-I-am nil) ; turn off determination of offset
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
578 (setq rtn
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
579 (reftex-select-item
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
580 reftex-select-label-prompt
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
581 reftex-select-label-help
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
582 reftex-select-label-map
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
583 offset
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
584 'reftex-show-label-location follow))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
585 (setq key (car rtn)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
586 data (nth 1 rtn)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
587 last-data (nth 2 rtn)
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
588 offset t)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
589 (unless key (throw 'exit nil))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
590 (cond
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
591 ((eq key ?g)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
592 ;; update buffer
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
593 (reftex-erase-buffer))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
594 ((or (eq key ?r)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
595 (eq key ?R))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
596 ;; rescan buffer
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
597 (and current-prefix-arg (setq key ?R))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
598 (reftex-erase-buffer)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
599 (reftex-reparse-document buf last-data key))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
600 ((eq key ?c)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
601 ;; toggle context mode
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
602 (reftex-erase-buffer)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
603 (setq context (not context)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
604 ((eq key ?s)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
605 ;; switch type
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
606 (setq here-I-am here-I-am1)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
607 (setq typekey (reftex-query-label-type)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
608 ((eq key ?t)
26910
489a5439b988 * reftex.el (reftex-compile-variables): respect new structure of
Carsten Dominik <dominik@science.uva.nl>
parents: 25806
diff changeset
609 ;; toggle table of contents display, or change depth
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
610 (reftex-erase-buffer)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
611 (if current-prefix-arg
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
612 (setq reftex-toc-max-level (prefix-numeric-value
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
613 current-prefix-arg))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
614 (setq toc (not toc))))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
615 ((eq key ?F)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
616 ;; toggle display of included file borders
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
617 (reftex-erase-buffer)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
618 (setq files (not files)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
619 ((eq key ?#)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
620 ;; toggle counter display
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
621 (reftex-erase-buffer)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
622 (setq counter (not counter)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
623 ((eq key ?%)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
624 ;; toggle display of commented labels
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
625 (reftex-erase-buffer)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
626 (setq commented (not commented)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
627 ((eq key ?l)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
628 ;; reuse the last referenced label again
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
629 (setq entries reftex-last-used-reference)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
630 (throw 'exit t))
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
631 ((eq key ?x)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
632 ;; select an external document
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
633 (setq xr-index (reftex-select-external-document
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
634 xr-alist xr-index))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
635 (setq buf (or (reftex-get-file-buffer-force
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
636 (cdr (nth xr-index xr-alist)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
637 (error "Cannot switch document"))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
638 prefix (or (car (nth xr-index xr-alist)) ""))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
639 (set-buffer buf)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
640 (reftex-access-scan-info))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
641 ((stringp key)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
642 (setq entries
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
643 (list
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
644 (list
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
645 (or (assoc key (symbol-value reftex-docstruct-symbol))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
646 (list key typekey)))))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
647 (throw 'exit t))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
648 ((memq key '(?a ?A return))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
649 (cond
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
650 (reftex-select-marked
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
651 (setq entries (nreverse reftex-select-marked)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
652 (data
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
653 (setq entries (list (list data))))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
654 (t (setq entries nil)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
655 (when entries
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
656 (if (equal key ?a) (push 'concat entries))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
657 (setq reftex-last-used-reference entries))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
658 (set-buffer buf)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
659 (throw 'exit t))
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
660 (t (error "This should not happen (reftex-offer-label-menu)"))))))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
661 (save-excursion
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
662 (while reftex-buffers-with-changed-invisibility
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
663 (set-buffer (car (car reftex-buffers-with-changed-invisibility)))
85197
861bd8efa4d6 (reftex-offer-label-menu): Use mapc rather than mapcar.
Glenn Morris <rgm@gnu.org>
parents: 78225
diff changeset
664 (setq buffer-invisibility-spec
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
665 (cdr (pop reftex-buffers-with-changed-invisibility)))))
85197
861bd8efa4d6 (reftex-offer-label-menu): Use mapc rather than mapcar.
Glenn Morris <rgm@gnu.org>
parents: 78225
diff changeset
666 (mapc (lambda (buf) (and (buffer-live-p buf) (bury-buffer buf)))
861bd8efa4d6 (reftex-offer-label-menu): Use mapc rather than mapcar.
Glenn Morris <rgm@gnu.org>
parents: 78225
diff changeset
667 selection-buffers)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
668 (reftex-kill-temporary-buffers))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
669 ;; Add the prefixes, put together the relevant information in the form
46683
060f433ebf11 Updated to RefTeX 4.18
Carsten Dominik <dominik@science.uva.nl>
parents: 46612
diff changeset
670 ;; (LABEL TYPEKEY SEPARATOR) and return a list of those.
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
671 (mapcar (lambda (x)
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
672 (if (listp x)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
673 (list (concat prefix (car (car x)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
674 (nth 1 (car x))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
675 (nth 2 x))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
676 x))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
677 entries)))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
678
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
679 (defun reftex-reparse-document (&optional buffer data key)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
680 ;; Rescan the document.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
681 (save-window-excursion
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
682 (save-excursion
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
683 (if buffer
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
684 (if (not (bufferp buffer))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
685 (error "No such buffer %s" (buffer-name buffer))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
686 (set-buffer buffer)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
687 (let ((arg (if (eq key ?R) '(16) '(4)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
688 (file (nth 3 data)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
689 (reftex-access-scan-info arg file)))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
690
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
691 (defun reftex-query-label-type ()
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
692 ;; Ask for label type
111422
2eee976277c5 Silence reftex compilation.
Glenn Morris <rgm@gnu.org>
parents: 110015
diff changeset
693 (let ((key (reftex-select-with-char
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
694 reftex-type-query-prompt reftex-type-query-help 3)))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
695 (unless (member (char-to-string key) reftex-typekey-list)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
696 (error "No such label type: %s" (char-to-string key)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
697 (char-to-string key)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
698
111422
2eee976277c5 Silence reftex compilation.
Glenn Morris <rgm@gnu.org>
parents: 110015
diff changeset
699 (defun reftex-show-label-location (data forward no-revisit
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
700 &optional stay error)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
701 ;; View the definition site of a label in another window.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
702 ;; DATA is an entry from the docstruct list.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
703 ;; FORWARD indicates if the label is likely forward from current point.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
704 ;; NO-REVISIT means do not load a file to show this label.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
705 ;; STAY means leave the new window selected.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
706 ;; ERROR means throw an error exception when the label cannot be found.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
707 ;; If ERROR is nil, the return value of this function indicates success.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
708 (let* ((this-window (selected-window))
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
709 (errorf (if error 'error 'message))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
710 label file buffer re found)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
711
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
712 (catch 'exit
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
713 (setq label (nth 0 data)
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
714 file (nth 3 data))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
715
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
716 (unless file
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
717 (funcall errorf "Unknown label - reparse might help")
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
718 (throw 'exit nil))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
719
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
720 ;; Goto the file in another window
111422
2eee976277c5 Silence reftex compilation.
Glenn Morris <rgm@gnu.org>
parents: 110015
diff changeset
721 (setq buffer
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
722 (if no-revisit
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
723 (reftex-get-buffer-visiting file)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
724 (reftex-get-file-buffer-force
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
725 file (not reftex-keep-temporary-buffers))))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
726 (if buffer
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
727 ;; good - the file is available
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
728 (switch-to-buffer-other-window buffer)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
729 ;; we have got a problem here. The file does not exist.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
730 ;; Let' get out of here..
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
731 (funcall errorf "Label %s not found" label)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
732 (throw 'exit nil))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
733
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
734 ;; search for that label
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
735 (setq re (format reftex-find-label-regexp-format (regexp-quote label)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
736 (setq found
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
737 (if forward
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
738 (re-search-forward re nil t)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
739 (re-search-backward re nil t)))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
740 (unless found
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
741 (goto-char (point-min))
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
742 (unless (setq found (re-search-forward re nil t))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
743 ;; Ooops. Must be in a macro with distributed args.
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
744 (setq found
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
745 (re-search-forward
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
746 (format reftex-find-label-regexp-format2
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
747 (regexp-quote label)) nil t))))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
748 (if (match-end 3)
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
749 (progn
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
750 (reftex-highlight 0 (match-beginning 3) (match-end 3))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
751 (reftex-show-entry (match-beginning 3) (match-end 3))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
752 (recenter '(4))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
753 (unless stay (select-window this-window)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
754 (select-window this-window)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
755 (funcall errorf "Label %s not found" label))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
756 found)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
757
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
758 (defvar font-lock-mode)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
759 (defun reftex-show-entry (beg-hlt end-hlt)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
760 ;; Show entry if point is hidden
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
761 (let* ((n (/ (reftex-window-height) 2))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
762 (beg (save-excursion
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
763 (re-search-backward "[\n\r]" nil 1 n) (point)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
764 (end (save-excursion
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
765 (re-search-forward "[\n\r]" nil 1 n) (point))))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
766 (cond
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
767 ((and (boundp 'buffer-invisibility-spec) buffer-invisibility-spec
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
768 (get-char-property (1+ beg-hlt) 'invisible))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
769 ;; Invisible with text properties. That is easy to change.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
770 (push (cons (current-buffer) buffer-invisibility-spec)
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
771 reftex-buffers-with-changed-invisibility)
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
772 (setq buffer-invisibility-spec nil))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
773 ((string-match "\r" (buffer-substring beg end))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
774 ;; Invisible with selective display. We need to copy it.
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
775 (let ((string (buffer-substring-no-properties beg end)))
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
776 (switch-to-buffer "*RefTeX Context Copy*")
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
777 (setq buffer-read-only nil)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
778 (erase-buffer)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
779 (insert string)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
780 (subst-char-in-region (point-min) (point-max) ?\r ?\n t)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
781 (goto-char (- beg-hlt beg))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
782 (reftex-highlight 0 (1+ (- beg-hlt beg)) (1+ (- end-hlt beg)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
783 (if (reftex-refontify)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
784 (when (or (not (eq major-mode 'latex-mode))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
785 (not font-lock-mode))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
786 (latex-mode)
111422
2eee976277c5 Silence reftex compilation.
Glenn Morris <rgm@gnu.org>
parents: 110015
diff changeset
787 (run-hook-with-args
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
788 'reftex-pre-refontification-functions
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
789 reftex-call-back-to-this-buffer 'reftex-hidden)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
790 (turn-on-font-lock))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
791 (when (or (not (eq major-mode 'fundamental-mode))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
792 font-lock-mode)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
793 (fundamental-mode)))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
794 (run-hooks 'reftex-display-copied-context-hook)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
795 (setq buffer-read-only t))))))
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
796
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
797 (defun reftex-varioref-vref ()
37998
706af946b1e7 * reftex-ref.el (reftex-select-label-help): Added "z" key
Carsten Dominik <dominik@science.uva.nl>
parents: 34402
diff changeset
798 "Insert a reference using the `\\vref' macro from the varioref package."
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
799 (interactive)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
800 (let ((reftex-format-ref-function 'reftex-format-vref))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
801 (reftex-reference)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
802 (defun reftex-fancyref-fref ()
37998
706af946b1e7 * reftex-ref.el (reftex-select-label-help): Added "z" key
Carsten Dominik <dominik@science.uva.nl>
parents: 34402
diff changeset
803 "Insert a reference using the `\\fref' macro from the fancyref package."
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
804 (interactive)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
805 (let ((reftex-format-ref-function 'reftex-format-fref)
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
806 ;;(reftex-guess-label-type nil) ;FIXME do we want this????
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
807 )
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
808 (reftex-reference)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
809 (defun reftex-fancyref-Fref ()
37998
706af946b1e7 * reftex-ref.el (reftex-select-label-help): Added "z" key
Carsten Dominik <dominik@science.uva.nl>
parents: 34402
diff changeset
810 "Insert a reference using the `\\Fref' macro from the fancyref package."
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
811 (interactive)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
812 (let ((reftex-format-ref-function 'reftex-format-Fref)
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
813 ;;(reftex-guess-label-type nil) ;FIXME do we want this????
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
814 )
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
815 (reftex-reference)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
816
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
817 (defun reftex-format-vref (label fmt)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
818 (while (string-match "\\\\ref{" fmt)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
819 (setq fmt (replace-match "\\vref{" t t fmt)))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
820 (format fmt label label))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
821 (defun reftex-format-Fref (label def-fmt)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
822 (format "\\Fref{%s}" label))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
823 (defun reftex-format-fref (label def-fmt)
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
824 (format "\\fref{%s}" label))
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
825
47050
904fd28be439 Update to RefTeX 4.19
Carsten Dominik <dominik@science.uva.nl>
parents: 46683
diff changeset
826 (defun reftex-goto-label (&optional other-window)
904fd28be439 Update to RefTeX 4.19
Carsten Dominik <dominik@science.uva.nl>
parents: 46683
diff changeset
827 "Prompt for a label (with completion) and jump to the location of this label.
904fd28be439 Update to RefTeX 4.19
Carsten Dominik <dominik@science.uva.nl>
parents: 46683
diff changeset
828 Optional prefix argument OTHER-WINDOW goes to the label in another window."
904fd28be439 Update to RefTeX 4.19
Carsten Dominik <dominik@science.uva.nl>
parents: 46683
diff changeset
829 (interactive "P")
904fd28be439 Update to RefTeX 4.19
Carsten Dominik <dominik@science.uva.nl>
parents: 46683
diff changeset
830 (reftex-access-scan-info)
904fd28be439 Update to RefTeX 4.19
Carsten Dominik <dominik@science.uva.nl>
parents: 46683
diff changeset
831 (let* ((wcfg (current-window-configuration))
52170
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
832 (docstruct (symbol-value reftex-docstruct-symbol))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
833 (label (completing-read "Label: " docstruct
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
834 (lambda (x) (stringp (car x))) t))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
835 (selection (assoc label docstruct))
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
836 (where (progn
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
837 (reftex-show-label-location selection t nil 'stay)
27340819ef07 Updated to version 4.21
Carsten Dominik <dominik@science.uva.nl>
parents: 50978
diff changeset
838 (point-marker))))
47050
904fd28be439 Update to RefTeX 4.19
Carsten Dominik <dominik@science.uva.nl>
parents: 46683
diff changeset
839 (unless other-window
904fd28be439 Update to RefTeX 4.19
Carsten Dominik <dominik@science.uva.nl>
parents: 46683
diff changeset
840 (set-window-configuration wcfg)
904fd28be439 Update to RefTeX 4.19
Carsten Dominik <dominik@science.uva.nl>
parents: 46683
diff changeset
841 (switch-to-buffer (marker-buffer where))
111422
2eee976277c5 Silence reftex compilation.
Glenn Morris <rgm@gnu.org>
parents: 110015
diff changeset
842 (goto-char where))
47050
904fd28be439 Update to RefTeX 4.19
Carsten Dominik <dominik@science.uva.nl>
parents: 46683
diff changeset
843 (reftex-unhighlight 0)))
904fd28be439 Update to RefTeX 4.19
Carsten Dominik <dominik@science.uva.nl>
parents: 46683
diff changeset
844
904fd28be439 Update to RefTeX 4.19
Carsten Dominik <dominik@science.uva.nl>
parents: 46683
diff changeset
845
25280
9b601931b795 Initial revision
Carsten Dominik <dominik@science.uva.nl>
parents:
diff changeset
846 ;;; reftex-ref.el ends here