]> code.delx.au - gnu-emacs/blobdiff - lisp/textmodes/reftex-parse.el
Merge from emacs-24; up to 117691
[gnu-emacs] / lisp / textmodes / reftex-parse.el
index 6bfc70c5d44278fc61c3e211874b9ee2433fd5bc..ce73939ac32bf6127f8861d39cbe06de372b7441 100644 (file)
@@ -1,6 +1,6 @@
 ;;; reftex-parse.el --- parser functions for RefTeX
 
-;; Copyright (C) 1997-2013 Free Software Foundation, Inc.
+;; Copyright (C) 1997-2014 Free Software Foundation, Inc.
 
 ;; Author: Carsten Dominik <dominik@science.uva.nl>
 ;; Maintainer: auctex-devel@gnu.org
              ,@body))
        (set-syntax-table saved-syntax))))
 
+;;;###autoload
 (defun reftex-parse-one ()
   "Re-parse this file."
   (interactive)
   (let ((reftex-enable-partial-scans t))
     (reftex-access-scan-info '(4))))
 
+;;;###autoload
 (defun reftex-parse-all ()
   "Re-parse entire document."
   (interactive)
   (reftex-access-scan-info '(16)))
 
+(defvar reftex--index-tags)
+
+;;;###autoload
 (defun reftex-do-parse (rescan &optional file)
-  "Do a document rescan.  When allowed, do only a partial scan from FILE."
+  "Do a document rescan.
+When allowed, do only a partial scan from FILE."
 
   ;; Normalize the rescan argument
   (setq rescan (cond ((eq rescan t) t)
@@ -71,7 +77,7 @@
          (file (or file (buffer-file-name)))
          (true-file (file-truename file))
          (bibview-cache (assq 'bibview-cache old-list))
-         (index-tags (cdr (assq 'index-tags old-list)))
+         (reftex--index-tags (cdr (assq 'index-tags old-list)))
          from-file appendix docstruct tmp)
 
     ;; Make sure replacement is really an option here
@@ -91,7 +97,7 @@
                 (t (error "This should not happen (reftex-do-parse)"))))
 
     ;; Reset index-tags if we scan everything
-    (if (equal rescan 1) (setq index-tags nil))
+    (if (equal rescan 1) (setq reftex--index-tags nil))
 
     ;; Find active toc entry and initialize section-numbers
     (setq reftex-active-toc (reftex-last-assoc-before-elt
            (entry (or (assq 'is-multi docstruct)
                       (car (push (list 'is-multi is-multi) docstruct)))))
       (setcdr entry (cons is-multi nil)))
-    (and index-tags (setq index-tags (sort index-tags 'string<)))
+    (and reftex--index-tags
+         (setq reftex--index-tags (sort reftex--index-tags 'string<)))
     (let ((index-tag-cell (assq 'index-tags docstruct)))
       (if index-tag-cell
-          (setcdr index-tag-cell index-tags)
-        (push (cons 'index-tags index-tags) docstruct)))
+          (setcdr index-tag-cell reftex--index-tags)
+        (push (cons 'index-tags reftex--index-tags) docstruct)))
     (unless (assq 'xr docstruct)
       (let* ((allxr (reftex-all-assq 'xr-doc docstruct))
              (alist (mapcar
     (set reftex-docstruct-symbol docstruct)
     (put reftex-docstruct-symbol 'modified t)))
 
+;;;###autoload
 (defun reftex-everything-regexp ()
   (if reftex-support-index
       reftex-everything-regexp
     reftex-everything-regexp-no-index))
 
+;; NB this is a global autoload - see reftex.el.
 ;;;###autoload
 (defun reftex-all-document-files (&optional relative)
   "Return a list of all files belonging to the current document.
@@ -188,10 +197,8 @@ of master file."
     (nreverse file-list)))
 
 ;; Bound in the caller, reftex-do-parse.
-(defvar index-tags)
-
 (defun reftex-parse-from-file (file docstruct master-dir)
-  ;; Scan the buffer for labels and save them in a list.
+  "Scan the buffer for labels and save them in a list."
   (let ((regexp (reftex-everything-regexp))
         (bound 0)
         file-found tmp include-file
@@ -238,12 +245,13 @@ of master file."
                           ;; \label{} defs should always be honored,
                           ;; just no keyval style [label=foo] defs.
                           (string-equal "\label{" (substring (reftex-match-string 0) 0 7))
-                          (not (fboundp 'TeX-current-macro))
-                          (not (fboundp 'LaTeX-current-environment))
-                          (not (or (member (save-match-data (TeX-current-macro))
-                                           reftex-label-ignored-macros-and-environments)
-                                   (member (save-match-data (LaTeX-current-environment))
-                                           reftex-label-ignored-macros-and-environments))))
+                           (if (and (fboundp 'TeX-current-macro)
+                                    (fboundp 'LaTeX-current-environment))
+                               (not (or (member (save-match-data (TeX-current-macro))
+                                                reftex-label-ignored-macros-and-environments)
+                                        (member (save-match-data (LaTeX-current-environment))
+                                                reftex-label-ignored-macros-and-environments)))
+                             t))
                   (push (reftex-label-info (reftex-match-string 1) file bound)
                         docstruct)))
 
@@ -298,7 +306,7 @@ of master file."
                  (when reftex-support-index
                    (setq index-entry (reftex-index-info file))
                    (when index-entry
-                     (add-to-list 'index-tags (nth 1 index-entry))
+                     (add-to-list 'reftex--index-tags (nth 1 index-entry))
                      (push index-entry docstruct))))
 
                 ((match-end 11)
@@ -348,21 +356,39 @@ of master file."
     ;; Return the list
     docstruct))
 
-(defun reftex-locate-bibliography-files (master-dir &optional files)
-  ;; Scan buffer for bibliography macro and return file list.
+(defun reftex-using-biblatex-p ()
+  "Return non-nil if we are using biblatex rather than bibtex."
+  (if (boundp 'TeX-active-styles)
+      ;; the sophisticated AUCTeX way
+      (member "biblatex" TeX-active-styles)
+    ;; poor-man's check...
+    (save-excursion
+      (re-search-forward "^[^%\n]*?\\\\usepackage.*{biblatex}" nil t))))
 
+;;;###autoload
+(defun reftex-locate-bibliography-files (master-dir &optional files)
+  "Scan buffer for bibliography macros and return file list."
   (unless files
     (save-excursion
       (goto-char (point-min))
-      (if (re-search-forward
-           (concat
-;           "\\(\\`\\|[\n\r]\\)[^%]*\\\\\\("
-            "\\(^\\)[^%\n\r]*\\\\\\("
-            (mapconcat 'identity reftex-bibliography-commands "\\|")
-            "\\){[ \t]*\\([^}]+\\)") nil t)
-          (setq files
-                (split-string (reftex-match-string 3)
-                              "[ \t\n\r]*,[ \t\n\r]*")))))
+      ;; when biblatex is used, multiple \bibliography or
+      ;; \addbibresource macros are allowed.  With plain bibtex, only
+      ;; the first is used.
+      (let ((using-biblatex (reftex-using-biblatex-p))
+           (again t))
+       (while (and again
+                   (re-search-forward
+                    (concat
+                     ;;           "\\(\\`\\|[\n\r]\\)[^%]*\\\\\\("
+                     "\\(^\\)[^%\n\r]*\\\\\\("
+                     (mapconcat 'identity reftex-bibliography-commands "\\|")
+                     "\\)\\(\\[.+?\\]\\)?{[ \t]*\\([^}]+\\)") nil t))
+         (setq files
+               (append files
+                       (split-string (reftex-match-string 4)
+                                     "[ \t\n\r]*,[ \t\n\r]*")))
+         (unless using-biblatex
+           (setq again nil))))))
   (when files
     (setq files
           (mapcar
@@ -378,10 +404,10 @@ of master file."
     (delq nil files)))
 
 (defun reftex-replace-label-list-segment (old insert &optional entirely)
-  ;; Replace the segment in OLD which corresponds to INSERT.
-  ;; Works with side effects, directly changes old.
-  ;; If entirely is t, just return INSERT.
-  ;; This function also makes sure the old toc markers do not point anywhere.
+  "Replace the segment in OLD which corresponds to INSERT.
+Works with side effects, directly changes old.
+If ENTIRELY is t, just return INSERT.
+This function also makes sure the old toc markers do not point anywhere."
 
   (cond
    (entirely
@@ -402,9 +428,10 @@ of master file."
           (setcdr (nthcdr (1- (length new)) new) (cdr eof-list)))
         new))))
 
+;;;###autoload
 (defun reftex-section-info (file)
-  ;; Return a section entry for the current match.
-  ;; Careful: This function expects the match-data to be still in place!
+  "Return a section entry for the current match.
+Careful: This function expects the match-data to be still in place!"
   (let* ((marker (set-marker (make-marker) (1- (match-beginning 3))))
          (macro (reftex-match-string 3))
          (prefix (save-match-data
@@ -438,10 +465,11 @@ of master file."
     (list 'toc "toc" text file marker level section-number
           literal (marker-position marker))))
 
+;;;###autoload
 (defun reftex-ensure-index-support (&optional abort)
-  ;; When index support is turned off, ask to turn it on and
-  ;; set the current prefix argument so that `reftex-access-scan-info'
-  ;; will rescan the entire document.
+  "When index support is turned off, ask to turn it on and
+set the current prefix argument so that `reftex-access-scan-info'
+will rescan the entire document."
   (cond
    (reftex-support-index t)
    ((y-or-n-p "Turn on index support and rescan entire document? ")
@@ -453,14 +481,16 @@ of master file."
         (ding)
         (sit-for 1)))))
 
+;;;###autoload
 (defun reftex-index-info-safe (file)
   (reftex-with-special-syntax
    (reftex-index-info file)))
 
 (defvar test-dummy)
+;;;###autoload
 (defun reftex-index-info (file)
-  ;; Return an index entry for the current match.
-  ;; Careful: This function expects the match-data to be still in place!
+  "Return an index entry for the current match.
+Careful: This function expects the match-data to be still in place!"
   (catch 'exit
     (let* ((macro (reftex-match-string 10))
            (bom (match-beginning 10))
@@ -506,8 +536,9 @@ of master file."
       ;;       0        1       2      3   4   5  6      7       8      9
       (list 'index index-tag context file bom arg key showkey sortkey key-end))))
 
+;;;###autoload
 (defun reftex-short-context (env parse &optional bound derive)
-  ;; Get about one line of useful context for the label definition at point.
+  "Get about one line of useful context for the label definition at point."
 
   (if (consp parse)
       (setq parse (if derive (cdr parse) (car parse))))
@@ -566,10 +597,11 @@ of master file."
     (t
      "INVALID VALUE OF PARSE"))))
 
+;;;###autoload
 (defun reftex-where-am-I ()
-  ;; Return the docstruct entry above point.  Actually returns a cons
-  ;; cell in which the cdr is a flag indicating if the information is
-  ;; exact (t) or approximate (nil).
+  "Return the docstruct entry above point.
+Actually returns a cons cell in which the cdr is a flag indicating
+if the information is exact (t) or approximate (nil)."
 
   (let ((docstruct (symbol-value reftex-docstruct-symbol))
         (cnt 0) rtn rtn-if-no-other
@@ -664,6 +696,7 @@ of master file."
             cnt 2))
     (cons rtn (eq cnt 1))))
 
+;;;###autoload
 (defun reftex-notice-new (&optional n force)
   "Hook to handshake with RefTeX after something new has been inserted."
   ;; Add a new entry to the docstruct list.  If it is a section, renumber
@@ -740,17 +773,17 @@ of master file."
              ;; Index entry
              (and reftex-support-index
                   (setq entry (reftex-index-info-safe buffer-file-name))
-                  ;; FIXME: (add-to-list 'index-tags (nth 1 index-entry))
+                  ;; FIXME: (add-to-list 'reftex--index-tags (nth 1 index-entry))
                   (push entry (cdr tail))))))))))
 
     (error nil))
   )
 
 (defsubst reftex-move-to-previous-arg (&optional bound)
-  ;; Assuming that we are in front of a macro argument,
-  ;; move backward to the closing parenthesis of the previous argument.
-  ;; This function understands the splitting of macros over several lines
-  ;; in TeX.
+  "Assuming that we are in front of a macro argument,
+move backward to the closing parenthesis of the previous argument.
+This function understands the splitting of macros over several lines
+in TeX."
   (cond
    ;; Just to be quick:
    ((memq (preceding-char) '(?\] ?\})))
@@ -762,29 +795,30 @@ of master file."
     t)
    (t nil)))
 
+;;;###autoload
 (defun reftex-what-macro-safe (which &optional bound)
-  ;; reftex-what-macro with special syntax table.
+  "Call `reftex-what-macro' with special syntax table."
   (reftex-with-special-syntax
    (reftex-what-macro which bound)))
 
+;;;###autoload
 (defun reftex-what-macro (which &optional bound)
-  ;; Find out if point is within the arguments of any TeX-macro.
-  ;; The return value is either ("\\macro" . (point)) or a list of them.
-
-  ;; If WHICH is nil, immediately return nil.
-  ;; If WHICH is 1, return innermost enclosing macro.
-  ;; If WHICH is t, return list of all macros enclosing point.
-  ;; If WHICH is a list of macros, look only for those macros and return the
-  ;;    name of the first macro in this list found to enclose point.
-  ;; If the optional BOUND is an integer, bound backwards directed
-  ;;    searches to this point.  If it is nil, limit to nearest \section -
-  ;;    like statement.
-
-  ;; This function is pretty stable, but can be fooled if the text contains
-  ;; things like \macro{aa}{bb} where \macro is defined to take only one
-  ;; argument.  As RefTeX cannot know this, the string "bb" would still be
-  ;; considered an argument of macro \macro.
-
+  "Find out if point is within the arguments of any TeX-macro.
+The return value is either (\"\\macro\" . (point)) or a list of them.
+
+If WHICH is nil, immediately return nil.
+If WHICH is 1, return innermost enclosing macro.
+If WHICH is t, return list of all macros enclosing point.
+If WHICH is a list of macros, look only for those macros and return the
+  name of the first macro in this list found to enclose point.
+If the optional BOUND is an integer, bound backwards directed
+  searches to this point.  If it is nil, limit to nearest \\section -
+  like statement.
+
+This function is pretty stable, but can be fooled if the text contains
+things like \\macro{aa}{bb} where \\macro is defined to take only one
+argument.  As RefTeX cannot know this, the string \"bb\" would still be
+considered an argument of macro \\macro."
   (unless reftex-section-regexp (reftex-compile-variables))
   (catch 'exit
     (if (null which) (throw 'exit nil))
@@ -830,21 +864,21 @@ of master file."
             (goto-char pos)))
         (nreverse cmd-list)))))
 
+;;;###autoload
 (defun reftex-what-environment (which &optional bound)
-  ;; Find out if point is inside a LaTeX environment.
-  ;; The return value is (e.g.) either ("equation" . (point)) or a list of
-  ;; them.
-
-  ;; If WHICH is nil, immediately return nil.
-  ;; If WHICH is 1, return innermost enclosing environment.
-  ;; If WHICH is t, return list of all environments enclosing point.
-  ;; If WHICH is a list of environments, look only for those environments and
-  ;;   return the name of the first environment in this list found to enclose
-  ;;   point.
-
-  ;; If the optional BOUND is an integer, bound backwards directed searches to
-  ;; this point.  If it is nil, limit to nearest \section - like statement.
-
+  "Find out if point is inside a LaTeX environment.
+The return value is (e.g.) either (\"equation\" . (point)) or a list of
+them.
+
+If WHICH is nil, immediately return nil.
+If WHICH is 1, return innermost enclosing environment.
+If WHICH is t, return list of all environments enclosing point.
+If WHICH is a list of environments, look only for those environments and
+  return the name of the first environment in this list found to enclose
+  point.
+
+If the optional BOUND is an integer, bound backwards directed searches to
+this point.  If it is nil, limit to nearest \\section - like statement."
   (unless reftex-section-regexp (reftex-compile-variables))
   (catch 'exit
     (save-excursion
@@ -868,19 +902,19 @@ of master file."
             (throw 'exit (cons env (point))))))
         (nreverse env-list)))))
 
+;;;###autoload
 (defun reftex-what-special-env (which &optional bound)
-  ;; Run the special environment parsers and return the matches.
-  ;;
-  ;; The return value is (e.g.) either ("my-parser-function" . (point))
-  ;; or a list of them.
-
-  ;; If WHICH is nil, immediately return nil.
-  ;; If WHICH is 1, return innermost enclosing environment.
-  ;; If WHICH is t, return list of all environments enclosing point.
-  ;; If WHICH is a list of environments, look only for those environments and
-  ;;   return the name of the first environment in this list found to enclose
-  ;;   point.
+  "Run the special environment parsers and return the matches.
+
+The return value is (e.g.) either (\"my-parser-function\" . (point))
+or a list of them.
 
+If WHICH is nil, immediately return nil.
+If WHICH is 1, return innermost enclosing environment.
+If WHICH is t, return list of all environments enclosing point.
+If WHICH is a list of environments, look only for those environments and
+  return the name of the first environment in this list found to enclose
+  point."
   (unless reftex-section-regexp (reftex-compile-variables))
   (catch 'exit
     (save-excursion
@@ -909,11 +943,11 @@ of master file."
             specials
           (car specials))))))
 
-(defsubst reftex-move-to-next-arg (&optional ignore)
-  ;; Assuming that we are at the end of a macro name or a macro argument,
-  ;; move forward to the opening parenthesis of the next argument.
-  ;; This function understands the splitting of macros over several lines
-  ;; in TeX.
+(defsubst reftex-move-to-next-arg (&optional _ignore)
+  "Assuming that we are at the end of a macro name or a macro argument,
+move forward to the opening parenthesis of the next argument.
+This function understands the splitting of macros over several lines
+in TeX."
   (cond
    ;; Just to be quick:
    ((memq (following-char) '(?\[ ?\{)))
@@ -928,9 +962,10 @@ of master file."
   (let ((entry (assoc key reftex-env-or-mac-alist)))
     (reftex-nth-arg (nth 5 entry) (nth 6 entry))))
 
+;;;###autoload
 (defun reftex-nth-arg (n &optional opt-args)
-  ;; Return the nth following {} or [] parentheses content.
-  ;; OPT-ARGS is a list of argument numbers which are optional.
+  "Return the Nth following {} or [] parentheses content.
+OPT-ARGS is a list of argument numbers which are optional."
 
   ;; If we are sitting at a macro start, skip to end of macro name.
   (and (eq (following-char) ?\\) (skip-chars-forward "a-zA-Z*\\\\"))
@@ -966,6 +1001,7 @@ of master file."
           (reftex-context-substring)
         nil))))
 
+;;;###autoload
 (defun reftex-move-over-touching-args ()
   (condition-case nil
       (while (memq (following-char) '(?\[ ?\{))
@@ -973,8 +1009,8 @@ of master file."
     (error nil)))
 
 (defun reftex-context-substring (&optional to-end)
-  ;; Return up to 150 chars from point
-  ;; When point is just after a { or [, limit string to matching parenthesis
+  "Return up to 150 chars from point.
+When point is just after a { or [, limit string to matching parenthesis"
   (cond
    (to-end
     ;; Environment - find next \end
@@ -1005,9 +1041,9 @@ of master file."
 ;; Variable holding the vector with section numbers
 (defvar reftex-section-numbers (make-vector reftex-max-section-depth 0))
 
+;;;###autoload
 (defun reftex-init-section-numbers (&optional toc-entry appendix)
-  ;; Initialize the section numbers with zeros or with what is found
-  ;; in the toc entry.
+  "Initialize the section numbers with zeros or with what is found in the TOC-ENTRY."
   (let* ((level  (or (nth 5 toc-entry) -1))
          (numbers (nreverse (split-string (or (nth 6 toc-entry) "") "\\.")))
          (depth (1- (length reftex-section-numbers)))
@@ -1024,9 +1060,10 @@ of master file."
       (decf i)))
   (put 'reftex-section-numbers 'appendix appendix))
 
+;;;###autoload
 (defun reftex-section-number (&optional level star)
-  ;; Return a string with the current section number.
-  ;; When LEVEL is non-nil, increase section numbers on that level.
+  "Return a string with the current section number.
+When LEVEL is non-nil, increase section numbers on that level."
   (let* ((depth (1- (length reftex-section-numbers))) idx n (string "")
          (appendix (get 'reftex-section-numbers 'appendix))
          (partspecial (and (not reftex-part-resets-chapter)
@@ -1072,7 +1109,7 @@ of master file."
         string))))
 
 (defun reftex-roman-number (n)
-  ;; Return as a string the roman number equal to N.
+  "Return as a string the roman number equal to N."
   (let ((nrest n)
         (string "")
         (list '((1000 . "M") ( 900 . "CM") ( 500 . "D") ( 400 . "CD")
@@ -1092,3 +1129,7 @@ of master file."
 (provide 'reftex-parse)
 
 ;;; reftex-parse.el ends here
+
+;; Local Variables:
+;; generated-autoload-file: "reftex.el"
+;; End: