Function: bazel-mode-create-index
bazel-mode-create-index is a natively compiled function defined in
bazel.el.
Signature
(bazel-mode-create-index)
Documentation
Return an Imenu index for the rule targets defined in the current buffer.
This function is useful as ‘imenu-create-index-function’ for
‘bazel-build-mode’, ‘bazel-workspace-mode’, and
‘bazel-module-mode’. See Info node (elisp) Imenu for details.
Source Code
;; Defined in /nix/store/ws8pkszjvcad1rgzqw6wja7qxacylfhn-emacs-packages-deps/share/emacs/site-lisp/elpa/bazel-20261002.1510/bazel.el
;;;; Imenu support
(defun bazel-mode-create-index ()
"Return an Imenu index for the rule targets defined in the current buffer.
This function is useful as ‘imenu-create-index-function’ for
‘bazel-build-mode’, ‘bazel-workspace-mode’, and
‘bazel-module-mode’. See Info node ‘(elisp) Imenu’ for details."
(declare (ftype (function () list)))
(save-excursion
(without-restriction
(goto-char (point-min))
(let ((case-fold-search nil)
(search-spaces-regexp nil)
(index ()))
;; Heuristic: We search for “name” attributes as they would show in
;; typical BUILD files. That’s not 100% correct, but doesn’t rely on
;; external processes and should work fine in common cases.
(while (re-search-forward
;; The target pattern isn’t the same as
;; https://bazel.build/concepts/labels#target-names (we don’t
;; allow quotation marks in target names), but should be good
;; enough here.
(rx symbol-start "name" (* blank) ?= (* blank)
(group (any ?\" ?'))
(group (+ (any "a-z" "A-Z" "0-9"
?- "!%@^_` #$&()*+,;<=>?[]{|}~/.")))
(backref 1))
nil t)
(let ((name (match-string-no-properties 2)))
(unless (python-syntax-comment-or-string-p)
(let ((pos (save-excursion
(python-nav-beginning-of-statement)
(if imenu-use-markers (point-marker) (point)))))
(push (cons name pos) index)))))
(nreverse index)))))