Hide diff buffers when the user is editing files outside the associated Claude session context, showing them only when relevant.
monet-hide-diff-when-irrelevant- boolean flag (default nil for backward compatibility)- When enabled, diffs are only shown when editing relevant files
Store additional information in the diff context (already in opened-diffs hash):
:initiating-file- The file that was active when diff was triggered:session-directory- The session's root directory:diff-buffer- Reference to the diff buffer (already stored):tab-name- The unique identifier (already stored)
- Runs on post-command-hook when feature is enabled
- For each session with active diffs:
- Check if current buffer is relevant to that session
- Show/hide diff windows accordingly
A diff should be visible when:
- Current buffer's file is under the session directory
- Current buffer's file matches the initiating file
- Current buffer IS the diff buffer itself
(defcustom monet-hide-diff-when-irrelevant nil
"When non-nil, hide diff buffers when editing unrelated files.
Diff buffers will only be shown when editing files within the
associated Claude session directory or the file that initiated
the diff request."
:type 'boolean
:group 'monet-tool)- Capture the current buffer's file when diff is created
- Store this in the diff context
- Include initiating file and session directory in returned context
- Conditionally display based on current context when feature is enabled
monet--is-buffer-relevant-to-session-p- Check if buffer belongs to sessionmonet--should-show-diff-p- Determine if diff should be visiblemonet--update-diff-visibility- Main visibility update functionmonet--show-diff-window- Show a hidden diffmonet--hide-diff-window- Hide a visible diff
- Add/remove post-command-hook based on:
- Feature enabled state
- Presence of active diffs
Rather than killing/recreating windows, we'll:
- Use
set-window-dedicated-pto prevent accidental reuse - Store window configuration in diff context
- Hide by switching window to a different buffer
- Show by restoring the diff buffer to its window
- Store control buffer as primary buffer to show/hide
- Optionally hide all three ediff buffers (A, B, control)
- Use ediff's window configuration management
-
Basic functionality
- Enable feature and create a diff
- Switch to file outside session - diff should hide
- Switch back to session file - diff should reappear
-
Multiple sessions
- Create diffs in two different sessions
- Verify each shows only in its context
-
Edge cases
- Files opened from outside session directory
- Switching between multiple diff buffers
- Closing diff buffers manually
-
Performance
- Ensure post-command-hook doesn't impact editing performance
- Test with many open buffers and active diffs
- Feature is disabled by default
- Existing behavior unchanged when
monet-hide-diff-when-irrelevantis nil - No changes to existing diff tool interfaces