6

Basically the indent style I'd like to obtain is the one described as 'Lisp style' on Wikipedia:

while (x == y) {
    something();
    somethingelse(); }

I'm using a custom .clang-format file (version 3.8) but I couldn't find any option suited for my need.

Thanks in advance.

mmj
  • 5,514
  • 2
  • 44
  • 51
  • 4
    Not an answer to your question (thus a comment) but to each their own; personally I cannot *stand* that format, preferring instead [Allman](https://en.wikipedia.org/wiki/Indent_style#Allman_style) formatting, like most of the rest of humanity. Best of luck though. Interesting, exercise. – WhozCraig Jul 06 '16 at 09:17
  • 1
    @WhozCraig I don't dislike the Allman style, but being used to Python and Lisp parentheses I'm ok with multiple closing braces, and I prefer the vertical compactness and the somewhat Python feel (the first thing I see on a new line is always a keyword). – mmj Jul 06 '16 at 09:53
  • 1
    Just think of a brace as being a keyword. Making C++ look like Python will always be a mistake. – Cody Gray - on strike Jul 06 '16 at 11:35
  • 2
    @CodyGray Call it Python, YAML or whatever, I like meaningful indentation, and after being processed by a formatter, even C++ indentation is undoubedtly meaningful. And since is meaningful, I see no point in seeing closing braces that give me an information I already have. Anyway, above all, *de gustibus non disputandum est*. – mmj Jul 06 '16 at 15:58
  • 1
    Wikipedia sample for lisp style looks gorgeous. Such a shame that clang-format has refused to support it. [coffeepp](https://github.com/jhasse/coffeepp), [CPY](https://github.com/vrsperanza/CPY), and [SugerCPP](https://github.com/curimit/SugarCpp) are a few alternatives to consider. – tejasvi88 Dec 20 '21 at 14:45

1 Answers1

3

The clang-format source code is pretty clean, it's not too difficult to read it or modify it once you get the idea.

Here's a patch I made like a year ago that adds a "break before brace after constructor initialization lists", in clang 3.7. (It didn't get merged after discussion unfortunately, but I kept using it for my own projects anyways.) It's not too much code: https://github.com/cbeck88/clang/commit/e4f65cf7ab3deea9e6c7cdd5900ad0362835e514

Figuring out how to build clang and run the clang unit tests is probably as much work as actually making a patch to do what you are saying.

As I recall, the source code is more based around adding breaks rather than removing them, so depending on exactly how you want to formalize your idea (is this only control structures? For if's? For brace ending a function or class?) it might be tricky. But I still expect you would be able to get it to work.

To my recollection, there are no built-in options to do something close to what you are saying.

Chris Beck
  • 15,614
  • 4
  • 51
  • 87
  • Also, fwiw building clang is not that hard, the only complicated part is how modular it is, how basically there's LLVM which stands alone, then clang which needs that, then the clang-tools as a submodules in that, and so you end up having to orchestrate the different components a little bit. But building gcc was way more difficult, at least for me :p – Chris Beck Jul 06 '16 at 10:36
  • 1
    Thanks for your suggestion, by the way before customizing source code of `clang-format` I think I'd try **Artistic Style** which seems to have a predefined 'Lisp style' option. – mmj Jul 06 '16 at 10:52