Function: reftex-where-am-I

reftex-where-am-I is an autoloaded and byte-compiled function defined in reftex-parse.el.gz.

Signature

(reftex-where-am-I)

Documentation

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).

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/reftex-parse.el.gz
;;;###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)."

  (let ((docstruct (symbol-value reftex-docstruct-symbol))
        (cnt 0) rtn rtn-if-no-other
        found)
    (save-excursion
      (while (not rtn)
        (incf cnt)
        (setq found (re-search-backward (reftex-everything-regexp) nil t))
        (setq rtn
              (cond
               ((not found)
                ;; no match
                (or
                 (car (member (list 'bof (reftex--get-buffer-identifier))
                              docstruct))
                 (not (setq cnt 2))
                 (assq 'bof docstruct)  ;; for safety reasons
                 'corrupted))
               ((match-end 1)
                ;; Label
                (assoc (reftex-match-string 1)
                       (symbol-value reftex-docstruct-symbol)))
               ((match-end 3)
                ;; Section
                (goto-char (1- (match-beginning 3)))
                (let* ((buffile (reftex--get-buffer-identifier))
                       (list (member (list 'bof buffile)
                                     docstruct))
                       (endelt (car (member (list 'eof buffile)
                                            list)))
                       rtn1)
                  (while (and list (not (eq endelt (car list))))
                    (if (and (eq (car (car list)) 'toc)
                             (equal buffile
                                    (nth 3 (car list))))
                        (cond
                         ((equal (point)
                                 (or (and (markerp (nth 4 (car list)))
                                          (marker-position (nth 4 (car list))))
                                     (nth 8 (car list))))
                          ;; Fits with marker position or recorded position
                          (setq rtn1 (car list) list nil))
                         ((looking-at (reftex-make-regexp-allow-for-ctrl-m
                                       (nth 7 (car list))))
                          ;; Same title: remember, but keep looking
                          (setq rtn-if-no-other (car list)))))
                    (pop list))
                  rtn1))
               ((match-end 7)
                ;; Input or include...
                (car
                 (member (list 'eof (reftex-locate-file
                                     (reftex-match-string 7) "tex"
                                     (cdr (assq 'master-dir docstruct))))
                         docstruct)))
               ((match-end 9)
                (assq 'appendix (symbol-value reftex-docstruct-symbol)))
               ((match-end 10)
                ;; Index entry
                (when reftex-support-index
                  (let* ((index-info (save-excursion
                                       (reftex-index-info-safe nil)))
                         (list (member
                                (list 'bof (reftex--get-buffer-identifier))
                                docstruct))
                         (endelt
                          (car (member
                                (list 'eof (reftex--get-buffer-identifier))
                                list)))
                         dist last-dist last (n 0))
                    ;; Check all index entries with equal text
                    (while (and list (not (eq endelt (car list))))
                      (when (and (eq (car (car list)) 'index)
                                 (string= (nth 2 index-info)
                                          (nth 2 (car list))))
                        (incf n)
                        (setq dist (abs (- (point) (nth 4 (car list)))))
                        (if (or (not last-dist) (< dist last-dist))
                            (setq last-dist dist last (car list))))
                      (setq list (cdr list)))
                    ;; We are sure if we have only one, or a zero distance
                    (cond ((or (= n 1) (equal dist 0)) last)
                          ((> n 1) (setq cnt 2) last)
                          (t nil)))))
               ((match-end 11)
                (save-excursion
                  (goto-char (match-end 11))
                  (assoc (reftex-no-props
                          (reftex-nth-arg-wrapper
                           (reftex-match-string 11)))
                         (symbol-value reftex-docstruct-symbol))))
               (t
                (error "This should not happen (reftex-where-am-I)"))))))
    ;; Check if there was only a by-name match for the section.
    (when (and (not rtn) rtn-if-no-other)
      (setq rtn rtn-if-no-other
            cnt 2))
    (cons rtn (eq cnt 1))))