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

[RDY] hl-Syntax should override cursorline and cursorcolumn #6380

Closed
wants to merge 1 commit into from

Conversation

zhou13
Copy link
Contributor

@zhou13 zhou13 commented Mar 28, 2017

This patch makes syntax highlight correctly overrides 'cursorline' and 'cursorcolumn'

Before this patch (default json syntax highlights every comment as error):

2017-03-27_18 53 53_826x446
2017-03-27_18 53 46_826x446

After this patch:
2017-03-27_18 47 36_826x446
2017-03-27_18 47 35_826x446

While nvim -d or "folding" is not affected (This may be good but I don't know exactly why):
2017-03-27_18 55 55_826x446

@tweekmonster
Copy link
Contributor

Does this also preserve the text color for concealed characters when set list is enabled? If so, this gets a big 👍 from me. I have a feeling that some tests are going to fail because of this, though.

@zhou13
Copy link
Contributor Author

zhou13 commented Mar 28, 2017

I don't quite understand your concern since it involves "conceal", "list", "cursorline". Could you give me an example?

@tweekmonster
Copy link
Contributor

Oh I feel dumb now. You fixed it in #4744. I disabled CursorLine highlighting a long time ago because of how annoying it was and forgot about it. This PR reminded me of the old issue. It never crossed my mind that it was already fixed. 😭 🎉

@justinmk
Copy link
Member

Just tried this PR (9bc7715). It regresses e.g. the DiffChange highlight. I have this:

hi DiffChange      guifg=white   guibg=#4C4745 ctermfg=255 ctermbg=239 gui=NONE cterm=NONE

But the changed diff lines don't show white foreground anymore.

@zhou13
Copy link
Contributor Author

zhou13 commented Mar 29, 2017

This is intended. Do you think DiffChange should override syntax? To fix it, we just need to change HLF_CHD from line_attr to line_attr_prior.

@justinmk
Copy link
Member

justinmk commented Mar 30, 2017

Do you think DiffChange should override syntax?

There wouldn't be any purpose to DiffChange if it gets overridden. If colorscheme or user wants DiffChange foreground color to be "overridden", they can do that by not specifying ctermfg/guifg:

:hi clear DiffChange
:hi DiffChange ctermbg=... guibg=...

If we take that away we've lost flexibility. We don't want to do that for any case where it's already controllable. (So if there are any other cases of this, same principle applies)

@zhou13
Copy link
Contributor Author

zhou13 commented Mar 30, 2017

There wouldn't be any purpose to DiffChange if it gets overridden. If colorscheme or user wants DiffChange foreground color to be "overridden", they can do that by not specifying ctermfg/guifg:

Yes. I have already restored the old behavior of Diff*.

@justinmk justinmk added this to the 0.2.1 milestone Mar 30, 2017
@zhou13 zhou13 force-pushed the cursorline-priority branch 5 times, most recently from e5aafd8 to ecd74d4 Compare March 31, 2017 06:31
@zhou13
Copy link
Contributor Author

zhou13 commented Mar 31, 2017

Just did a refactor so that it maintains old nvim -d behavior better.

@zhou13 zhou13 changed the title [RFC] everything should override cursorline and cursorcolumn [RFC] hl-Syntax should override cursorline and cursorcolumn Mar 31, 2017
@zhou13 zhou13 force-pushed the cursorline-priority branch 3 times, most recently from 7ece468 to 5ae213c Compare March 31, 2017 08:34
@zhou13
Copy link
Contributor Author

zhou13 commented May 23, 2017

Is this patch ready to go?

@zhou13 zhou13 changed the title [RFC] hl-Syntax should override cursorline and cursorcolumn [RDY] hl-Syntax should override cursorline and cursorcolumn Sep 28, 2017
@zhou13
Copy link
Contributor Author

zhou13 commented Sep 28, 2017

@justinmk I fixed some merge conflicts. Is there anything prevent this from being merged?

&& !(wp == curwin && VIsual_active)) {
if (line_attr != 0 && !(State & INSERT) && bt_quickfix(wp->w_buffer)
&& qf_current_entry(wp) == lnum) {
line_attr = hl_combine_attr(win_hl_attr(wp, HLF_CUL), line_attr);
Copy link
Member

Choose a reason for hiding this comment

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

Why isn't this branch needed anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The old one basically says if we are in quickfix window, then we use HLF_CUL to complement current line_attr, otherwise it will directly set line_attr to HLF_CUL. Setting line_attr to HLF_CUL is not what we want, since it incorrectly override some highlights under some condition (the logic is complex here)....

In this patch, I split line_attr into line_attr and line_attr_low_priority. Now line_attr_low_priority only takes care of cursorline, and it will be merged into char_attr with lowest priority. For other line_attr, it will still use the old logic. Since line_attr_low_priority already has lowest priority, I believe these lines are not necessary.

} else if (draw_color_col && VCOL_HLC == *color_cols) {
vcol_save_attr = char_attr;
char_attr = hl_combine_attr(char_attr, win_hl_attr(wp, HLF_MC));
char_attr = hl_combine_attr(win_hl_attr(wp, HLF_MC), char_attr);
Copy link
Member

Choose a reason for hiding this comment

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

This could be a separate change, right? And it's much lower-risk than the line_attr_low_priority change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. They can fix the problem for cursorcolumn and colorcolumn.

@justinmk
Copy link
Member

justinmk commented Sep 29, 2017

Looking at this again, this adds numerous decisions that appear fragile and difficult to follow.

  • A new line_attr_low_priority variable is introduced which is "like line_attr but different".
  • Several checks are added in various places, spread over 1500 lines of code.

Is there any way to avoid this? Can we make a smaller improvement with a much smaller code change?

@zhou13
Copy link
Contributor Author

zhou13 commented Sep 29, 2017

@justinmk I will say this is unlikely. The old vim uses line_attr for a bunch of things that should be treated differently. For example, you mentioned that DiffChange should override syntax highlight, while cursorline should not. I think they need to be split.

Also most changes to checks are minor: just replace line_attr with line_attr | line_attr_low_priority. This pull request only adds one line of code in total...

@justinmk
Copy link
Member

justinmk commented Oct 7, 2017

Merged in #7364

@zhou13 I have to admit the current cursorline behavior for diff-mode is very annoying. I wonder if it makes sense to have cursorline override only the NonText part?

@justinmk justinmk closed this Oct 7, 2017
@justinmk justinmk added syntax regex syntax or non-regex parsing, lpeg, grammars and removed RDY labels Oct 7, 2017
justinmk added a commit to justinmk/neovim that referenced this pull request Oct 7, 2017
justinmk added a commit to justinmk/neovim that referenced this pull request Oct 7, 2017
justinmk added a commit to justinmk/neovim that referenced this pull request Oct 7, 2017
@zhou13
Copy link
Contributor Author

zhou13 commented Oct 7, 2017

Could you upload a screenshot to describe your problem?

@justinmk
Copy link
Member

justinmk commented Oct 7, 2017

@zhou13 sorry to confuse, I was referring to the existing behavior, i.e., the behavior I requested we preserve. Nothing changed by this PR.

I think ignoring 'cursorline' for diff highlights completely is probably too much, but if we could enable the 'cursorline' highlight only for non-text, that might be interesting. Not sure. Just a thought for the future.

@justinmk
Copy link
Member

justinmk commented Oct 8, 2017

@zhou13 If you get a chance, it would be valuable to have some test coverage for these changes. I think there's no coverage of 'cursorcolumn' nor 'colorcolumn', and only indirect coverage of 'cursorline'.

@zhou13
Copy link
Contributor Author

zhou13 commented Oct 8, 2017 via email

@justinmk
Copy link
Member

For reference: this PR was partially reverted, tentative future plan is described in #7383 (comment)

justinmk added a commit to justinmk/neovim that referenced this pull request Oct 15, 2017
justinmk added a commit that referenced this pull request Oct 16, 2017
zhou13 added a commit to zhou13/neovim that referenced this pull request Jun 18, 2018
justinmk added a commit to justinmk/neovim that referenced this pull request Sep 21, 2018
justinmk added a commit to justinmk/neovim that referenced this pull request Oct 31, 2018
justinmk added a commit to justinmk/neovim that referenced this pull request Nov 26, 2018
justinmk added a commit to justinmk/neovim that referenced this pull request Nov 26, 2018
justinmk added a commit to justinmk/neovim that referenced this pull request Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
syntax regex syntax or non-regex parsing, lpeg, grammars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants