Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev indent align braces #13

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Dev indent align braces #13

wants to merge 11 commits into from

Conversation

pboettch
Copy link
Owner

No description provided.

@pboettch
Copy link
Owner Author

@blueyed I made my hands dirty on the indent file. This version seems to work, except for when using bracket-comments. Please give it a try and tell me what you think and why not adding more test-cases.

@pboettch pboettch force-pushed the dev-indent-align-braces branch from 2661397 to d501b0e Compare July 17, 2019 15:00
README.md Outdated
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
```

By setting `g:cmake_indent_no_command_argument_align` to 1 in your vimrc-file the old behavior is activated:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might be a good default - resulting in fewer changes in diffs (when the command/function changes). OTOH that's also not so common in CMake I guess.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defaulting to 1 you mean?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.
That seems to be the current behavior also, right?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, though it doesn't work correctly in all cases. Will be defaulted to 1 (or the variable name will change).

@blueyed
Copy link

blueyed commented Jul 17, 2019

@pboettch
Awesome. Will start to test drive this.

Some remark (which might not really apply): it is possible to also use syntax highlight / hl groups, so that e.g. comments can be skipped etc (see https://github.com/Vimjas/vim-python-pep8-indent/blob/master/indent/python.vim).

@pboettch
Copy link
Owner Author

What do you mean by getting comments skipped? Should comments always be aligned to the zero-column for you?

@blueyed
Copy link

blueyed commented Jul 18, 2019

I've meant that syntax can be used in expressions with searchpairpos for example.
It does not seem to be necessary really since there are only line comments (easier to handle/check).
But it should ignore any opening parenthesis in a comment.

@pboettch
Copy link
Owner Author

Cmake has sectional comments as well (#[[ ]]), see #14 .

Parens in comments can be a problem. I'll check whether it works or not.

@pboettch
Copy link
Owner Author

It seems to work, unless aligned comments are unwanted:

add_custom_command(tout # )
                   #add_custom_command(
                   hallo
                   )

@pboettch
Copy link
Owner Author

I added an option for users to select whether they want comment to be aligned a 0.

Also I tested parens in line-comments to see whether it breaks. It seems not to.

I'll merge this branch to master soon. Thanks for your initial work and thus making me learn vim-indent.

@blueyed
Copy link

blueyed commented Jul 24, 2019

With this commit it does not indent the endif correctly anymore:

Thanks for the quick fix! :)

@pboettch
Copy link
Owner Author

Thanks for finding.

@blueyed
Copy link

blueyed commented Jul 24, 2019

It does not handle the following (multiline string):

message(STATUS "foo
  bar")
  set(foo 1)
  1. set() should get no indent (with o after the second line, or == on the line itself
  2. the second line's indent should be kept as-is

That's a problem on master though already.

@pboettch
Copy link
Owner Author

pboettch commented Jul 24, 2019

Hard to solve this one. I basically didn't change the regexes which were already there. But they would need to be fixed in order to have something respecting multiline strings and intra-line-comments.

Resulting in a complete parser of the CMake-language.

@pboettch
Copy link
Owner Author

Actually it's not that bad. The while-you-type indent fails, but when re-indenting the whole block I get:

if(HALLO)
    message(STATUS "foo
    bar")
    set(foo)
    set(foo 1)
endif()

@blueyed
Copy link

blueyed commented Jul 24, 2019

It messes with the initial indent of the existing multiline string however:

if(HALLO)
    message(STATUS "foo
  bar")
    set(foo)
    set(foo 1)
endif()

This sounds like a good case where using the actual syntax would be useful: i.e. the line with the multiline comment has types "cmakeString cmakeArguments" - and lines starting with "cmakeString" could be left as-is. Ref: https://github.com/Vimjas/vim-python-pep8-indent/blob/dac91047444e5c907226b1cae39bb3ce428bc441/indent/python.vim#L112-L133

Resulting in a complete parser of the CMake-language.

That is kind of what the syntax provides already luckily.. :)

@pboettch pboettch force-pushed the dev-indent-align-braces branch from aed30e1 to 7edeedb Compare January 29, 2020 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants