octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: astyle configuration


From: Kai Torben Ohlhus
Subject: Re: astyle configuration
Date: Tue, 14 Jan 2020 14:15:03 +0900
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.3.0

On 1/14/20 7:28 AM, Rik wrote:
> On 01/13/2020 01:37 PM, Gene Harvey wrote:
>>
>> Would it be a good idea to use clang-format instead? It has a more
>> configuration options and it's more robust for handling edge cases
>> (it uses clang's lexer).
>>
>> Unfortunately, I haven't been able to emulate Octave's style
>> perfectly with it.
>>
>> [...]
>>
>> However, other than that I've come decently close to emulating the
>> style.


@Gene: can you post your clang-format options as well for comparing the
results easier?


On 1/14/20 7:28 AM, Rik wrote:
> My current astylerc is
>
> --style=gnu
> --indent=spaces=2
> --max-code-length=80
> --min-conditional-indent=1
> --indent-cases
> --indent-labels
> --indent-namespaces
> ##--indent-preproc-block
> ##--indent-preproc-cond
> ##--indent-preproc-define
> --pad-header
> --pad-comma
> --align-pointer=name
> --align-reference=type
> --attach-closing-while
> --close-templates              # now that C++11 is required
> --keep-one-line-blocks
> --keep-one-line-statements
>

@Rik with your current astyle settings, I still get 758 of 1253
formattings and started using a script adding "--suffix=none" to avoid
astyle to create backups

```sh
#!/bin/sh

ASTYLE_OPTS=" \
  --suffix=none \
  --style=gnu \
  --indent=spaces=2 \
  --max-code-length=80 \
  --min-conditional-indent=1 \
  --indent-cases \
  --indent-labels \
  --indent-namespaces \
  --pad-header \
  --pad-comma \
  --align-pointer=name \
  --align-reference=type \
  --attach-closing-while \
  --close-templates \
  --keep-one-line-blocks \
  --keep-one-line-statements"

find . \
  -type d \( -path ./.hg -o -path ./gnulib -o -path ./libgnu \) -prune
-false \
  -o -type f -name "*.h" -or -name "*.c" -or -name "*.cc" \
  | xargs astyle ${ASTYLE_OPTS} > astyle.txt

cat astyle.txt | wc -l
cat astyle.txt | grep "Formatted" | wc -l
```

to call directly inside the Octave development repository, excluding
some irrelevant directories.  To undo the mess, run

  hg revert --no-backup --all



On 1/14/20 7:28 AM, Rik wrote:
> The only reason, for me, to incur the switching costs would be
> if clang-format handled the alignment of tertiary operators in
> a better manner.  An example is
>
> octave_value retval = (! some_variable.isempty ()) ? true
>                                                    : false;
>
> astyle wants to pull the second line beginning with a colon back
> towards column 1 rather than leaving it aligned under the '?'
> character.
>

I think we should in general change to this layout in such cases:

  octave_value retval = (! some_variable.isempty ())
                        ? true
                        : false;

Then astyle also does not break anything with your configuration and for
me it is even more clearer, where to look for the condition?true:false
parts of that operator.

clang-format offers BreakBeforeTernaryOperators [1] but first want to
have a more complete configuration by Gene before experimenting too much.

Kai


[1] https://clang.llvm.org/docs/ClangFormatStyleOptions.html









reply via email to

[Prev in Thread] Current Thread [Next in Thread]