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

feat(ui): add 'statuscolumn' option #20621

Merged
merged 1 commit into from
Jan 9, 2023
Merged

Conversation

luukvbaal
Copy link
Contributor

@luukvbaal luukvbaal commented Oct 12, 2022

Problem: Unable to customize the column next to a window ('gutter').
Solution: Add 'statuscolumn' option that follows the 'statusline' syntax, allowing to customize the status column. Also supporting the %@ click execute function label. Adds new items @C and @s which will print the fold and sign columns. Line numbers and signs can be clicked, highlighted, aligned, transformed, margined etc.

Following discussion in #4941 (comment), this was ported/improved from vim/vim#11303, after it was rejected there.
Closes #6092, closes #19805, closes #20035.

A companion plugin to this option providing common number formats and click handlers is available here

@luukvbaal luukvbaal changed the title unable to customize the number column feat(ui): add 'numberformat' option Oct 12, 2022
@max397574
Copy link
Contributor

would it be possible to define a variable or sth so the cursorline number can be treated special?

Copy link
Member

@justinmk justinmk left a comment

Choose a reason for hiding this comment

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

Naming nit: based on existing options, I think 'numbercolumn' might be a more conventional name. That helps discoverability by grouping it with other "column" options.

Some comments from vim users and further consideration swayed me back to a 'statusline' expression approach. We get things like highlighting, alignment, clickable elements(? untested) for free.

That's good info to include in the commit message.

src/nvim/buffer.c Outdated Show resolved Hide resolved
src/nvim/drawline.c Outdated Show resolved Hide resolved
runtime/doc/options.txt Outdated Show resolved Hide resolved
runtime/doc/options.txt Outdated Show resolved Hide resolved
src/nvim/drawscreen.c Outdated Show resolved Hide resolved
src/nvim/statusline.c Outdated Show resolved Hide resolved
src/nvim/statusline.c Outdated Show resolved Hide resolved
src/nvim/statusline.c Outdated Show resolved Hide resolved
src/nvim/drawline.c Outdated Show resolved Hide resolved
src/nvim/statusline.c Outdated Show resolved Hide resolved
@luukvbaal
Copy link
Contributor Author

luukvbaal commented Oct 12, 2022

would it be possible to define a variable or sth so the cursorline number can be treated special?

Not sure it's necessary, can use v:relnum == 0 for this.

@luukvbaal luukvbaal marked this pull request as draft October 12, 2022 18:11
@luukvbaal luukvbaal changed the title feat(ui): add 'numberformat' option feat(ui): add 'numbercolumn' option Oct 13, 2022
@luukvbaal

This comment was marked as outdated.

runtime/doc/options.txt Outdated Show resolved Hide resolved
src/nvim/drawscreen.c Outdated Show resolved Hide resolved
@luukvbaal

This comment was marked as outdated.

@luukvbaal luukvbaal marked this pull request as ready for review October 14, 2022 00:46
src/nvim/statusline.c Outdated Show resolved Hide resolved
@luukvbaal
Copy link
Contributor Author

luukvbaal commented Oct 14, 2022

Ready for another round of review. Points of contention are:

  • Whether or not to provide new 'statusline' expression format items specifically for 'cursorcolumn' by assigning unused letters or overloading existing ones, since most of them appear to be useless in the number column. Even if we do this, we still need to provide v:-vars because stl-items themselves cannot be substituted in the %{} eval block(also an option to allow that for certain items, in that case we might not need the v:-vars?).
  • If we don't add new stl-items, it might be worth to add previously requested use-cases in the :h cursorcolumn docs. How many (if any) are appropriate there?
  • Currently I am setting v:redraw_relnum to -1 if 'relativenumber' is unset. Does this make sense? That way users can check if it is larger than or equal to 0 but we could also always set it to the appropriate value and have users check against &rnu. That way we also have an easy way to check for the cursor line nr if 'relativenumber' is unset. I think that might be better, or even add the boolean @max397574 suggested. Not sure what will result in the most ergonomic 'numbercolumn' strings/functions.

@luukvbaal luukvbaal marked this pull request as draft October 14, 2022 02:09
@luukvbaal

This comment was marked as outdated.

@luukvbaal

This comment was marked as resolved.

@luukvbaal

This comment was marked as outdated.

@luukvbaal luukvbaal force-pushed the numberformat branch 4 times, most recently from a3cdcee to 283f67d Compare October 15, 2022 22:31
@luukvbaal

This comment was marked as outdated.

@luukvbaal

This comment was marked as outdated.

@luukvbaal luukvbaal marked this pull request as ready for review October 16, 2022 01:29
Problem:    Unable to customize the column next to a window ('gutter').
Solution:   Add 'statuscolumn' option that follows the 'statusline' syntax,
	    allowing to customize the status column. Also supporting the %@
	    click execute function label. Adds new items @C and @s which
	    will print the fold and sign columns. Line numbers and signs
	    can be clicked, highlighted, aligned, transformed, margined etc.
@lewis6991 lewis6991 merged commit 364b131 into neovim:master Jan 9, 2023
@hrqmonteiro
Copy link

Since it closed this, could i realy use this to set something between the linenumber and the code as it was asking?

For example, set the GitSigns to be on this space instead of the extreme left of the window (as it were before)?

