Function: TeX-fold-item

TeX-fold-item is a byte-compiled function defined in tex-fold.el.

Signature

(TeX-fold-item TYPE)

Documentation

Hide the item on which point currently is located.

TYPE specifies the type of item and can be one of the symbols env for environments, macro for macros or math for math macros. Return non-nil if an item was found and folded, nil otherwise.

Source Code

;; Defined in ~/.emacs.d/elpa/auctex-14.1.2/tex-fold.el
(defun TeX-fold-item (type)
  "Hide the item on which point currently is located.
TYPE specifies the type of item and can be one of the symbols
`env' for environments, `macro' for macros or `math' for math
macros.
Return non-nil if an item was found and folded, nil otherwise."
  (if (and (eq type 'env)
           (eq major-mode 'plain-TeX-mode))
      (message
       "Folding of environments is not supported in current mode")
    (let ((item-start (cond ((and (eq type 'env)
                                  (eq major-mode 'ConTeXt-mode))
                             (save-excursion
                               (ConTeXt-find-matching-start) (point)))
                            ((and (eq type 'env)
                                  (eq major-mode 'Texinfo-mode))
                             (save-excursion
                               (Texinfo-find-env-start) (point)))
                            ((eq type 'env)
                             (condition-case nil
                                 (save-excursion
                                   (LaTeX-find-matching-begin) (point))
                               (error nil)))
                            (t
                             (TeX-find-macro-start)))))
      (when item-start
        (let* ((item-name (save-excursion
                            (goto-char item-start)
                            (looking-at
                             (cond ((and (eq type 'env)
                                         (eq major-mode 'ConTeXt-mode))
                                    (concat (regexp-quote TeX-esc)
                                            "start\\([A-Za-z]+\\)"))
                                   ((and (eq type 'env)
                                         (eq major-mode 'Texinfo-mode))
                                    (concat (regexp-quote TeX-esc)
                                            "\\([A-Za-z]+\\)"))
                                   ((eq type 'env)
                                    (concat (regexp-quote TeX-esc)
                                            "begin[ \t]*{"
                                            "\\([A-Za-z*]+\\)}"))
                                   (t
                                    (concat (regexp-quote TeX-esc)
                                            "\\([A-Za-z@*]+\\)"))))
                            (match-string-no-properties 1)))
               (fold-list (cond ((eq type 'env) TeX-fold-env-spec-list-internal)
                                ((eq type 'math)
                                 TeX-fold-math-spec-list-internal)
                                (t TeX-fold-macro-spec-list-internal)))
               fold-item
               (spec-sig?
                (or (catch 'found
                      (while fold-list
                        (setq fold-item (car fold-list))
                        (setq fold-list (cdr fold-list))
                        (when (member item-name (cadr fold-item))
                          (throw 'found (car fold-item)))))
                    ;; Item is not specified.
                    (if TeX-fold-unspec-use-name
                        (concat "[" item-name "]")
                      (if (eq type 'env)
                          TeX-fold-unspec-env-display-string
                        TeX-fold-unspec-macro-display-string))))
               ;; spec-sig? is of the form SPEC or (SPEC . SIG).
               (display-string-spec (if (consp spec-sig?)
                                        (car spec-sig?)
                                      spec-sig?))
               (sig (when (consp spec-sig?)
                      (cdr spec-sig?)))
               (item-end (TeX-fold-item-end item-start type sig))
               (ov (TeX-fold-make-overlay item-start item-end type
                                          display-string-spec)))
          (TeX-fold-hide-item ov))))))