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

Navigate regexp #782

Merged
merged 5 commits into from
Nov 23, 2021
Merged

Navigate regexp #782

merged 5 commits into from
Nov 23, 2021

Conversation

WayneD
Copy link
Contributor

@WayneD WayneD commented Nov 18, 2021

In my navigating of delta diffs, I'd prefer to not stop at each hunk. My first thought was to override the navigate_regexp value, but it wasn't configurable. Then I had the idea to change the hunk-label to an empty string, which then made n/N stop at every line.

This branch makes the following changes:

  • Turn --navigate-regexp into an option that defaults to an empty string. When the string is empty, it is auto-populated with a value based on the various labels (the old behavior).
  • Change the make_navigate_regexp() func to not add empty regex options to the string.
  • Change the code that outputs the hunk-label to output it whenever it is non-empty, not when --navigate is specified. This (1) makes the option work all the time like other labels, and (2) ensures that an empty hunk-label doesn't add a leading space when --navigate is specified.

With these changes I've chosen to not override navigate-regexp and to just force hunk-label to an empty string in my git config. This avoids stopping at each hunk while also making it easy to manually specify an override --hunk-label option when I want to change my mind. So, if you don't like the first commit in this branch (making navigate_regexp an option) the other 2 commits are good enough for my needs.

@th1000s
Copy link
Contributor

th1000s commented Nov 19, 2021

Indeed, the --navigate-regexp should be user configurable.

So if I understand correctly, this can make navigation more fine grained by passing something that matches every line? Do you have ideas for other possible regexes which improve navigation?

I've also been playing around with this and want to add a nav marker every term-height/2 changed lines to still be able to jump around when using a lot of context such as -U200, but I have not found a good spot to place them (or hide via ANSI magic) yet.

@WayneD
Copy link
Contributor Author

WayneD commented Nov 19, 2021

I'm wanting to avoid matching every line. With the current code, an option of --hunk-title '' results in an empty option in the auto-gen regex ('^(commit|added:|removed:|renamed:|Δ|)') which matches every line, making the skipping useless. The new code avoids adding an empty label in such a case ('^(commit|added:|removed:|renamed:|Δ)') as well as any other empty label (e.g. also specifying --file-modified-label '' would result in '^(commit|added:|removed:|renamed:)').

As for smaller amounts of skipping, a d goes down 1/2 a page, or the user could type 10z to make space go forward in 10-line chunks. If you want an invisible stopping point, you could try outputting a zero-width space at the start of a line and adding that to the navigate regex (U+200B). That works in my terminal.

src/cli.rs Outdated Show resolved Hide resolved
src/config.rs Outdated Show resolved Hide resolved
src/cli.rs Outdated Show resolved Hide resolved
@th1000s
Copy link
Contributor

th1000s commented Nov 21, 2021

Apart from the "expert mode" of specifying the navigate-regex directly, might it make sense to specify the navigation stop types in a more user friendly way?

invisible stopping point / zero-width space

Thanks, great idea!

@dandavison
Copy link
Owner

Great, thanks! I'll merge when the tests pass.

@WayneD
Copy link
Contributor Author

WayneD commented Nov 23, 2021

Apart from the "expert mode" of specifying the navigate-regex directly, might it make sense to specify the navigation stop types in a more user friendly way?

That is an interesting idea, since you could then leave hunk off the list without hard-wiring the other labels to particular values. That makes me think that some kind of normally invalid regex idiom, such as {added} and {hunk} might be an interesting way to specify such a thing. So, the default would be similar to:

^(commit|{added}|{removed}|{renamed}|{modified}|{label})

(though the default does also auto-remove empty labels and their prior vertical bar). To avoid the stop-on-every-line issue with this regex idiom, an empty label could be turned into something like [^\s\S] that would make that option never match (and thus not require any vertical bar removals).

@dandavison dandavison merged commit 0c0043b into dandavison:master Nov 23, 2021
kang8 added a commit to kang8/.dotfiles that referenced this pull request Jun 18, 2023
Unset features:
- unset hunk-label, to skip hunk when using navigate jump. See: dandavison/delta#782
- unset hyperlinks-file-link-format, I do not want to open file when
  hyperlinks is enable.
Use merge.conflictstyle is diff3 to enable conflict in delta.
Add alias `gds` and `gdas` to show side-by-side in diff
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.

None yet

3 participants