-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
[RFC] Allow displaying signs in the number column #9040
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
Conversation
Temporary commit.
Except for STRNCPY -> STRLCPY, we don't want that.
src/nvim/screen.c
Outdated
if ((wp->w_p_cul || wp->w_p_rnu) | ||
&& lnum == wp->w_cursor.lnum) { | ||
|
||
if (text_sign != 0 && strstr((char *)wp->w_p_scl, "number") != NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
General note: win_line
is a hot path, so it needs to stay fast. It's probably negligible, or maybe compilers optimize this strstr
, but the general practice in win_line
is avoid the risk.
Typical "Vim style" would be to check (*wp->w_p_scl == 'n' && *wp->w_p_scl == 'u')
. But that's a bit much, rather store a boolean at the top of win_line
.
For the same reason we might want to mark draw_sign
as inline
(it should also be static
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is a concern, the value could be parsed into an enum by option.c at the time of setting, as is done for other "hot-path" string options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell, this code is run only once per call to win_line
anyway, except in the case of wrapping lines. So I don't think putting it at the beginning of win_line
would do much. For now, I did the char-wise check.
As for using an enum, I haven't found any such cases for other options. Do you have an example?
I find the |
I hadn't thought of that possibility. I think adding |
I dealt with the I also removed |
I added a test, but I'm not sure if I did it right. Perhaps I should split it up into smaller tests? |
In order to save horizontal space, this patch allows you to display signs in place of line numbers in the number column by setting
signcolumn=number
. Additionally, settingsigncolumn=number_hl
will display the line number, but highlighted according to the sign.I'm not an experienced C programmer, so please forgive any rookie mistakes.
Some comments:
The code is currently broken withIt now eats into the padding to get enough room.numberwidth
<= 2. This can either be fixed by forcing the number column to be wider in this case, or by truncating or hiding the sign.extra
buffer can be overflown with a sign text with unreasonable amounts of combining characters. I switched to usingp_extra_free
to fix this.draw_sign
function, although it's still not very elegant.cursorline
, but that can easily be changed.number
starts with the lettern
, and hence is interpreted as ano
by the part of the code that hides the regular sign column. Maybe this is a bit too hacky, but easy to fix.