Function: bazel-mode
bazel-mode is an interactive and natively compiled function defined in
bazel.el.
Signature
(bazel-mode)
Documentation
Major mode for editing Bazel files with Starlark-like syntax.
This is the parent mode for the more specific modes
‘bazel-build-mode’, ‘bazel-workspace-mode’, ‘bazel-module-mode’,
‘bazel-repo-mode’, ‘bazel-vendor-mode’, and ‘bazel-starlark-mode’.
In addition to any hooks its parent mode prog-mode might have run,
this mode runs the hook bazel-mode-hook, as the final or penultimate
step during initialization.
C-c C-b bazel-build
C-c C-c bazel-coverage
C-c C-f bazel-buildifier
C-c C-r bazel-run
C-c C-t bazel-test
Key Bindings
This command is not in any keymaps.
Source Code
;; Defined in /nix/store/ws8pkszjvcad1rgzqw6wja7qxacylfhn-emacs-packages-deps/share/emacs/site-lisp/elpa/bazel-20261002.1510/bazel.el
(define-derived-mode bazel-mode prog-mode "Bazel"
"Major mode for editing Bazel files with Starlark-like syntax.
This is the parent mode for the more specific modes
‘bazel-build-mode’, ‘bazel-workspace-mode’, ‘bazel-module-mode’,
‘bazel-repo-mode’, ‘bazel-vendor-mode’, and ‘bazel-starlark-mode’."
;; Almost all Starlark code in existence uses 4 spaces for indentation.
;; Buildifier also enforces this style.
(setq-local tab-width 4)
(setq-local python-indent-offset 4)
(setq-local python-indent-guess-indent-offset nil)
(setq-local indent-tabs-mode nil)
;; Take over some syntactic constructs from ‘python-mode’.
(setq-local comment-start "# ")
(setq-local comment-start-skip (rx (+ ?#) (* (syntax whitespace))))
(setq-local comment-end "")
(setq-local comment-use-syntax t)
(setq-local parse-sexp-ignore-comments t)
(setq-local forward-sexp-function #'python-nav-forward-sexp)
(setq-local font-lock-defaults '((bazel-font-lock-keywords
bazel-font-lock-keywords-1
bazel-font-lock-keywords-2
bazel-font-lock-keywords-3)))
(setq-local syntax-propertize-function python-syntax-propertize-function)
(setq-local indent-line-function #'python-indent-line-function)
(setq-local indent-region-function #'python-indent-region)
(setq-local electric-indent-inhibit t)
(setq-local prettify-symbols-alist python-prettify-symbols-alist)
;; Adapt some Python indentation style variables for Bazel.
(setq-local python-indent-def-block-scale 1)
;; Treat magic comments as being separate paragraphs for filling.
(setq-local paragraph-start
(rx (or (seq (* (syntax whitespace)) (regexp comment-start-skip)
(regexp bazel--magic-comment-regexp))
(regexp paragraph-start))))
(setq-local fill-paragraph-function #'python-fill-paragraph)
(setq-local normal-auto-fill-function #'python-do-auto-fill)
(add-hook 'before-save-hook #'bazel--buildifier-before-save-hook nil :local)
(add-hook 'flymake-diagnostic-functions #'bazel-mode-flymake nil :local)
(add-hook 'xref-backend-functions #'bazel-mode-xref-backend nil :local)
(add-hook 'completion-at-point-functions #'bazel-completion-at-point
nil :local)
(when-let* ((filename buffer-file-name))
;; Initialize filename cache.
(bazel--repository-relative-name filename))
nil)