Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: dired-jump for dired-collapse #189

Open
yurikhan opened this issue Feb 8, 2022 · 3 comments
Open

Feature request: dired-jump for dired-collapse #189

yurikhan opened this issue Feb 8, 2022 · 3 comments

Comments

@yurikhan
Copy link

yurikhan commented Feb 8, 2022

dired-collapse lets us skip several levels of subdirectories when drilling down, and this is occasionally very convenient. It’s like saying “I go down this path” rather than repeating “I move forward” multiple times.

It would be nice to also be able to say “I go up to the nearest interesting directory”, where “interesting” is defined as “has more than one item”.

@Fuco1
Copy link
Owner

Fuco1 commented Feb 8, 2022

Maybe something like this

(defun dired-collapse-jump ()
  "Jump to the first parent directory with more than one file.

This is opposite of \"drilling down\" through empty collapsed directories."
  (interactive)
  (let* ((file-name (buffer-file-name))
         (path (or (f-parent file-name) default-directory))
         prev-path
         files)
    (while (and (file-directory-p path)
                (file-readable-p path)
                (setq files (f-entries path))
                (= 1 (length files)))
      (setq prev-path path)
      (setq path (f-parent path)))
    (dired-jump nil prev-path)
    (dired-goto-file file-name)))

@yurikhan
Copy link
Author

yurikhan commented Feb 8, 2022

-  (let* ((file-name (buffer-file-name))
+  (let* ((file-name (or (buffer-file-name) default-directory))

or something, because (buffer-file-name) returns nil for Dired bufers and then (f-parent nil) on the next line errors out.

Otherwise, it seems to work, thank you! Now I was going to bind it to [remap dired-jump] but dired-collapse-mode does not seem to have a keymap… Never mind, dired-collapse-mode is not going to be enabled in file buffers so I’ll need to bind it globally.

@Fuco1
Copy link
Owner

Fuco1 commented Feb 9, 2022

Yea, good catch. I'll add it to the package, I like it. Good suggestion!

@Fuco1 Fuco1 assigned Fuco1 and unassigned Fuco1 Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Ready
Development

No branches or pull requests

2 participants