Function: bazel--find-rule-target

bazel--find-rule-target is a natively compiled function defined in bazel.el.

Signature

(bazel--find-rule-target NAME)

Documentation

Find the rule target definition with the given NAME in the current buffer.

The current buffer should visit a BUILD file. If there’s a definition of a rule target with the given NAME, return its location. Otherwise, return nil.

Source Code

;; Defined in /nix/store/ws8pkszjvcad1rgzqw6wja7qxacylfhn-emacs-packages-deps/share/emacs/site-lisp/elpa/bazel-20261002.1510/bazel.el
(defun bazel--find-rule-target (name)
  "Find the rule target definition with the given NAME in the current buffer.
The current buffer should visit a BUILD file.  If there’s a definition
of a rule target with the given NAME, return its location.  Otherwise,
return nil."
  (declare (ftype (function (string) (or integer null))))
  (cl-check-type name string)
  (let ((case-fold-search nil)
        (search-spaces-regexp nil))
    (save-excursion
      (without-restriction
        (goto-char (point-min))
        ;; Heuristic: we search for a “name” attribute as it would show up
        ;; in typical BUILD files.  That’s not 100% correct, but doesn’t
        ;; rely on external processes and should work fine in common cases.
        (cl-block nil
          (while (re-search-forward
                  (rx symbol-start "name" (* blank) ?= (* blank)
                      (group (any ?\" ?')) (group (literal name)) (backref 1))
                  nil t)
            (let ((position (match-beginning 2)))
              (unless (python-syntax-comment-or-string-p)
                (cl-return position)))))))))