I prefer flatter projects.

Unfortunately some languages dictate a deeper structure. When dealing with those, it helps (a little) if directory views "collapse" empty paths. Example how GitHub does this.

I'm wondering how I could make dired do this?

  • Is there an existing option I'm overlooking?
  • Is there an existing package that adds this?
  • Should I attempt to write such a package? O_o

Update: Drew commented that the GitHub example isn't clear and asked me to explain. Their August 19, 2014 blog post explains a new feature they call "Folder Jumping".

  • You could suggest such a feature on @Fuco's github.com/Fuco1/dired-hacks...
    – wasamasa
    Jan 23, 2016 at 18:47
  • The question is not very clear, to me at least. What does it mean to "collapse" an empty directory in its parent Dired listing? Subdirs are already collapsed, in the sense that their contents are not shown by default. You can of course insert any subdir, using i, but that "expands" it, instead of collapsing. Please clarify what you are looking for versus what you see in vanilla Dired. Give an example. (Your GitHub "example" is not clear to me. Show what you would like for a Dired listing.)
    – Drew
    Jan 23, 2016 at 21:10
  • 2
    There is a new "dired-collapse" package on melpa for this.
    – glucas
    Jul 17, 2017 at 12:53

1 Answer 1


I think I should self-answer. (But it's not an exact answer to my question as-asked. So I'm not sure if I should self-accept.)

Thanks to wasamasa I checked out dired-subtree. Unlike plain dired, it inserts subdir trees "inline". Nice.

Next I realized I can use its dired-subtree-cycle command with a prefix argument to expand N levels deep. So I bound that to TAB.

(use-package dired-subtree
  :ensure t
  :init (setq dired-subtree-use-backgrounds nil)
  :config (bind-keys :map dired-mode-map
                     ;; With C-u prefix expands N deep.
                     ;; C-u TAB will expand 4
                     ;; C-u C-u TAB will expand 16
                     ;; C-u C-u C-u TAB will expand 64
                     ("TAB" . dired-subtree-cycle)))

As a result, I can C-u C-u TAB to expand 16 levels deep.

I can even C-u C-u C-u TAB to expand 64 levels -- enough for even the most ceremonial languages (hello, Java).

Another TAB closes the whole subtree.

Although not the GitHub-style "folder jumping" I originally imagined, I think this will work as well or better, for me.

  • Well, you can still open a ticket on that repository, even if it's just for exchanging ideas with someone knowing their way around dired, perhaps that will give you a hint how to do even better.
    – wasamasa
    Jan 25, 2016 at 21:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.