1

Protocol-Buffers mode binds c-indent-line-or-region to the TAB key. Since one of my projects uses 4 spaces for .proto file indentation, I've tried customizing indent-tabs-mode to nil, and tab-width and c-basic-offset both to 4. However, pressing TAB will re-indent lines using 2 spaces.

How can I make it do what I need?


Edit: the Commentary for protobuf-mode says:

;; You can customize this mode just like any mode derived from CC Mode.  If
;; you want to add customizations specific to protobuf-mode, you can use the
;; `protobuf-mode-hook'. For example, the following would make protocol-mode
;; use 2-space indentation:
;;
;;   (defconst my-protobuf-style
;;     '((c-basic-offset . 2)
;;       (indent-tabs-mode . nil)))

I have used customize-variable to set c-basic-offset and tab-width to 4.

Esteban
  • 111
  • 2

1 Answers1

0

Assuming you're referring to protobuf-mode in MELPA, there is config documentation in its Commentary.

Use either of:

  • M-x find-library RET protobuf-mode RET
  • M-x finder-commentary RET protobuf-mode RET
phils
  • 48,657
  • 3
  • 76
  • 115
  • Even though I've been using spacemacs for years, I'm still pretty much a noob. However, I find my expectation of consistent config interfaces across modes (about simple, universal things such as indentation) completely reasonable. Yet other emacs users don't seem distraught by the fact that you need to find and read docs over and over again to solve the same problem—just in a different mode. Come to think about it, emacs may just not be the editor for me. – Esteban Aug 31 '22 at 20:11
  • I've added the Commentary to my question. Apparently, the selected "style" was to blame since selecting `cc-mode` fixed it. I still don't know what I'm doing but I'll try to read up on styles. – Esteban Aug 31 '22 at 20:21
  • The various complexities of and requirements for indentation across the vast breadth of things supported by Emacs are far from "universal", and so consequently the topic isn't very "simple" either. In the end, any given mode is free to implement it however it wants to (or needs to). In practice there are some common conventions, but it's true that checking the docs is often necessary. – phils Aug 31 '22 at 22:22
  • The manual at `C-h i g (ccmode)` has sections on "styles" and on the indentation system used by major modes based on cc-mode. – phils Sep 01 '22 at 01:01
  • I'll note that some other editors will get away with making indentation simpler because they expect the user to indent things manually. Emacs has a general philosophy of automated indentation, such that you can ask it to indent an entire region (or file) for you, and in order to be able to do that correctly for any given definition of "correct", configuration can become complex. The styles system in ccmode is a way of codifying sets of "correct" rules. – phils Sep 01 '22 at 01:06