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

Allow headers to be defined using regular expressions #436

Closed
ericpruitt opened this issue Sep 25, 2023 · 6 comments
Closed

Allow headers to be defined using regular expressions #436

ericpruitt opened this issue Sep 25, 2023 · 6 comments

Comments

@ericpruitt
Copy link

I like the "--header" option, but I wish it were possible to specify headers using regular expressions. This would be useful when, for example, looking at long diffs where the file name might be scroll out of view or looking at man pages and figuring out which section you're reviewing without having to scroll back. Ideally, it'd be nice to be able to specify the number of lines of context before and after the diff, but even showing a single line would be useful.

@bew
Copy link

bew commented Sep 25, 2023

This would integrate nicely with delta and be a basic replacement to ov's section system

@gwsw
Copy link
Owner

gwsw commented Sep 25, 2023

Just to make sure I understand this proposal, you're asking for an option where you'd specify a regular expression, and the first line in the file that matches that pattern would always be displayed as the first line on the screen? Is that correct? Maybe it make more sense to use a line number instead of a pattern, to avoid ambiguity about what should be done if no line matches the pattern, or if more than one do.

@ericpruitt
Copy link
Author

ericpruitt commented Sep 25, 2023

No, the idea is that when you scroll past a line matching the regular expression, it becomes the new header.

If it was possible to specify multiple header line numbers, that could suffice, but it becomes more complicated when you're using less to view ephemeral data that way which is why I would prefer regular expressions.

@gwsw
Copy link
Owner

gwsw commented Sep 30, 2023

In that case the header displayed at a certain position in the file would be nondeterministic. It would depend on how you reached that point in the file -- scrolling there might show one header, but jumping there via the g or p command would show a different header. Is that the intended behavior?

@ericpruitt
Copy link
Author

ericpruitt commented Sep 30, 2023

No, that's not the intended behavior. I would expect the implementation to search backwards for a matching header if the user moves in discontinuous manner. The process could be optimized with some caching of matching line numbers and keeping track of which lines have been searched for header matches to reduce the search space.

@gwsw
Copy link
Owner

gwsw commented Nov 30, 2023

Using a regular expression to define headers turned out to be rather awkward to implement. It also seems to me to be less than useful in cases where there isn't a clear pattern that can capture all header lines. Instead, in a1a6f61 I have enhanced the --header option so that it sets the first line on the screen to be the header line. This can be issued as needed to select different lines as header lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants