1

I am trying to get electric indent behaviour in bazel BUILD files. These are essentially python files, although the structure is extremely simple.

Let me give you an example:

cc_binary(
    name = "hello-world",
    srcs = ["hello-world.cc"],
    deps = [
        ":hello-greet",
        "//lib:hello-time",
    ],
)

What I want is to have electric indentation behaviour for "]" and ")".

What I have tried is:

  • to add these characters to electric-indent-chars
  • to add electric-indent-post-self-insert-function to post-self-insert-hook

Neither of these steps seems to change the behaviour of the characters. What am I doing wrong?

Realraptor
  • 1,253
  • 6
  • 17

2 Answers2

1

If your major mode derives from python-mode, than you likely need to make it

(setq-local electric-indent-inhibit nil)

As for why it's non-nil: python-mode sets this vars to a non-nil value because electric-indent is usually undesirable when indentation is syntactically significant (as in Python).

Stefan
  • 26,154
  • 3
  • 46
  • 84
0

The solution is slightly more complicated than Stefan's answer, so it might be worth recording the details.

(defun rr-enable-electric-indent ()
  (setq-local electric-indent-inhibit nil)
  (add-to-list 'electric-indent-chars ?\))
  (add-to-list 'electric-indent-chars ?\]))

(add-hook 'python-mode-hook 'rr-enable-electric-indent)
Realraptor
  • 1,253
  • 6
  • 17