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

Add a conf option to show no line number #769

Closed
wants to merge 1 commit into from

Conversation

irevoire
Copy link
Contributor

This PR adds the possibility to not print any line number:
On the left is a file opened with this patch vs the default settings on the right:
image

This is not ideal because if we don't print any line number we could save 5 unused spaces on the left but I don't know how to do it for now 😒
A little help would be appreciated if you have the time 👍

@pickfire
Copy link
Contributor

Thanks a lot. Nice PR since no one touch this up till now.

This is not ideal because if we don't print any line number we could save 5 unused spaces on the left but I don't know how to do it for now unamused

Quite a few places are hard-coded with the extra spaces. Most likely you need to change render_view and those places.

@irevoire
Copy link
Contributor Author

@pickfire it's probably not optimal, but it seems that it works.
I've been using it for one hour now and didn't encounter any bugs.

Here is a small video of how it works: https://asciinema.org/a/ujENYIa5G8JUrh6mYZRgilaeK
I'm thinking; maybe some users will prefer the old behaviour of having the column on the left of arbitrary fixed size. I don't know 🤔
But I think this could be done in another PR

@CptPotato
Copy link
Contributor

I like this feature 👍
This could be a first step to allow for a minimalistic "distraction free" mode or plugin similar to goyo.vim for example.

@archseer
Copy link
Member

While this implementation works, I'd rather wait until the gutter code is cleanly abstracted. That way disabling the line numbers simply removes the function from the list of gutters. We also don't want to pass cloned config objects into every view, the inner_area function will probably take a gutters_width parameter.

I'll see if I can get the gutter changes done today.

@archseer
Copy link
Member

Working on a prototype here: #783 disabling line numbers would simply remove the function from the set of gutters.

}

impl View {
pub fn new(doc: DocumentId) -> Self {
pub fn new(doc: DocumentId, config: crate::editor::Config) -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the config should be shared, best without using RefCell<Mutex<Config>> for #798

Copy link
Contributor

@pickfire pickfire left a comment

Choose a reason for hiding this comment

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

Tested and works nicely but I think how the config passed in can be done better.

@archseer archseer mentioned this pull request Nov 25, 2021
let last_line = self.offset.row + self.area.height as usize - 1; // -1 for statusline
let offset = match self.config.line_number {
LineNumber::Absolute | LineNumber::Relative => {
last_line.to_string().chars().count() + OFFSET
Copy link
Contributor

Choose a reason for hiding this comment

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

I just opened a log file with a few million lines and was searching for an issue about cut-off line numbers, nice to see that it’s fixed here!
I think computing the offset is more efficient with

/// Computes the number of decimal digits needed to print a number.
fn digits10(i: usize) -> usize {
    ((i + 1) as f64).log10().ceil() as usize
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Huum I'm not sure that using float and log10 would be any fast 🤔

What do you think of this function?

/// Computes the number of decimal digits needed to print a number.
fn digits10(n: usize) -> usize {
    std::iter::successors(Some(n), |n| {
        let n = n / 10;
        (n != 0).then(|| n)
    }).count()
}

I'll run a little benchmark just to get an idea but thanks for the suggestion.
I don't think this PR will be merged any time soon however because I don't really have any time to invest in helix currently so you can take it if you want and have the time 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is my result with a bunch of numbers:

log10/0                     time:   [6.8428 ns 6.8473 ns 6.8525 ns]                            
divide/0                    time:   [1.2312 ns 1.2334 ns 1.2362 ns]                             

log10/100                   time:   [8.8163 ns 8.8380 ns 8.8643 ns]                              
divide/100                  time:   [1.6460 ns 1.6472 ns 1.6485 ns]                               

log10/1000                  time:   [9.0255 ns 9.0385 ns 9.0530 ns]                               
divide/1000                 time:   [1.9341 ns 1.9369 ns 1.9403 ns]                                

log10/4000                  time:   [9.3187 ns 9.3493 ns 9.3821 ns]                               
divide/4000                 time:   [1.8846 ns 1.8853 ns 1.8860 ns]                                

log10/10000                 time:   [8.7732 ns 8.7818 ns 8.7922 ns]                                
divide/10000                time:   [2.0882 ns 2.0900 ns 2.0922 ns]                                 

log10/50000                 time:   [9.1107 ns 9.1342 ns 9.1616 ns]                                
divide/50000                time:   [2.1692 ns 2.1741 ns 2.1798 ns]                                 

log10/100000                time:   [9.0641 ns 9.0708 ns 9.0776 ns]                                 
divide/100000               time:   [2.4120 ns 2.4160 ns 2.4204 ns]                                  

log10/500000                time:   [9.3445 ns 9.3639 ns 9.3847 ns]                                 
divide/500000               time:   [2.3472 ns 2.3540 ns 2.3627 ns]                                  

log10/18446744073709551615  time:   [7.7829 ns 7.7914 ns 7.8008 ns]
divide/18446744073709551615 time:   [10.872 ns 10.879 ns 10.887 ns]

log10 is your function and divide is my function. The number after the / is which number was given to our function.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, that’s a lot faster!

@dannasessha dannasessha mentioned this pull request Dec 20, 2021
@Flakebi
Copy link
Contributor

Flakebi commented Dec 21, 2021

I rebased this PR and stitched something together that asks the gutter how much space it needs in https://github.com/Flakebi/helix/tree/no_line_number
The part that’s missing is, how do I get access to the Config and Document in places where the width is computed like View::inner_area?
I tried passing it through, but that required a lot of changes and didn’t feel right.

@pickfire
Copy link
Contributor

What about passing in a subset? Don't pass the whole config or document.

@pickfire
Copy link
Contributor

I wonder if this should be closed since gutter functions are merged.

@irevoire
Copy link
Contributor Author

Yes you're right there is no way for any of this code to be merged

@irevoire irevoire closed this Jan 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants