3

I would like emacs to indent my c/c++ code like this:

auto LoopMatcher = forStmt(hasLoopInit(declStmt(hasSingleDecl(varDecl(
    hasInitializer(integerLiteral(equals(0)))))))).bind("forLoop");

(code taken from clang's AST matcher tutorial).

In other words, I want emacs to indent by the default offset after one or more open parentheses.

yorel
  • 177
  • 8

1 Answers1

2

Here you have a solution for that:

(defun custom-indent (langelem)
  (save-excursion
    (goto-char (cdr langelem))
    (vector (+ (current-column) c-basic-offset))))

(c-add-style "custom" '((c-offsets-alist . ((arglist-intro . custom-indent)))))

(c-set-style "custom")
juanleon
  • 9,220
  • 30
  • 41
  • Thanks a lot, that does the trick. Doh, I'd vote your answer up but I don't have enough reputation... – yorel May 19 '14 at 19:34
  • @user2285932 You could start by [accepting](https://stackoverflow.com/help/accepted-answer) the answer... – itsjeyd May 19 '14 at 21:06
  • Oooh...the tick that becomes green when you click it? Took me some time to realize what that does :-| – yorel May 20 '14 at 22:06