Function: reftex-insert-docstruct

reftex-insert-docstruct is an autoloaded and byte-compiled function defined in reftex-sel.el.gz.

Signature

(reftex-insert-docstruct BUF TOC LABELS INDEX-ENTRIES FILES CONTEXT COUNTER SHOW-COMMENTED HERE-I-AM XR-PREFIX TOC-BUFFER)

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/reftex-sel.el.gz
;;;###autoload
(defun reftex-insert-docstruct
  (buf toc labels index-entries files context counter show-commented
            here-I-am xr-prefix toc-buffer)
  ;; Insert an excerpt of the docstruct list.
  ;; Return the data property of the entry corresponding to HERE-I-AM.
  ;; BUF is the buffer which has the correct docstruct-symbol.
  ;; LABELS non-nil means to include labels into the list.
  ;;        When a string, indicates the label type to include
  ;; FILES non-nil means to display file boundaries.
  ;; CONTEXT non-nil means to include label context.
  ;; COUNTER means to count the labels.
  ;; SHOW-COMMENTED means to include also labels which are commented out.
  ;; HERE-I-AM is a member of the docstruct list.  The function will return
  ;;           a used member near to this one, as a possible starting point.
  ;; XR-PREFIX is the prefix to put in front of labels.
  ;; TOC-BUFFER means this is to fill the toc buffer.
  (let* ((font reftex-use-fonts)
         (cnt 0)
         (index -1)
         (toc-indent " ")
         (label-indent
          (concat "> "
                  (if toc (make-string (* 7 reftex-level-indent) ?\ ) "")))
         (context-indent
          (concat ".   "
                  (if toc (make-string (* 7 reftex-level-indent) ?\ ) "")))
         (mouse-face
          (if (memq reftex-highlight-selection '(mouse both))
              reftex-mouse-selected-face
            nil))
         (label-face reftex-label-face)
         (index-face reftex-index-face)
         all cell text label typekey note comment master-dir-re
         prev-inserted offset from to index-tag docstruct-symbol)

    ;; Pop to buffer buf to get the correct buffer-local variables
    (with-current-buffer buf

      ;; Ensure access to scanning info
      (reftex-access-scan-info)

      (setq docstruct-symbol reftex-docstruct-symbol
            all (symbol-value reftex-docstruct-symbol)
            reftex-active-toc nil
            master-dir-re
            (concat "\\`" (regexp-quote
                           (file-name-directory (reftex-TeX-master-file))))))

    (set (make-local-variable 'reftex-docstruct-symbol) docstruct-symbol)
    (set (make-local-variable 'reftex-prefix)
         (cdr (assoc labels reftex-typekey-to-prefix-alist)))
    (if (equal reftex-prefix " ") (setq reftex-prefix nil))

    ;; Walk the docstruct and insert the appropriate stuff
    (while (setq cell (pop all))

      (cl-incf index)
      (setq from (point))

      (cond

       ((memq (car cell) '(bib thebib label-numbers appendix
                               master-dir bibview-cache is-multi xr xr-doc)))
       ;; These are currently ignored

       ((memq (car cell) '(bof eof file-error))
        ;; Beginning or end of a file
        (when files
          (setq prev-inserted cell)
;         (if (eq offset 'attention) (setq offset cell))
          (insert
           " File " (if (string-match master-dir-re (nth 1 cell))
                   (substring (nth 1 cell) (match-end 0))
                 (nth 1 cell))
           (cond ((eq (car cell) 'bof) " starts here\n")
                 ((eq (car cell) 'eof) " ends here\n")
                 ((eq (car cell) 'file-error) " was not found\n")))
          (setq to (point))
          (when font
            (put-text-property from to
                               'font-lock-face reftex-file-boundary-face))
          (when toc-buffer
            (if mouse-face
                (put-text-property from (1- to)
                                   'mouse-face mouse-face))
            (put-text-property from to :data cell))))

       ((eq (car cell) 'toc)
        ;; a table of contents entry
        (when (and toc
                   (<= (nth 5 cell) reftex-toc-max-level))
          (setq prev-inserted cell)
;         (if (eq offset 'attention) (setq offset cell))
          (setq reftex-active-toc cell)
          (insert (concat toc-indent (nth 2 cell) "\n"))
          (setq to (point))
          (when font
            (put-text-property from to
                               'font-lock-face reftex-section-heading-face))
          (when toc-buffer
            (if mouse-face
                (put-text-property from (1- to)
                                   'mouse-face mouse-face))
            (put-text-property from to :data cell))
          (goto-char to)))

       ((stringp (car cell))
        ;; a label
        (when (null (nth 2 cell))
          ;; No context yet.  Quick update.
          (setcdr cell (cdr (reftex-label-info-update cell)))
          (put docstruct-symbol 'modified t))

        (setq label   (car cell)
              typekey (nth 1 cell)
              text    (nth 2 cell)
              comment (nth 4 cell)
              note    (nth 5 cell))

        (when (and labels
                   (or (eq labels t)
                       (string= typekey labels)
                       (string= labels " "))
                   (or show-commented (null comment)))

          ;; Yes we want this one
          (cl-incf cnt)
          (setq prev-inserted cell)
;         (if (eq offset 'attention) (setq offset cell))

          (setq label (concat xr-prefix label))
          (when comment (setq label (concat "% " label)))
          (insert label-indent label)
          (when font
            (setq to (point))
            (put-text-property
             (- (point) (length label)) to
             'font-lock-face (if comment
                       'font-lock-comment-face
                     label-face))
            (goto-char to))

          (insert (if counter (format " (%d) " cnt) "")
                  (if comment " LABEL IS COMMENTED OUT " "")
                  (if (stringp note) (concat "  " note) "")
                  "\n")
          (setq to (point))

          (when context
            (insert context-indent text "\n")
            (setq to (point)))
          (put-text-property from to :data cell)
          (when mouse-face
            (put-text-property from (1- to)
                               'mouse-face mouse-face))
          (goto-char to)))

       ((eq (car cell) 'index)
        ;; index entry
        (when (and index-entries
                   (or (eq t index-entries)
                       (string= index-entries (nth 1 cell))))
          (setq prev-inserted cell)
;         (if (eq offset 'attention) (setq offset cell))
          (setq index-tag (format "<%s>" (nth 1 cell)))
          (and font
               (put-text-property 0 (length index-tag)
                                  'font-lock-face reftex-index-tag-face index-tag))
          (insert label-indent index-tag " " (nth 7 cell))

          (when font
            (setq to (point))
            (put-text-property
             (- (point) (length (nth 7 cell))) to
             'font-lock-face index-face)
            (goto-char to))
          (insert "\n")
          (setq to (point))

          (when context
            (insert context-indent (nth 2 cell) "\n")
            (setq to (point)))
          (put-text-property from to :data cell)
          (when mouse-face
            (put-text-property from (1- to)
                               'mouse-face mouse-face))
          (goto-char to))))

      (if (eq cell here-I-am)
          (setq offset 'attention))
      (if (and prev-inserted (eq offset 'attention))
          (setq offset prev-inserted))
      )

    (when (reftex-refontify)
      ;; we need to fontify the buffer
      (reftex-fontify-select-label-buffer buf))
    (run-hooks 'reftex-display-copied-context-hook)
    offset))