Skip to content

Fixes #284: Capture buffer not associated with a file#285

Open
jamescherti wants to merge 1 commit into
dgutov:masterfrom
jamescherti:fix-capture-buffer-not-associated-with-file
Open

Fixes #284: Capture buffer not associated with a file#285
jamescherti wants to merge 1 commit into
dgutov:masterfrom
jamescherti:fix-capture-buffer-not-associated-with-file

Conversation

@jamescherti
Copy link
Copy Markdown
Contributor

@jamescherti jamescherti commented Jun 5, 2026

This pull request:

  • Fixes Capture buffer not associated with a file #284
  • Resolves compatibility issues when invoking diff-hl commands from cloned or indirect buffers. Several functions in vc, such as vc-buffer-sync and vc-deduce-fileset, rely on the state and file association of the current buffer. When these functions are executed from an indirect buffer, they often fail to resolve the proper version control context, leading to errors during operations like reverting hunks, fetching diffs, or deducing the active VC backend. To address this, the updates systematically wrap buffer-dependent vc-* function calls within a with-current-buffer (diff-hl--target-buffer ...)) block.
  • diff-hl--target-buffer: make its argument optional, cleaning up several redundant calls.

@jamescherti jamescherti force-pushed the fix-capture-buffer-not-associated-with-file branch 3 times, most recently from 832baba to 5552a66 Compare June 5, 2026 16:12
@jamescherti jamescherti marked this pull request as draft June 5, 2026 16:29
@jamescherti jamescherti marked this pull request as ready for review June 5, 2026 16:30
@jamescherti jamescherti force-pushed the fix-capture-buffer-not-associated-with-file branch 3 times, most recently from 117f068 to c3d0219 Compare June 5, 2026 17:20
@jamescherti
Copy link
Copy Markdown
Contributor Author

I tested this pull request with org-capture and it works:
image

@jamescherti jamescherti force-pushed the fix-capture-buffer-not-associated-with-file branch from c3d0219 to 32708f0 Compare June 5, 2026 17:37
@jamescherti
Copy link
Copy Markdown
Contributor Author

I have also made changes to fix both diff-hl-revert-hunk-1 and diff-hl-after-checkin.

@jamescherti jamescherti force-pushed the fix-capture-buffer-not-associated-with-file branch 4 times, most recently from b481e3c to 0a65381 Compare June 5, 2026 18:56
@jamescherti
Copy link
Copy Markdown
Contributor Author

This pull request fixes the issue: #284 (comment)

VC library functions (like vc-buffer-sync, vc-deduce-fileset, and
vc-ensure-vc-buffer) rely on the current buffer's file association and
local state. When invoked from an indirect or cloned buffer, these
functions can fail or return incorrect results.

This commit wraps these buffer-dependent VC calls in
(with-current-buffer (diff-hl--target-buffer ...)) to ensure they always
execute in the context of the base buffer.

The diff-hl--target-buffer function was also updated to make its
argument optional, cleaning up several redundant calls.
@jamescherti jamescherti force-pushed the fix-capture-buffer-not-associated-with-file branch from 0a65381 to a0378a2 Compare June 5, 2026 19:00
@dgutov
Copy link
Copy Markdown
Owner

dgutov commented Jun 5, 2026

@jamescherti Remember the several places we have the redundant (with-current-buffer (current-buffer now?

How about we try to localize the fix there?

Both diff-hl-revert-hunk and diff-hl-diff-goto-hunk are in that set, for instance.

@jamescherti
Copy link
Copy Markdown
Contributor Author

jamescherti commented Jun 5, 2026

Hello @dgutov,

Let's merge this fix and then work on enhancements in a separate pull request.

Merging this will fix #284 for the users who are experiencing it. It also fixes the issue with reverting the hunk.

@dgutov
Copy link
Copy Markdown
Owner

dgutov commented Jun 5, 2026

@jamescherti Could we limit the fix to those with-current-buffer forms? Or do we have to add new ones?

How do we reproduce the issue? Just using M-x org-capture in a version-controlled .org file?

@dgutov
Copy link
Copy Markdown
Owner

dgutov commented Jun 5, 2026

If we have to add a new one, we can add it in diff-hl-flydiff-update.

Or change save-current-buffer to with-current-buffer (...) in diff-hl-diff-buffer-with-reference.

But preferably just one of these.

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.

Capture buffer not associated with a file

2 participants