aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTassilo Horn2013-06-12 14:42:35 +0200
committerTassilo Horn2013-06-12 14:42:35 +0200
commit79d7167f20582b7d0e8743bec650bda1a12a85ab (patch)
tree98408e5ff598a88b567e1e62fcbaebe64fc10a8f
parent6186a2767fcae48a43675dabc457ed2b2177b884 (diff)
downloademacs-79d7167f20582b7d0e8743bec650bda1a12a85ab.tar.gz
emacs-79d7167f20582b7d0e8743bec650bda1a12a85ab.zip
* textmodes/reftex-cite.el (reftex-cite-regexp-hist)
(reftex-citation-prompt, reftex-default-bibliography) (reftex-bib-or-thebib, reftex-get-bibfile-list) (reftex-pop-to-bibtex-entry, reftex-extract-bib-entries) (reftex-bib-sort-author, reftex-bib-sort-year) (reftex-bib-sort-year-reverse, reftex-get-crossref-alist) (reftex-extract-bib-entries-from-thebibliography) (reftex-get-bibkey-default, reftex-get-bib-names) (reftex-parse-bibtex-entry, reftex-get-bib-field) (reftex-format-bib-entry, reftex-parse-bibitem) (reftex-format-bibitem, reftex-do-citation) (reftex-figure-out-cite-format, reftex-offer-bib-menu) (reftex-restrict-bib-matches, reftex-extract-bib-file) (reftex-insert-bib-matches, reftex-format-citation) (reftex-make-cite-echo-string, reftex-bibtex-selection-callback) (reftex-create-bibtex-file): Add docstrings, mostly by converting existing comments into docstrings.
-rw-r--r--lisp/ChangeLog20
-rw-r--r--lisp/textmodes/reftex-cite.el129
-rw-r--r--lisp/textmodes/reftex-parse.el154
3 files changed, 157 insertions, 146 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 5abb3b1b1bc..18f225ec308 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,23 @@
12013-06-12 RĂ¼diger Sonderfeld <ruediger@c-plusplus.de>
2
3 * textmodes/reftex-cite.el (reftex-cite-regexp-hist)
4 (reftex-citation-prompt, reftex-default-bibliography)
5 (reftex-bib-or-thebib, reftex-get-bibfile-list)
6 (reftex-pop-to-bibtex-entry, reftex-extract-bib-entries)
7 (reftex-bib-sort-author, reftex-bib-sort-year)
8 (reftex-bib-sort-year-reverse, reftex-get-crossref-alist)
9 (reftex-extract-bib-entries-from-thebibliography)
10 (reftex-get-bibkey-default, reftex-get-bib-names)
11 (reftex-parse-bibtex-entry, reftex-get-bib-field)
12 (reftex-format-bib-entry, reftex-parse-bibitem)
13 (reftex-format-bibitem, reftex-do-citation)
14 (reftex-figure-out-cite-format, reftex-offer-bib-menu)
15 (reftex-restrict-bib-matches, reftex-extract-bib-file)
16 (reftex-insert-bib-matches, reftex-format-citation)
17 (reftex-make-cite-echo-string, reftex-bibtex-selection-callback)
18 (reftex-create-bibtex-file): Add docstrings, mostly by converting
19 existing comments into docstrings.
20
12013-06-12 Xue Fuqiao <xfq.free@gmail.com> 212013-06-12 Xue Fuqiao <xfq.free@gmail.com>
2 22
3 * ibuf-ext.el (ibuffer-mark-help-buffers): Doc fix. 23 * ibuf-ext.el (ibuffer-mark-help-buffers): Doc fix.
diff --git a/lisp/textmodes/reftex-cite.el b/lisp/textmodes/reftex-cite.el
index ca29709de2e..6c103294a06 100644
--- a/lisp/textmodes/reftex-cite.el
+++ b/lisp/textmodes/reftex-cite.el
@@ -25,18 +25,16 @@
25;;; Code: 25;;; Code:
26 26
27(eval-when-compile (require 'cl)) 27(eval-when-compile (require 'cl))
28(provide 'reftex-cite)
29(require 'reftex)
30;;;
31 28
32;; Variables and constants 29(require 'reftex)
33 30
34;; The history list of regular expressions used for citations 31;;; Variables and constants
35(defvar reftex-cite-regexp-hist nil) 32(defvar reftex-cite-regexp-hist nil
33 "The history list of regular expressions used for citations")
36 34
37;; Prompt and help string for citation selection
38(defconst reftex-citation-prompt 35(defconst reftex-citation-prompt
39 "Select: [n]ext [p]revious [r]estrict [ ]full_entry [q]uit RET [?]Help+more") 36 "Select: [n]ext [p]revious [r]estrict [ ]full_entry [q]uit RET [?]Help+more"
37 "Prompt and help string for citation selection")
40 38
41(defconst reftex-citation-help 39(defconst reftex-citation-help
42 " n / p Go to next/previous entry (Cursor motion works as well). 40 " n / p Go to next/previous entry (Cursor motion works as well).
@@ -51,8 +49,7 @@
51 e / E Create BibTeX file with all (marked/unmarked) entries 49 e / E Create BibTeX file with all (marked/unmarked) entries
52 a / A Put all (marked) entries into one/many \\cite commands.") 50 a / A Put all (marked) entries into one/many \\cite commands.")
53 51
54;; Find bibtex files 52;;; Find bibtex files
55
56(defmacro reftex-with-special-syntax-for-bib (&rest body) 53(defmacro reftex-with-special-syntax-for-bib (&rest body)
57 `(let ((saved-syntax (syntax-table))) 54 `(let ((saved-syntax (syntax-table)))
58 (unwind-protect 55 (unwind-protect
@@ -62,8 +59,8 @@
62 (set-syntax-table saved-syntax)))) 59 (set-syntax-table saved-syntax))))
63 60
64(defun reftex-default-bibliography () 61(defun reftex-default-bibliography ()
65 ;; Return the expanded value of `reftex-default-bibliography'. 62 "Return the expanded value of variable `reftex-default-bibliography'.
66 ;; The expanded value is cached. 63The expanded value is cached."
67 (unless (eq (get 'reftex-default-bibliography :reftex-raw) 64 (unless (eq (get 'reftex-default-bibliography :reftex-raw)
68 reftex-default-bibliography) 65 reftex-default-bibliography)
69 (put 'reftex-default-bibliography :reftex-expanded 66 (put 'reftex-default-bibliography :reftex-expanded
@@ -74,9 +71,8 @@
74 (get 'reftex-default-bibliography :reftex-expanded)) 71 (get 'reftex-default-bibliography :reftex-expanded))
75 72
76(defun reftex-bib-or-thebib () 73(defun reftex-bib-or-thebib ()
77 ;; Tests if BibTeX or \begin{thebibliography} should be used for the 74 "Test if BibTeX or \begin{thebibliography} should be used for the citation.
78 ;; citation 75Find the bof of the current file"
79 ;; Find the bof of the current file
80 (let* ((docstruct (symbol-value reftex-docstruct-symbol)) 76 (let* ((docstruct (symbol-value reftex-docstruct-symbol))
81 (rest (or (member (list 'bof (buffer-file-name)) docstruct) 77 (rest (or (member (list 'bof (buffer-file-name)) docstruct)
82 docstruct)) 78 docstruct))
@@ -94,11 +90,11 @@
94 (if thebib 'thebib nil)))) 90 (if thebib 'thebib nil))))
95 91
96(defun reftex-get-bibfile-list () 92(defun reftex-get-bibfile-list ()
97 ;; Return list of bibfiles for current document. 93 "Return list of bibfiles for current document.
98 ;; When using the chapterbib or bibunits package you should either 94When using the chapterbib or bibunits package you should either
99 ;; use the same database files everywhere, or separate parts using 95use the same database files everywhere, or separate parts using
100 ;; different databases into different files (included into the mater file). 96different databases into different files (included into the mater file).
101 ;; Then this function will return the applicable database files. 97Then this function will return the applicable database files."
102 98
103 ;; Ensure access to scanning info 99 ;; Ensure access to scanning info
104 (reftex-access-scan-info) 100 (reftex-access-scan-info)
@@ -115,16 +111,14 @@
115 (cdr (assq 'bib (symbol-value reftex-docstruct-symbol))) 111 (cdr (assq 'bib (symbol-value reftex-docstruct-symbol)))
116 (error "\\bibliography statement missing or .bib files not found"))) 112 (error "\\bibliography statement missing or .bib files not found")))
117 113
118;; Find a certain reference in any of the BibTeX files. 114;;; Find a certain reference in any of the BibTeX files.
119
120(defun reftex-pop-to-bibtex-entry (key file-list &optional mark-to-kill 115(defun reftex-pop-to-bibtex-entry (key file-list &optional mark-to-kill
121 highlight item return) 116 highlight item return)
122 ;; Find BibTeX KEY in any file in FILE-LIST in another window. 117 "Find BibTeX KEY in any file in FILE-LIST in another window.
123 ;; If MARK-TO-KILL is non-nil, mark new buffer to kill. 118If MARK-TO-KILL is non-nil, mark new buffer to kill.
124 ;; If HIGHLIGHT is non-nil, highlight the match. 119If HIGHLIGHT is non-nil, highlight the match.
125 ;; If ITEM in non-nil, search for bibitem instead of database entry. 120If ITEM in non-nil, search for bibitem instead of database entry.
126 ;; If RETURN is non-nil, just return the entry and restore point. 121If RETURN is non-nil, just return the entry and restore point."
127
128 (let* ((re 122 (let* ((re
129 (if item 123 (if item
130 (concat "\\\\bibitem[ \t]*\\(\\[[^]]*\\]\\)?[ \t]*{" 124 (concat "\\\\bibitem[ \t]*\\(\\[[^]]*\\]\\)?[ \t]*{"
@@ -178,12 +172,11 @@
178 (progn (forward-list 1) (point))) 172 (progn (forward-list 1) (point)))
179 (error (min (point-max) (+ 300 (point))))))) 173 (error (min (point-max) (+ 300 (point)))))))
180 174
181;; Parse bibtex buffers 175;;; Parse bibtex buffers
182
183(defun reftex-extract-bib-entries (buffers) 176(defun reftex-extract-bib-entries (buffers)
184 ;; Extract bib entries which match regexps from BUFFERS. 177 "Extract bib entries which match regexps from BUFFERS.
185 ;; BUFFERS is a list of buffers or file names. 178BUFFERS is a list of buffers or file names.
186 ;; Return list with entries." 179Return list with entries."
187 (let* (re-list first-re rest-re 180 (let* (re-list first-re rest-re
188 (buffer-list (if (listp buffers) buffers (list buffers))) 181 (buffer-list (if (listp buffers) buffers (list buffers)))
189 found-list entry buffer1 buffer alist 182 found-list entry buffer1 buffer alist
@@ -309,6 +302,8 @@
309 (t found-list)))) 302 (t found-list))))
310 303
311(defun reftex-bib-sort-author (e1 e2) 304(defun reftex-bib-sort-author (e1 e2)
305 "Compare bib entries E1 and E2 by author.
306The name of the first different author/editor is used."
312 (let ((al1 (reftex-get-bib-names "author" e1)) 307 (let ((al1 (reftex-get-bib-names "author" e1))
313 (al2 (reftex-get-bib-names "author" e2))) 308 (al2 (reftex-get-bib-names "author" e2)))
314 (while (and al1 al2 (string= (car al1) (car al2))) 309 (while (and al1 al2 (string= (car al1) (car al2)))
@@ -320,15 +315,17 @@
320 (not (stringp (car al1)))))) 315 (not (stringp (car al1))))))
321 316
322(defun reftex-bib-sort-year (e1 e2) 317(defun reftex-bib-sort-year (e1 e2)
318 "Compare bib entries E1 and E2 by year in ascending order."
323 (< (string-to-number (or (cdr (assoc "year" e1)) "0")) 319 (< (string-to-number (or (cdr (assoc "year" e1)) "0"))
324 (string-to-number (or (cdr (assoc "year" e2)) "0")))) 320 (string-to-number (or (cdr (assoc "year" e2)) "0"))))
325 321
326(defun reftex-bib-sort-year-reverse (e1 e2) 322(defun reftex-bib-sort-year-reverse (e1 e2)
323 "Compare bib entries E1 and E2 by year in descending order."
327 (> (string-to-number (or (cdr (assoc "year" e1)) "0")) 324 (> (string-to-number (or (cdr (assoc "year" e1)) "0"))
328 (string-to-number (or (cdr (assoc "year" e2)) "0")))) 325 (string-to-number (or (cdr (assoc "year" e2)) "0"))))
329 326
330(defun reftex-get-crossref-alist (entry) 327(defun reftex-get-crossref-alist (entry)
331 ;; return the alist from a crossref entry 328 "Return the alist from a crossref ENTRY."
332 (let ((crkey (cdr (assoc "crossref" entry))) 329 (let ((crkey (cdr (assoc "crossref" entry)))
333 start) 330 start)
334 (save-excursion 331 (save-excursion
@@ -347,10 +344,9 @@
347 344
348;; Parse the bibliography environment 345;; Parse the bibliography environment
349(defun reftex-extract-bib-entries-from-thebibliography (files) 346(defun reftex-extract-bib-entries-from-thebibliography (files)
350 ;; Extract bib-entries from the \begin{thebibliography} environment. 347 "Extract bib-entries from the \begin{thebibliography} environment.
351 ;; Parsing is not as good as for the BibTeX database stuff. 348Parsing is not as good as for the BibTeX database stuff.
352 ;; The environment should be located in file FILE. 349The environment should be located in FILES."
353
354 (let* (start end buf entries re re-list file default) 350 (let* (start end buf entries re re-list file default)
355 (unless files 351 (unless files
356 (error "Need file name to find thebibliography environment")) 352 (error "Need file name to find thebibliography environment"))
@@ -430,8 +426,8 @@
430 entries)) 426 entries))
431 427
432(defun reftex-get-bibkey-default () 428(defun reftex-get-bibkey-default ()
433 ;; Return the word before the cursor. If the cursor is in a 429 "Return the word before the cursor.
434 ;; citation macro, return the word before the macro. 430If the cursor is in a citation macro, return the word before the macro."
435 (let* ((macro (reftex-what-macro 1))) 431 (let* ((macro (reftex-what-macro 1)))
436 (save-excursion 432 (save-excursion
437 (if (and macro (string-match "cite" (car macro))) 433 (if (and macro (string-match "cite" (car macro)))
@@ -439,10 +435,10 @@
439 (skip-chars-backward "^a-zA-Z0-9") 435 (skip-chars-backward "^a-zA-Z0-9")
440 (reftex-this-word)))) 436 (reftex-this-word))))
441 437
442;; Parse and format individual entries 438;;; Parse and format individual entries
443
444(defun reftex-get-bib-names (field entry) 439(defun reftex-get-bib-names (field entry)
445 ;; Return a list with the author or editor names in ENTRY 440 "Return a list with the author or editor names in ENTRY.
441If FIELD is empty try \"editor\" field."
446 (let ((names (reftex-get-bib-field field entry))) 442 (let ((names (reftex-get-bib-field field entry)))
447 (if (equal "" names) 443 (if (equal "" names)
448 (setq names (reftex-get-bib-field "editor" entry))) 444 (setq names (reftex-get-bib-field "editor" entry)))
@@ -457,7 +453,9 @@
457 (split-string names "\n"))) 453 (split-string names "\n")))
458 454
459(defun reftex-parse-bibtex-entry (entry &optional from to raw) 455(defun reftex-parse-bibtex-entry (entry &optional from to raw)
460 ; if RAW is non-nil, keep double quotes/curly braces delimiting fields 456 "Parse BibTeX ENTRY.
457If ENTRY is nil then parse the entry in current buffer between FROM and TO.
458If RAW is non-nil, keep double quotes/curly braces delimiting fields."
461 (let (alist key start field) 459 (let (alist key start field)
462 (save-excursion 460 (save-excursion
463 (save-restriction 461 (save-restriction
@@ -518,7 +516,8 @@
518 alist)) 516 alist))
519 517
520(defun reftex-get-bib-field (fieldname entry &optional format) 518(defun reftex-get-bib-field (fieldname entry &optional format)
521 ;; Extract the field FIELDNAME from an ENTRY 519 "Extract the field FIELDNAME from ENTRY.
520If FORMAT is non-nil `format' entry accordingly."
522 (let ((cell (assoc fieldname entry))) 521 (let ((cell (assoc fieldname entry)))
523 (if cell 522 (if cell
524 (if format 523 (if format
@@ -527,7 +526,7 @@
527 ""))) 526 "")))
528 527
529(defun reftex-format-bib-entry (entry) 528(defun reftex-format-bib-entry (entry)
530 ;; Format a BibTeX ENTRY so that it is nice to look at 529 "Format a BibTeX ENTRY so that it is nice to look at."
531 (let* 530 (let*
532 ((auth-list (reftex-get-bib-names "author" entry)) 531 ((auth-list (reftex-get-bib-names "author" entry))
533 (authors (mapconcat 'identity auth-list ", ")) 532 (authors (mapconcat 'identity auth-list ", "))
@@ -570,7 +569,7 @@
570 (concat key "\n " authors " " year " " extra "\n " title "\n\n"))) 569 (concat key "\n " authors " " year " " extra "\n " title "\n\n")))
571 570
572(defun reftex-parse-bibitem (item) 571(defun reftex-parse-bibitem (item)
573 ;; Parse a \bibitem entry 572 "Parse a \bibitem entry in ITEM."
574 (let ((key "") (text "")) 573 (let ((key "") (text ""))
575 (when (string-match "\\`{\\([^}]+\\)}\\([^\000]*\\)" item) 574 (when (string-match "\\`{\\([^}]+\\)}\\([^\000]*\\)" item)
576 (setq key (match-string 1 item) 575 (setq key (match-string 1 item)
@@ -586,7 +585,7 @@
586 (cons "&entry" (concat key " " text))))) 585 (cons "&entry" (concat key " " text)))))
587 586
588(defun reftex-format-bibitem (item) 587(defun reftex-format-bibitem (item)
589 ;; Format a \bibitem entry so that it is (relatively) nice to look at. 588 "Format a \bibitem entry in ITEM so that it is (relatively) nice to look at."
590 (let ((text (reftex-get-bib-field "&text" item)) 589 (let ((text (reftex-get-bib-field "&text" item))
591 (key (reftex-get-bib-field "&key" item)) 590 (key (reftex-get-bib-field "&key" item))
592 (lines nil)) 591 (lines nil))
@@ -603,7 +602,7 @@
603 (put-text-property 0 (length text) 'face reftex-bib-author-face text)) 602 (put-text-property 0 (length text) 'face reftex-bib-author-face text))
604 (concat key "\n " text "\n\n"))) 603 (concat key "\n " text "\n\n")))
605 604
606;; Make a citation 605;;; Make a citation
607 606
608;;;###autoload 607;;;###autoload
609(defun reftex-citation (&optional no-insert format-key) 608(defun reftex-citation (&optional no-insert format-key)
@@ -627,7 +626,6 @@ The regular expression uses an expanded syntax: && is interpreted as `and'.
627Thus, `aaaa&&bbb' matches entries which contain both `aaaa' and `bbb'. 626Thus, `aaaa&&bbb' matches entries which contain both `aaaa' and `bbb'.
628While entering the regexp, completion on knows citation keys is possible. 627While entering the regexp, completion on knows citation keys is possible.
629`=' is a good regular expression to match all entries in all files." 628`=' is a good regular expression to match all entries in all files."
630
631 (interactive) 629 (interactive)
632 630
633 ;; check for recursive edit 631 ;; check for recursive edit
@@ -645,8 +643,7 @@ While entering the regexp, completion on knows citation keys is possible.
645 (reftex-kill-temporary-buffers))) 643 (reftex-kill-temporary-buffers)))
646 644
647(defun reftex-do-citation (&optional arg no-insert format-key) 645(defun reftex-do-citation (&optional arg no-insert format-key)
648 ;; This really does the work of reftex-citation. 646 "This really does the work of `reftex-citation'."
649
650 (let* ((format (reftex-figure-out-cite-format arg no-insert format-key)) 647 (let* ((format (reftex-figure-out-cite-format arg no-insert format-key))
651 (docstruct-symbol reftex-docstruct-symbol) 648 (docstruct-symbol reftex-docstruct-symbol)
652 (selected-entries (reftex-offer-bib-menu)) 649 (selected-entries (reftex-offer-bib-menu))
@@ -743,8 +740,8 @@ While entering the regexp, completion on knows citation keys is possible.
743 (mapcar 'car selected-entries))) 740 (mapcar 'car selected-entries)))
744 741
745(defun reftex-figure-out-cite-format (arg &optional no-insert format-key) 742(defun reftex-figure-out-cite-format (arg &optional no-insert format-key)
746 ;; Check if there is already a cite command at point and change cite format 743 "Check if there is already a cite command at point and change cite format
747 ;; in order to only add another reference in the same cite command. 744in order to only add another reference in the same cite command."
748 (let ((macro (car (reftex-what-macro 1))) 745 (let ((macro (car (reftex-what-macro 1)))
749 (cite-format-value (reftex-get-cite-format)) 746 (cite-format-value (reftex-get-cite-format))
750 key format) 747 key format)
@@ -802,8 +799,7 @@ While entering the regexp, completion on knows citation keys is possible.
802 799
803(defvar reftex-select-bib-map) 800(defvar reftex-select-bib-map)
804(defun reftex-offer-bib-menu () 801(defun reftex-offer-bib-menu ()
805 ;; Offer bib menu and return list of selected items 802 "Offer bib menu and return list of selected items."
806
807 (let ((bibtype (reftex-bib-or-thebib)) 803 (let ((bibtype (reftex-bib-or-thebib))
808 found-list rtn key data selected-entries) 804 found-list rtn key data selected-entries)
809 (while 805 (while
@@ -917,7 +913,7 @@ While entering the regexp, completion on knows citation keys is possible.
917 selected-entries)) 913 selected-entries))
918 914
919(defun reftex-restrict-bib-matches (found-list) 915(defun reftex-restrict-bib-matches (found-list)
920 ;; Limit FOUND-LIST with more regular expressions 916 "Limit FOUND-LIST with more regular expressions."
921 (let ((re-list (split-string (read-string 917 (let ((re-list (split-string (read-string
922 "RegExp [ && RegExp...]: " 918 "RegExp [ && RegExp...]: "
923 nil 'reftex-cite-regexp-hist) 919 nil 'reftex-cite-regexp-hist)
@@ -940,7 +936,7 @@ While entering the regexp, completion on knows citation keys is possible.
940 found-list))) 936 found-list)))
941 937
942(defun reftex-extract-bib-file (all &optional marked complement) 938(defun reftex-extract-bib-file (all &optional marked complement)
943 ;; Limit FOUND-LIST with more regular expressions 939 "Limit FOUND-LIST with more regular expressions."
944 (let ((file (read-file-name "File to create: "))) 940 (let ((file (read-file-name "File to create: ")))
945 (find-file-other-window file) 941 (find-file-other-window file)
946 (if (> (buffer-size) 0) 942 (if (> (buffer-size) 0)
@@ -963,7 +959,7 @@ While entering the regexp, completion on knows citation keys is possible.
963 (goto-char (point-min)))) 959 (goto-char (point-min))))
964 960
965(defun reftex-insert-bib-matches (list) 961(defun reftex-insert-bib-matches (list)
966 ;; Insert the bib matches and number them correctly 962 "Insert the bib matches and number them correctly."
967 (let ((mouse-face 963 (let ((mouse-face
968 (if (memq reftex-highlight-selection '(mouse both)) 964 (if (memq reftex-highlight-selection '(mouse both))
969 reftex-mouse-selected-face 965 reftex-mouse-selected-face
@@ -996,8 +992,7 @@ While entering the regexp, completion on knows citation keys is possible.
996 last))))) 992 last)))))
997 993
998(defun reftex-format-citation (entry format) 994(defun reftex-format-citation (entry format)
999 ;; Format a citation from the info in the BibTeX ENTRY 995 "Format a citation from the info in the BibTeX ENTRY according to FORMAT."
1000
1001 (unless (stringp format) (setq format "\\cite{%l}")) 996 (unless (stringp format) (setq format "\\cite{%l}"))
1002 997
1003 (if (and reftex-comment-citations 998 (if (and reftex-comment-citations
@@ -1064,7 +1059,7 @@ While entering the regexp, completion on knows citation keys is possible.
1064 format) 1059 format)
1065 1060
1066(defun reftex-make-cite-echo-string (entry docstruct-symbol) 1061(defun reftex-make-cite-echo-string (entry docstruct-symbol)
1067 ;; Format a bibtex entry for the echo area and cache the result. 1062 "Format a bibtex ENTRY for the echo area and cache the result."
1068 (let* ((key (reftex-get-bib-field "&key" entry)) 1063 (let* ((key (reftex-get-bib-field "&key" entry))
1069 (string 1064 (string
1070 (let* ((reftex-cite-punctuation '(" " " & " " etal."))) 1065 (let* ((reftex-cite-punctuation '(" " " & " " etal.")))
@@ -1088,9 +1083,9 @@ While entering the regexp, completion on knows citation keys is possible.
1088 string)) 1083 string))
1089 1084
1090(defun reftex-bibtex-selection-callback (data ignore no-revisit) 1085(defun reftex-bibtex-selection-callback (data ignore no-revisit)
1091 ;; Callback function to be called from the BibTeX selection, in 1086 "Callback function to be called from the BibTeX selection, in
1092 ;; order to display context. This function is relatively slow and not 1087order to display context. This function is relatively slow and not
1093 ;; recommended for follow mode. It works OK for individual lookups. 1088recommended for follow mode. It works OK for individual lookups."
1094 (let ((win (selected-window)) 1089 (let ((win (selected-window))
1095 (key (reftex-get-bib-field "&key" data)) 1090 (key (reftex-get-bib-field "&key" data))
1096 bibfile-list item bibtype) 1091 bibfile-list item bibtype)
@@ -1157,7 +1152,7 @@ While entering the regexp, completion on knows citation keys is possible.
1157 alist)))) 1152 alist))))
1158 1153
1159(defun reftex-create-bibtex-file (bibfile) 1154(defun reftex-create-bibtex-file (bibfile)
1160 "Create a new BibTeX database file with all entries referenced in document. 1155 "Create a new BibTeX database BIBFILE with all entries referenced in document.
1161The command prompts for a filename and writes the collected 1156The command prompts for a filename and writes the collected
1162entries to that file. Only entries referenced in the current 1157entries to that file. Only entries referenced in the current
1163document with any \\cite-like macros are used. The sequence in 1158document with any \\cite-like macros are used. The sequence in
@@ -1247,5 +1242,5 @@ created files in the variables `reftex-create-bibtex-header' or
1247 (message "%d entries extracted and copied to new database" 1242 (message "%d entries extracted and copied to new database"
1248 (length entries)))) 1243 (length entries))))
1249 1244
1250 1245(provide 'reftex-cite)
1251;;; reftex-cite.el ends here 1246;;; reftex-cite.el ends here
diff --git a/lisp/textmodes/reftex-parse.el b/lisp/textmodes/reftex-parse.el
index 3a64aad6a06..a99791e5427 100644
--- a/lisp/textmodes/reftex-parse.el
+++ b/lisp/textmodes/reftex-parse.el
@@ -49,7 +49,8 @@
49 (reftex-access-scan-info '(16))) 49 (reftex-access-scan-info '(16)))
50 50
51(defun reftex-do-parse (rescan &optional file) 51(defun reftex-do-parse (rescan &optional file)
52 "Do a document rescan. When allowed, do only a partial scan from FILE." 52 "Do a document rescan.
53When allowed, do only a partial scan from FILE."
53 54
54 ;; Normalize the rescan argument 55 ;; Normalize the rescan argument
55 (setq rescan (cond ((eq rescan t) t) 56 (setq rescan (cond ((eq rescan t) t)
@@ -191,7 +192,7 @@ of master file."
191(defvar index-tags) 192(defvar index-tags)
192 193
193(defun reftex-parse-from-file (file docstruct master-dir) 194(defun reftex-parse-from-file (file docstruct master-dir)
194 ;; Scan the buffer for labels and save them in a list. 195 "Scan the buffer for labels and save them in a list."
195 (let ((regexp (reftex-everything-regexp)) 196 (let ((regexp (reftex-everything-regexp))
196 (bound 0) 197 (bound 0)
197 file-found tmp include-file 198 file-found tmp include-file
@@ -350,8 +351,7 @@ of master file."
350 docstruct)) 351 docstruct))
351 352
352(defun reftex-locate-bibliography-files (master-dir &optional files) 353(defun reftex-locate-bibliography-files (master-dir &optional files)
353 ;; Scan buffer for bibliography macro and return file list. 354 "Scan buffer for bibliography macro and return file list."
354
355 (unless files 355 (unless files
356 (save-excursion 356 (save-excursion
357 (goto-char (point-min)) 357 (goto-char (point-min))
@@ -379,10 +379,10 @@ of master file."
379 (delq nil files))) 379 (delq nil files)))
380 380
381(defun reftex-replace-label-list-segment (old insert &optional entirely) 381(defun reftex-replace-label-list-segment (old insert &optional entirely)
382 ;; Replace the segment in OLD which corresponds to INSERT. 382 "Replace the segment in OLD which corresponds to INSERT.
383 ;; Works with side effects, directly changes old. 383Works with side effects, directly changes old.
384 ;; If entirely is t, just return INSERT. 384If ENTIRELY is t, just return INSERT.
385 ;; This function also makes sure the old toc markers do not point anywhere. 385This function also makes sure the old toc markers do not point anywhere."
386 386
387 (cond 387 (cond
388 (entirely 388 (entirely
@@ -404,8 +404,8 @@ of master file."
404 new)))) 404 new))))
405 405
406(defun reftex-section-info (file) 406(defun reftex-section-info (file)
407 ;; Return a section entry for the current match. 407 "Return a section entry for the current match.
408 ;; Careful: This function expects the match-data to be still in place! 408Careful: This function expects the match-data to be still in place!"
409 (let* ((marker (set-marker (make-marker) (1- (match-beginning 3)))) 409 (let* ((marker (set-marker (make-marker) (1- (match-beginning 3))))
410 (macro (reftex-match-string 3)) 410 (macro (reftex-match-string 3))
411 (prefix (save-match-data 411 (prefix (save-match-data
@@ -440,9 +440,9 @@ of master file."
440 literal (marker-position marker)))) 440 literal (marker-position marker))))
441 441
442(defun reftex-ensure-index-support (&optional abort) 442(defun reftex-ensure-index-support (&optional abort)
443 ;; When index support is turned off, ask to turn it on and 443 "When index support is turned off, ask to turn it on and
444 ;; set the current prefix argument so that `reftex-access-scan-info' 444set the current prefix argument so that `reftex-access-scan-info'
445 ;; will rescan the entire document. 445will rescan the entire document."
446 (cond 446 (cond
447 (reftex-support-index t) 447 (reftex-support-index t)
448 ((y-or-n-p "Turn on index support and rescan entire document? ") 448 ((y-or-n-p "Turn on index support and rescan entire document? ")
@@ -460,8 +460,8 @@ of master file."
460 460
461(defvar test-dummy) 461(defvar test-dummy)
462(defun reftex-index-info (file) 462(defun reftex-index-info (file)
463 ;; Return an index entry for the current match. 463 "Return an index entry for the current match.
464 ;; Careful: This function expects the match-data to be still in place! 464Careful: This function expects the match-data to be still in place!"
465 (catch 'exit 465 (catch 'exit
466 (let* ((macro (reftex-match-string 10)) 466 (let* ((macro (reftex-match-string 10))
467 (bom (match-beginning 10)) 467 (bom (match-beginning 10))
@@ -508,7 +508,7 @@ of master file."
508 (list 'index index-tag context file bom arg key showkey sortkey key-end)))) 508 (list 'index index-tag context file bom arg key showkey sortkey key-end))))
509 509
510(defun reftex-short-context (env parse &optional bound derive) 510(defun reftex-short-context (env parse &optional bound derive)
511 ;; Get about one line of useful context for the label definition at point. 511 "Get about one line of useful context for the label definition at point."
512 512
513 (if (consp parse) 513 (if (consp parse)
514 (setq parse (if derive (cdr parse) (car parse)))) 514 (setq parse (if derive (cdr parse) (car parse))))
@@ -568,9 +568,9 @@ of master file."
568 "INVALID VALUE OF PARSE")))) 568 "INVALID VALUE OF PARSE"))))
569 569
570(defun reftex-where-am-I () 570(defun reftex-where-am-I ()
571 ;; Return the docstruct entry above point. Actually returns a cons 571 "Return the docstruct entry above point.
572 ;; cell in which the cdr is a flag indicating if the information is 572Actually returns a cons cell in which the cdr is a flag indicating
573 ;; exact (t) or approximate (nil). 573if the information is exact (t) or approximate (nil)."
574 574
575 (let ((docstruct (symbol-value reftex-docstruct-symbol)) 575 (let ((docstruct (symbol-value reftex-docstruct-symbol))
576 (cnt 0) rtn rtn-if-no-other 576 (cnt 0) rtn rtn-if-no-other
@@ -748,10 +748,10 @@ of master file."
748 ) 748 )
749 749
750(defsubst reftex-move-to-previous-arg (&optional bound) 750(defsubst reftex-move-to-previous-arg (&optional bound)
751 ;; Assuming that we are in front of a macro argument, 751 "Assuming that we are in front of a macro argument,
752 ;; move backward to the closing parenthesis of the previous argument. 752move backward to the closing parenthesis of the previous argument.
753 ;; This function understands the splitting of macros over several lines 753This function understands the splitting of macros over several lines
754 ;; in TeX. 754in TeX."
755 (cond 755 (cond
756 ;; Just to be quick: 756 ;; Just to be quick:
757 ((memq (preceding-char) '(?\] ?\}))) 757 ((memq (preceding-char) '(?\] ?\})))
@@ -764,28 +764,27 @@ of master file."
764 (t nil))) 764 (t nil)))
765 765
766(defun reftex-what-macro-safe (which &optional bound) 766(defun reftex-what-macro-safe (which &optional bound)
767 ;; reftex-what-macro with special syntax table. 767 "Call `reftex-what-macro' with special syntax table."
768 (reftex-with-special-syntax 768 (reftex-with-special-syntax
769 (reftex-what-macro which bound))) 769 (reftex-what-macro which bound)))
770 770
771(defun reftex-what-macro (which &optional bound) 771(defun reftex-what-macro (which &optional bound)
772 ;; Find out if point is within the arguments of any TeX-macro. 772 "Find out if point is within the arguments of any TeX-macro.
773 ;; The return value is either ("\\macro" . (point)) or a list of them. 773The return value is either (\"\\macro\" . (point)) or a list of them.
774 774
775 ;; If WHICH is nil, immediately return nil. 775If WHICH is nil, immediately return nil.
776 ;; If WHICH is 1, return innermost enclosing macro. 776If WHICH is 1, return innermost enclosing macro.
777 ;; If WHICH is t, return list of all macros enclosing point. 777If WHICH is t, return list of all macros enclosing point.
778 ;; If WHICH is a list of macros, look only for those macros and return the 778If WHICH is a list of macros, look only for those macros and return the
779 ;; name of the first macro in this list found to enclose point. 779 name of the first macro in this list found to enclose point.
780 ;; If the optional BOUND is an integer, bound backwards directed 780If the optional BOUND is an integer, bound backwards directed
781 ;; searches to this point. If it is nil, limit to nearest \section - 781 searches to this point. If it is nil, limit to nearest \\section -
782 ;; like statement. 782 like statement.
783 783
784 ;; This function is pretty stable, but can be fooled if the text contains 784This function is pretty stable, but can be fooled if the text contains
785 ;; things like \macro{aa}{bb} where \macro is defined to take only one 785things like \\macro{aa}{bb} where \\macro is defined to take only one
786 ;; argument. As RefTeX cannot know this, the string "bb" would still be 786argument. As RefTeX cannot know this, the string \"bb\" would still be
787 ;; considered an argument of macro \macro. 787considered an argument of macro \\macro."
788
789 (unless reftex-section-regexp (reftex-compile-variables)) 788 (unless reftex-section-regexp (reftex-compile-variables))
790 (catch 'exit 789 (catch 'exit
791 (if (null which) (throw 'exit nil)) 790 (if (null which) (throw 'exit nil))
@@ -832,20 +831,19 @@ of master file."
832 (nreverse cmd-list))))) 831 (nreverse cmd-list)))))
833 832
834(defun reftex-what-environment (which &optional bound) 833(defun reftex-what-environment (which &optional bound)
835 ;; Find out if point is inside a LaTeX environment. 834 "Find out if point is inside a LaTeX environment.
836 ;; The return value is (e.g.) either ("equation" . (point)) or a list of 835The return value is (e.g.) either (\"equation\" . (point)) or a list of
837 ;; them. 836them.
838 837
839 ;; If WHICH is nil, immediately return nil. 838If WHICH is nil, immediately return nil.
840 ;; If WHICH is 1, return innermost enclosing environment. 839If WHICH is 1, return innermost enclosing environment.
841 ;; If WHICH is t, return list of all environments enclosing point. 840If WHICH is t, return list of all environments enclosing point.
842 ;; If WHICH is a list of environments, look only for those environments and 841If WHICH is a list of environments, look only for those environments and
843 ;; return the name of the first environment in this list found to enclose 842 return the name of the first environment in this list found to enclose
844 ;; point. 843 point.
845 844
846 ;; If the optional BOUND is an integer, bound backwards directed searches to 845If the optional BOUND is an integer, bound backwards directed searches to
847 ;; this point. If it is nil, limit to nearest \section - like statement. 846this point. If it is nil, limit to nearest \\section - like statement."
848
849 (unless reftex-section-regexp (reftex-compile-variables)) 847 (unless reftex-section-regexp (reftex-compile-variables))
850 (catch 'exit 848 (catch 'exit
851 (save-excursion 849 (save-excursion
@@ -870,18 +868,17 @@ of master file."
870 (nreverse env-list))))) 868 (nreverse env-list)))))
871 869
872(defun reftex-what-special-env (which &optional bound) 870(defun reftex-what-special-env (which &optional bound)
873 ;; Run the special environment parsers and return the matches. 871 "Run the special environment parsers and return the matches.
874 ;; 872
875 ;; The return value is (e.g.) either ("my-parser-function" . (point)) 873The return value is (e.g.) either (\"my-parser-function\" . (point))
876 ;; or a list of them. 874or a list of them.
877
878 ;; If WHICH is nil, immediately return nil.
879 ;; If WHICH is 1, return innermost enclosing environment.
880 ;; If WHICH is t, return list of all environments enclosing point.
881 ;; If WHICH is a list of environments, look only for those environments and
882 ;; return the name of the first environment in this list found to enclose
883 ;; point.
884 875
876If WHICH is nil, immediately return nil.
877If WHICH is 1, return innermost enclosing environment.
878If WHICH is t, return list of all environments enclosing point.
879If WHICH is a list of environments, look only for those environments and
880 return the name of the first environment in this list found to enclose
881 point."
885 (unless reftex-section-regexp (reftex-compile-variables)) 882 (unless reftex-section-regexp (reftex-compile-variables))
886 (catch 'exit 883 (catch 'exit
887 (save-excursion 884 (save-excursion
@@ -911,10 +908,10 @@ of master file."
911 (car specials)))))) 908 (car specials))))))
912 909
913(defsubst reftex-move-to-next-arg (&optional ignore) 910(defsubst reftex-move-to-next-arg (&optional ignore)
914 ;; Assuming that we are at the end of a macro name or a macro argument, 911 "Assuming that we are at the end of a macro name or a macro argument,
915 ;; move forward to the opening parenthesis of the next argument. 912move forward to the opening parenthesis of the next argument.
916 ;; This function understands the splitting of macros over several lines 913This function understands the splitting of macros over several lines
917 ;; in TeX. 914in TeX."
918 (cond 915 (cond
919 ;; Just to be quick: 916 ;; Just to be quick:
920 ((memq (following-char) '(?\[ ?\{))) 917 ((memq (following-char) '(?\[ ?\{)))
@@ -930,8 +927,8 @@ of master file."
930 (reftex-nth-arg (nth 5 entry) (nth 6 entry)))) 927 (reftex-nth-arg (nth 5 entry) (nth 6 entry))))
931 928
932(defun reftex-nth-arg (n &optional opt-args) 929(defun reftex-nth-arg (n &optional opt-args)
933 ;; Return the nth following {} or [] parentheses content. 930 "Return the Nth following {} or [] parentheses content.
934 ;; OPT-ARGS is a list of argument numbers which are optional. 931OPT-ARGS is a list of argument numbers which are optional."
935 932
936 ;; If we are sitting at a macro start, skip to end of macro name. 933 ;; If we are sitting at a macro start, skip to end of macro name.
937 (and (eq (following-char) ?\\) (skip-chars-forward "a-zA-Z*\\\\")) 934 (and (eq (following-char) ?\\) (skip-chars-forward "a-zA-Z*\\\\"))
@@ -974,8 +971,8 @@ of master file."
974 (error nil))) 971 (error nil)))
975 972
976(defun reftex-context-substring (&optional to-end) 973(defun reftex-context-substring (&optional to-end)
977 ;; Return up to 150 chars from point 974 "Return up to 150 chars from point.
978 ;; When point is just after a { or [, limit string to matching parenthesis 975When point is just after a { or [, limit string to matching parenthesis"
979 (cond 976 (cond
980 (to-end 977 (to-end
981 ;; Environment - find next \end 978 ;; Environment - find next \end
@@ -1007,8 +1004,7 @@ of master file."
1007(defvar reftex-section-numbers (make-vector reftex-max-section-depth 0)) 1004(defvar reftex-section-numbers (make-vector reftex-max-section-depth 0))
1008 1005
1009(defun reftex-init-section-numbers (&optional toc-entry appendix) 1006(defun reftex-init-section-numbers (&optional toc-entry appendix)
1010 ;; Initialize the section numbers with zeros or with what is found 1007 "Initialize the section numbers with zeros or with what is found in the TOC-ENTRY."
1011 ;; in the toc entry.
1012 (let* ((level (or (nth 5 toc-entry) -1)) 1008 (let* ((level (or (nth 5 toc-entry) -1))
1013 (numbers (nreverse (split-string (or (nth 6 toc-entry) "") "\\."))) 1009 (numbers (nreverse (split-string (or (nth 6 toc-entry) "") "\\.")))
1014 (depth (1- (length reftex-section-numbers))) 1010 (depth (1- (length reftex-section-numbers)))
@@ -1026,8 +1022,8 @@ of master file."
1026 (put 'reftex-section-numbers 'appendix appendix)) 1022 (put 'reftex-section-numbers 'appendix appendix))
1027 1023
1028(defun reftex-section-number (&optional level star) 1024(defun reftex-section-number (&optional level star)
1029 ;; Return a string with the current section number. 1025 "Return a string with the current section number.
1030 ;; When LEVEL is non-nil, increase section numbers on that level. 1026When LEVEL is non-nil, increase section numbers on that level."
1031 (let* ((depth (1- (length reftex-section-numbers))) idx n (string "") 1027 (let* ((depth (1- (length reftex-section-numbers))) idx n (string "")
1032 (appendix (get 'reftex-section-numbers 'appendix)) 1028 (appendix (get 'reftex-section-numbers 'appendix))
1033 (partspecial (and (not reftex-part-resets-chapter) 1029 (partspecial (and (not reftex-part-resets-chapter)
@@ -1073,7 +1069,7 @@ of master file."
1073 string)))) 1069 string))))
1074 1070
1075(defun reftex-roman-number (n) 1071(defun reftex-roman-number (n)
1076 ;; Return as a string the roman number equal to N. 1072 "Return as a string the roman number equal to N."
1077 (let ((nrest n) 1073 (let ((nrest n)
1078 (string "") 1074 (string "")
1079 (list '((1000 . "M") ( 900 . "CM") ( 500 . "D") ( 400 . "CD") 1075 (list '((1000 . "M") ( 900 . "CM") ( 500 . "D") ( 400 . "CD")