chr4 / nginx.vim

Improved nginx vim plugin (incl. syntax highlighting)
449 stars 41 forks source link

`/*` breaks indenting #3

Closed ben-turner closed 1 year ago

ben-turner commented 7 years ago

First off, thank you for publishing this plugin—syntax highlighting is super nice to have.

However, I've had to turn off indenting because of how the plugin deals with /*. I often use patterns like include /etc/nginx/conf.d/*.nginx but it seems that cindent treats this as the start of a multi-line comment and ruins the formatting for the entire file.

Not being much of a vim wizard, I can't find a solution to fix it myself and create a PR so I'm hoping someone else can fix it.

image

chr4 commented 7 years ago

Thanks for your report!

I've tried reproducing your issue by inserting include /etc/nginx/conf.d/*.nginx; into one of my nginx config files, but it worked as expected. Also trying /* at random places hat no effect on the syntax.

Can you double-check whether there are other plugins active, or a special vim configuration on your end? /* comment */ is used in C-style languages, so maybe that's a hint where to look for?

ben-turner commented 7 years ago

I don't immediately see any other plugins that could be causing that but I'll look some more.

I probably should have included this in the initial issue, but I can reproduce the issue like this:

I can confirm that it's cindent treating the /* as a comment because if I add # */ to the end of the "include" line, it seems to fix the problem.

chr4 commented 7 years ago

Thank you for the clarification and the instructions! I could reproduce the problem. This looks indeed like a bug.

I'm currently not aware of fiddeling with /* */ somewhere, but I'll dig into it.

chr4 commented 7 years ago

This is due to the setlocal cindent statement in indent/nginx.vim.

chr4 commented 7 years ago

A fast solution would be to drop cindent in favor of smartindent. This solves your problem, but I'd apprechiate feedback whether this actually messes other indention up:

indent/nginx.vim

setlocal smartindent " instead of setlocal cindent
ben-turner commented 7 years ago

cindent definitely messes with comments. It might be possible to use cinoptions c or C setting to fix this.

cN Indent comment lines after the comment opener, when there is no other text with which to align, N characters from the comment opener. (default 3). See also |format-comments|.

cino=                    cino=c5
  /*                       /*
     text.                      text.
  */                       */

CN When N is non-zero, indent comment lines by the amount specified with the c flag above even if there is other text behind the comment opener. (default 0).

cino=c0                    cino=c0,C1
  /********                  /********
    text.                    text.
  ********/                  ********/
ben-turner commented 7 years ago

Digging in further, it looks like the comments setting might help. Just trying to find the correct setting now.

chr4 commented 7 years ago

I've actually tried this, but as far as I understood/ tested cino=cN is a relative setting. This results in the following:

#c3 (standard)
test /*
        test

# c0
test /*
     test
ben-turner commented 7 years ago

That's also how I understood it too. I'm thinking if we can :set comments to the right value we should be able to disable that type of comment.

chr4 commented 7 years ago

set comments=b:# and set comments= don't make a difference here. I assume that cindent overrides a lot of formatting-options (I think I saw something like that when skipping through the documentation).

My current guess is to try smartindent, and if that turns out to be not enough, write a custom indentexpr.

Curious whether you have more luck though.

HLFH commented 1 year ago

Fixed by https://github.com/chr4/nginx.vim/pull/20. Can this issue be closed and the PR merged?

Thanks!

chr4 commented 1 year ago

PR merged. Thanks for contributing!