Function: web-mode-imenu-index

web-mode-imenu-index is an interactive and natively compiled function defined in web-mode.el.

Signature

(web-mode-imenu-index)

Documentation

Returns imenu items.

Key Bindings

This command is not in any keymaps.

Source Code

;; Defined in /nix/store/2qgnz1rp30nzfz6w0apx4kdm14if1bbs-emacs-packages-deps/share/emacs/site-lisp/elpa/web-mode-20260831.219/web-mode.el
(defun web-mode-imenu-index ()
  "Returns imenu items."
  (interactive)
  (let (toc-index
        line)
    (save-excursion
      (goto-char (point-min))
      (while (not (eobp))
        (setq line (buffer-substring-no-properties
                    (line-beginning-position)
                    (line-end-position)))
        (let (found
              (i 0)
              item
              regexp
              type
              type-idx
              content
              content-idx
              content-regexp
              close-tag-regexp
              concat-str
              jumpto
              str)
          (while (and (not found ) (< i (length web-mode-imenu-regexp-list)))
            (setq item (nth i web-mode-imenu-regexp-list))
            (setq regexp (nth 0 item))
            (setq type-idx (nth 1 item))
            (setq content-idx (nth 2 item))
            (setq concat-str (nth 3 item))
            (when (not (numberp content-idx))
              (setq content-regexp (nth 2 item)
                    close-tag-regexp (nth 4 item)
                    content-idx nil))

            (when (string-match regexp line)

              (cond
                (content-idx
                 (setq type (match-string type-idx line))
                 (setq content (match-string content-idx line))
                 (setq str (concat type concat-str content))
                 (setq jumpto (line-beginning-position)))
                (t
                 (let (limit)
                   (setq type (match-string type-idx line))
                   (goto-char (line-beginning-position))
                   (save-excursion
                     (setq limit (re-search-forward close-tag-regexp (point-max) t)))

                   (when limit
                     (when (re-search-forward content-regexp limit t)
                       (setq content (match-string 1))
                       (setq str (concat type concat-str content))
                       (setq jumpto (line-beginning-position))
                       )
                     )))
                )
              (when str (setq toc-index
                              (cons (cons str jumpto)
                                    toc-index)
                              )
                    (setq found t))
              )
            (setq i (1+ i))))
        (forward-line)
        (goto-char (line-end-position)) ;; make sure we are at eobp
        ))
    (nreverse toc-index)))