2

I've got a small problem to do with Doom Emacs / Emacs. Enum contents are not indented at all...

Here's what I would like:

enum class RandomEnum
{
    A,
    B,
    C,
    D
};

Here's what I get:

enum class RandomEnum
{
A,
B,
C,
D
};

How can I go about fixing this? I'm sure that there a simple option I can put in my config? Thank you in advance.

1
  • 1
    Sorry, this isn't enough information to go off. Which major mode is this in? Can you reproduce the issue from emacs -Q? If not, can you recursively bisect your configuration to determine the source of the behaviour? Etc. If you discover a bug in a built-in mode, please report it to the Emacs bug tracker via M-x report-emacs-bug RET; if it's a bug in a third-party package, report it to their bug tracker / maintainer.
    – Basil
    Commented Dec 9, 2020 at 21:21

1 Answer 1

1

Emacs comes with some preconfigured C/C++ Styles.
You can change the indentation style of the current buffer with C-c .

When you have chosen a style and only want to temporary/test adjust a few offsets C-c C-o helps. Emacs indentation styles can be modified very fine grained.

You can also set a default style by changing the alist c-default-style


Given the above information, the elisp code following will set the indentation style "stroustrup" as default style for c++ source code. Then it modifies this style to give the indentation for your example:

(defun change-c-style (c-style-name option-section add-options)
  "function to easily change a predefined indentation style."
  (let ((tmp (assoc option-section (assoc c-style-name c-style-alist))))
    (when tmp
      (setf (cdr tmp) (append (cdr tmp) add-options))))  )

(require 'cc-mode) ;; load up c++-mode environment
(push '(c++-mode . "stroustrup") c-default-style) ;; make "stroustrup" the default style for c++ files
(change-c-style "stroustrup" 'c-offsets-alist '((brace-list-open . 0) (brace-list-intro . ++))) ;; modify the "stroustrup" style with above defined function

Evaling above elisp code and then opening a c++-file will give you the wanted indentation by pressing tab

Above code is meant as a working example, because your question did not deliver enough information about your current environment.

1
  • Thank you very much! This worked very nicely!
    – Krys
    Commented Dec 10, 2020 at 17:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.