you need to use inclass
to set the indenting of functions & members inside the class.
But this will lead to situation that functions & members in the struct
will be indented by 2 tabs, instead of one, so we need to have a special function to set correct indentation width. I'm using following config to achieve this (I've got the snippet from somewhere in the internet, maybe from emacswiki)...
Getting emacs's access-label indentation to add an indentation level
-
19-10-2022 - |
Вопрос
I was looking at this question and realized I had a similar concern that is not thoroughly answered there.
I want access specifiers to add a level of indentation. On this and this page, I found that the syntactic symbol I need to indent is access-label. Thus, I need to use (c-set-offset 'access-label '0)
.
However, this only indents the line containing the access label and not anything that comes after. What I get is this,
class foo {
public:
void someFunc(); // Doesn't take the indentation of the access label into account
...
};
What I want is,
class foo {
public:
void someFunc();
...
};
How would I do this? Is there some other variable I'm suppose to modify?
Решение
Другие советы
If you use the braces on new line, the workaround above is not completely correct; you must check if after first goto you are before an open brace. This is my more generale workaround:
(defun agb/c++-mode-hook ()
(c-set-offset 'access-label '-)
(c-set-offset 'topmost-intro '0)
(c-set-offset 'inclass '(lambda (arg)
(let ((inclass (assoc 'inclass c-syntactic-context)))
(save-excursion
(goto-char (c-langelem-pos inclass))
(if (looking-at "{")
(goto-char (c-langelem-pos (assoc 'class-open (c-guess-basic-syntax)))))
(if (or (looking-at "struct")
(looking-at "typedef struct"))
'+
'++))))))
Не связан с StackOverflow