Skip to content

Fix recursion when opening regular files with C-j in dired-narrow - #237

Open
nicewise wants to merge 1 commit into
Fuco1:masterfrom
nicewise:fix-narrow-enter-file
Open

Fix recursion when opening regular files with C-j in dired-narrow#237
nicewise wants to merge 1 commit into
Fuco1:masterfrom
nicewise:fix-narrow-enter-file

Conversation

@nicewise

Copy link
Copy Markdown

Problem

When pressing C-j in dired-narrow, the command
dired-narrow-enter-directory inserts a magic string and exits the
minibuffer. The control flow in dired-narrow--internal then calls
dired-narrow-find-file and unconditionally re-enters narrowing.

This works correctly for directories, but when the target is a regular
file, narrowing may re-enter unexpectedly or produce inconsistent
behavior.

Cause

The current implementation does not distinguish between entering a
directory and opening a regular file after calling
dired-narrow-find-file. It always restarts the narrowing loop.

Solution

After calling dired-narrow-find-file, check whether the resulting
buffer is still derived from dired-mode. If so, it means a directory
was entered and narrowing should restart. Otherwise, if a regular file
was opened, narrowing should not re-enter.

This keeps the original behavior for directories while avoiding
unnecessary recursion for regular files.

Result

  • C-j on directories: enter directory and continue narrowing
  • C-j on regular files: open file and exit narrowing
  • No change to existing directory workflow

Instead of unconditionally re-entering narrowing after
`dired-narrow-find-file`, check whether the resulting buffer
is still in `dired-mode`. This prevents unintended recursion
when opening regular files.
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.

1 participant