Emacs C++-Mode Incorrect Indentation

How do I make emacs treat #ifdef and #endif like '{' and '}'?

You can use this el file for emacs :
http://www.emacswiki.org/emacs/ppindent.el

You can find many info about emacs indentation here : http://www.emacswiki.org/emacs/IndentingC

vim: C indent braces at the same level as case

cino+={-1s

instead of

cino+={0

works. Basically, the default is 0s which places it indented in. -1s places the braces as desired.

Haskell where indentation: why must it be indented past identifier?

Basically, Haskell notes the column where the first non-space character after where appears (in this case, the c of convert) and treats following lines beginning in that column as new definitions inside the where.

A line that continues the definition of the previous line (such as your | guards) must be indented to the right of the first non-space character (c in your code).

A line indented to the left of c would be outside the where (for example, the start of your next top-level function).

It's the column of the first character following where that is crucial, even if it's on a new line:

  where
convert acc x
| ...
anotherFunction x y

^

C Comment in Emacs - Linux Kernel Style

Try with:

(setq comment-style 'extra-line)

clang-format: indentation of macros

  • Bad news: Sorry, this is not available in the current release version of clang-format(7).
  • Good news: There is a StatementMacros option, which is available since clang-format 8(not release yet, but you can build from source).

See this commit:

Summary:
Some macros are used in the body of function, and actually contain the trailing semicolon: they should thus be automatically followed by a new line, and not get merged with the next line. This is for example the case with Qt's Q_UNUSED macro:

  void foo(int a, int b) {
Q_UNUSED(a)
return b;
}

This patch deals with these cases by introducing a new option to specify list of statement macros. This re-uses the system already in place for foreach macros, to ensure there is no impact on performance.

Document:

◆ StatementMacros

std::vector clang::format::FormatStyle::StatementMacros
A vector of macros that should be interpreted as complete statements.

Typical macros are expressions, and require a semi-colon to be added; sometimes this is not the case, and this allows to make clang-format aware of such cases.

For example: Q_UNUSED

Definition at line 1061 of file Format.h.

Referenced by clang::format::FormatTokenLexer::FormatTokenLexer(), clang::format::getLLVMStyle(), llvm::yaml::MappingTraits< FormatStyle >::mapping(), and operator==().

Solution:

build clang from source/wait for llvm/clang8 release, then
put StatementMacros ['QUERY_BEGIN()', 'QUERY_NORESULT()', 'QUERY_END()'] into your .clang-format.

Workaround for old clang-format

// clang-format off
void unformatted_code ;
// clang-format on

Turn off clang-format in this macro statements.



Related Topics



Leave a reply



Submit