dired-hacks icon indicating copy to clipboard operation
dired-hacks copied to clipboard

dired-narrow: call `dired-narrow-find-file' when entering directory

Open bastidest opened this issue 3 years ago • 6 comments

Information

Emacs Version GNU Emacs 28.0.50.148618
OS Arch Linux (5.12.15-arch1-1)
emacs -q ? yes

Emacs Configuration:

(require 'package)
(package-initialize)

(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))

(use-package dired-narrow
  :after (dired)
  :bind (:map dired-mode-map
        ("/" . dired-narrow)))

Bug Description

May be related to #147 . Please confirm that the described behavior is intended as such (I might not understand dired-narrow-enter-directory correctly).

Expected Behavior

After entering dired-narrow-mode and selecting a directory (by filtering and moving the point), calling dired-narrow-enter-directory should enter the directory at point and start another dired-narrow minibuffer.

Actual Behavior

After entering dired-narrow-mode and selecting a directory, calling dired-narrow-enter-directory does not enter the directory, but simply restarts narrowing in the current (already narrowed) directory.

Change Description

Before this change, when dired-narrow-enter-directory was called, the dired-narrow--internal function did call itself to start another instance of dired narrow in the subdirectory. However it did not visit the directory at point, which restarted dired-narrow in the current (already filtered) directory.

With this change dired-narrow-find-file is called before restarting dired-narrow--internal. This will visit the directory at point and start another dired-narrow instance. If the current file is not a directory, visit the file at point.

Comment

Thank you for maintaining this package!

bastidest avatar Jul 13 '21 11:07 bastidest

Hi. I tried to replicate this but can't. Are you sure you are calling dired-narrow-enter-directory (bound to right arrow key or C-j) and not the regular dired find file?

Fuco1 avatar Aug 25 '21 12:08 Fuco1

Thank you for your response. Your screencast shows my desired result. I tested it on a different system with the configuration shown above and was still able to reproduce my issue.

Screenshot from 2021-08-27 17-50-48

The screenshot shows a dired-narrow buffer filtering by the word auto. I changed focus from the minibuffer to the dired buffer and confirmed that the C-j binding does indeed call dired-narrow-enter-directory (C-h c). The issue still persists.

Have you tried to reproduce this with emacs -Q? I will try to test it on emacs 27 when I get the chance.

bastidest avatar Aug 27 '21 16:08 bastidest

I'm actually on E26, so that might be the variable which is different here.

Fuco1 avatar Aug 27 '21 16:08 Fuco1

I reproduced it on emacs 27.2 and emacs 26.

Docker commands:

  • docker run --rm -it silex/emacs:27.2-alpine
  • docker run --rm -it silex/emacs:26-alpine

Steps:

  1. Go to *scratch* buffer
  2. Paste this
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(package-initialize)

(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))

(use-package dired-narrow
  :ensure t
  :after (dired)
  :bind (:map dired-mode-map
        ("/" . dired-narrow)))
  1. M-x eval-buffer
  2. C-x d --> dired opens at /
  3. / --> dired-narrow mode in minibuffer
  4. etc --> filters etc directory
  5. C-j --> Bug

bastidest avatar Aug 29 '21 12:08 bastidest

You're not binding dired-narrow-enter-directory in your repro case. However, I added the binding and can reproduce the bug. So there must be something on my system fixing it.

Fuco1 avatar Aug 29 '21 17:08 Fuco1

Binding it should not be necessary, right? At least the default keymap shows the bindings (describe-keymap)

dired-narrow-map is a keymap variable defined in ‘dired-narrow.el’.

Documentation:
Keymap used while ‘dired-narrow’ is reading the pattern.

key             binding
---             -------

C-g             minibuffer-keyboard-quit
C-j             dired-narrow-enter-directory
RET             exit-minibuffer
C-n             dired-narrow-next-file
C-p             dired-narrow-previous-file
<down>          dired-narrow-next-file
<return>        exit-minibuffer
<right>         dired-narrow-enter-directory
<up>            dired-narrow-previous-file

bastidest avatar Aug 29 '21 17:08 bastidest

I figured it out. By default, the dired-narrow-exit-action is set to ignore so it does nothing. I had it set to dired-narrow-find-file, so when I exited the minibuffer with C-j it called this function and remembered that I used the enter-directory command so it restarted the search.

For you, since your exit action is most likely just the default ignore, it executed that (= did nothing) and then restarted the narrowing in the same buffer.

Your fix was to call the dired-narrow-find-file when acting on a directory, however, you call it after the default action runs. So for someone like me, it would actually call the exit action twice (once from the config and once from your patch).

I reordered the conditions so that in case of the enter directory action the exit-action is simply ignored because it doesn't actually make sense... our action is to enter the directory so we shouldn't run anything else.

Fuco1 avatar Jun 29 '24 19:06 Fuco1

Thank you for the contribution, your code helped me figure out the problem!

Fuco1 avatar Jun 29 '24 19:06 Fuco1