@luukvbaal
Copy link
Contributor Author

luukvbaal commented Jan 9, 2023

Since it closed this, could i realy use this to set something between the linenumber and the code as it was asking?

Yes, IDK what "something" is but a margin between the line number and the code could be set like this:

:let &statuscolumn='%l   '

For example, set the GitSigns to be on this space instead of the extreme left of the window (as it were before)?

If "something" is supposed to be the signcolumn, a more complete 'statuscolumn' would something like this:

:let &statuscolumn='%C%l%=%s'

Meaning foldcolumn -> line number -> right aligned sign column.

Whether this should close that issue is still debatable I guess.

@hrqmonteiro
Copy link

hrqmonteiro commented Jan 9, 2023

Since it closed this, could i realy use this to set something between the linenumber and the code as it was asking?

Yes, IDK what "something" is but a margin between the line number and the code could be set like this:

:let &statuscolumn='%l   '

For example, set the GitSigns to be on this space instead of the extreme left of the window (as it were before)?

If "something" is supposed to be the signcolumn, a more complete 'statuscolumn' would something like this:

:let &statuscolumn='%C%l%=%s'

Meaning foldcolumn -> line number -> right aligned sign column.

Whether this should close that issue is still debatable I guess.

That kinda did it, actually, wow. I just tried swapping the order and i tried: :let &statuscolumn='%l=%s%C' and i got this:

Screenshot from 2023-01-09 15-38-14

Which is almost like what i wanted, wow. I wanted: line number -> signcolumn -> foldcolumn and it's very close. Just have to get the number to 'sound' right (i mean the spacing and being aligned), and the relative numbers.

Any tips on how to achieve that?

@clason
Copy link
Member

clason commented Jan 9, 2023

Usage questions are better asked on Matrix or your discussion platform of choice.

@neovim neovim locked as resolved and limited conversation to collaborators Jan 9, 2023
@justinmk
Copy link
Member

justinmk commented Jan 9, 2023

@luukvbaal fantastic work!

Where did we land with these items:

  • With the following diff (not resetting the sign pointers in the statuscol structure for non-wrapped lines), Repeat signs across wrapped lines #12866 would be default behavior in this PR.

  • Would providing the option here be sufficient to consider that issue resolved? Or would core still want to keep the issue open to provide it in the regular sign state at some point. Same question for Clickable and customizable sign area  #20447.

Tradeoff being that users that want to disable it require a re-evaluate block in their 'statuscolumn', presumably affecting redraw performance

Seems like a fine tradeoff. Can we close those 2 issues then?

@neovim neovim unlocked this conversation Jan 9, 2023
@neovim neovim unlocked this conversation Jan 16, 2023
HendrikPetertje added a commit to HendrikPetertje/nvim-tree.lua that referenced this pull request Jan 24, 2023
with neovim/neovim#20621 merged in it is now
possible to fully customize the status-column in nvim (the column on the
left containing line-numbers, fold info, signs and borders).

A fair few cool implementations have popped up like:
- https://github.com/CKolkey/config/blob/master/nvim/after/plugin/statuscolumn.lua
- https://github.com/luukvbaal/statuscol.nvim
- and my own personal one (based on CKolkey's fantastic work) https://git.hendrikpeter.net/hendrikpeter/pico-vim/-/blob/main/lua/peva/status_column.lua

The problem with nvim-tree however is that dynamic sizing doesn't take
the custom size of a status column into account and the end of file
names get clipped off. This little patch should fix that (and give some
examples to help other status_column modders get started).

Thanks for looking at this and thanks for making this amazing plugin,
I've been using it for a while and I really like it!
alex-courtis added a commit to nvim-tree/nvim-tree.lua that referenced this pull request Jan 28, 2023
* fix: variable width accounts for sign/number columns

* Add dynamic sizing padding options

with neovim/neovim#20621 merged in it is now
possible to fully customize the status-column in nvim (the column on the
left containing line-numbers, fold info, signs and borders).

A fair few cool implementations have popped up like:
- https://github.com/CKolkey/config/blob/master/nvim/after/plugin/statuscolumn.lua
- https://github.com/luukvbaal/statuscol.nvim
- and my own personal one (based on CKolkey's fantastic work) https://git.hendrikpeter.net/hendrikpeter/pico-vim/-/blob/main/lua/peva/status_column.lua

The problem with nvim-tree however is that dynamic sizing doesn't take
the custom size of a status column into account and the end of file
names get clipped off. This little patch should fix that (and give some
examples to help other status_column modders get started).

Thanks for looking at this and thanks for making this amazing plugin,
I've been using it for a while and I really like it!

* allow padding function, update docs, rollback readme

* typo in example setup

* help formatting

---------

Co-authored-by: Alexander Courtis <[email protected]>
@abzrg

This comment was marked as resolved.

@luukvbaal
Copy link
Contributor Author

The default value is empty, meaning that it is not used. You should ask usage questions elsewhere, but the default "gutter" looks something like vim.o.statuscolumn = "%C%s%l ".

@neovim neovim deleted a comment from abzrg Mar 9, 2023
@neovim neovim locked as resolved and limited conversation to collaborators Mar 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
column sign/number column
Projects
None yet