Skip to content

Conversation

ideasman42
Copy link

Support adjusting the context lines from the default of 3.


In some cases I want to stage/revert smaller hunks, this makes it possible.

@dgutov
Copy link
Owner

dgutov commented Jul 10, 2025

Hi!

Could you describe a specific scenario when the current literal value of 3 makes the hunks too "rough"?

There could be a bug somewhere, but the design behind the function diff-hl-split-away-changes (which you can see called in the diff) is to only keep some many lines of context when they don't intersect with the next set of changed lines.

@dgutov
Copy link
Owner

dgutov commented Jul 10, 2025

Perhaps the goal is to alter the contents of the buffer you see after M-x diff-hl-stage-some.

In that case, could I suggest trying C-c C-s first?

I wouldn't mind adding an option too, but it seems the above command would be more flexible in most cases, and without losing the context which usually helps orient oneself.

@ideasman42
Copy link
Author

ideasman42 commented Jul 10, 2025

I'm not familier with diff-hl-split-away-changes although I'm not sure it makes this pull request redundant, currently I use:

  • diff-hl-revert-hunk
  • diff-hl-stage-dwin

As I understand it, in both cases the "current-hunk" will depend on the number of context lines, so being able to control this allows for more granular control.


The use case I ran into where I wanted to use this feature was updating an author list: https://projects.blender.org/blender/blender/commit/85ad73809fa945f09f8fa7cc51c2f7702ca38354
... where it was useful to stage a single line without grouping it with other authors.

@dgutov
Copy link
Owner

dgutov commented Jul 10, 2025

As I understand it, in both cases the "current-hunk" will depend on the number of context lines, so being able to control this allows for more granular control.

The number of context lines could change, but the actual hunk to use is chosen carefully.

Here's an example, there are two hunks separated by just one line of context. I stage just one of them using diff-hl-stage-current-hunk (called by diff-hl-stage-dwim) with the current settings:

Screencast.from.2025-07-10.05-20-09.webm

@dgutov
Copy link
Owner

dgutov commented Jul 10, 2025

If it works differently for you, please show the steps to reproduce.

@dgutov dgutov closed this Oct 3, 2025
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.

2 participants