2072 / PHP-Indenting-for-VIm

The official VIm indent script for PHP
http://www.2072productions.com/to/phpindent.txt
128 stars 29 forks source link

Indentation of the curly braces not working after setting hi PhpParent #52

Closed marekkon closed 6 years ago

marekkon commented 8 years ago

I get:

public function zero()
{
    }
2072 commented 8 years ago

what syntax script are you using and how do you set this option?

marekkon commented 8 years ago

I forgot to mention that I use neovim. I use the default syntax, but also tried it with 'StanAngeloff/php.vim'. Highlight is set in local colorscheme (nvim/colors). Directly setting this in init.vim gives the same effect.

2072 commented 7 years ago

Can you provide complete phpParent highlight example please?

marekkon commented 7 years ago

Currently it is

hi link    PhpParent      Normal

but earlier it was (same effect)

hi link    PhpParent      guifg=#999b9e

After some additional tests it turned out that any use of the PhpParent causes malfunction. E.g. if I comment out PhpParent highlight but leave something like this:

hi link    jsonBraces      PhpParent

then indentation doesn't work either.

2072 commented 7 years ago

I'm sorry but I'm still unable to reproduce this issue. I was using GVim8.0.69, I've just compiled the latest 8.0.514 and I still can't reproduce the issue.

You're probably experiencing a bug from your version of vim.

The indent script relies on the syntax name attribute to decide if the element needs indentation or not.

Put your cursor on a brace and run the following command:

:echo synIDattr(synID(line("."), col("."), 0), "name")

it should write phpParent. The indent script ignores almost everything that doesn't start with 'php'.

marekkon commented 7 years ago

PhpParent it is.

jamessan commented 7 years ago

Vim doesn't care about the case of the highlight groups. It considers phpParent the same as PhpParent. This means that if the user defines PhpParent before the syntax script defines phpParent, the synID information will report PhpParent.

The indent script probably should remove case-sensitive requirement for the matches.

    if synname == "Delimiter" || synname == "phpRegionDelimiter" || synname =~# "^phpParent" || synname == "phpArrayParens" || synname =~# '^php\%(Block\|Brace\)' || synname == "javaScriptBraces" || synname =~# '^php\%(Doc\)\?Comment' && b:UserIsTypingComment
marekkon commented 7 years ago

Wow, so simple fix after all this time. Thanks.

2072 commented 7 years ago

@marekkon: I never noticed the uppercase P of PhpParent in your comments...

marekkon commented 7 years ago

I would never think that it matters, especially since the rest of the highlight groups start with uppercase letters and they don't cause problems.