Álvaro Ramírez
Hide another detail
It's been 5 years since I talked about showing/hiding Emacs dired details in style, a short post showcasing hide-details-mode (built-in) and diredfl (third-party).
While my dired usage increased over the years, my dired config remained largely unchanged. Today, I'll show a new dired tweak.
As you likely suspect by now, I'm a big fan of hide-details-mode. It gives me super clean and minimalistic view of my files.
If I need more details, it's one toggle away using my trusty C-( binding.
Now this is a super minor thing, but for a little while, I wished I could also hide the current directory's absolute path as part of hide-details-mode
's toggling. In the same spirit as other hidden dired details, I rarely need to see the absolute path. And if I did, it'd only be a toggle away.
With that in mind, I set out to bend dired my way. I looked at the dired-hide-details-mode
built-in code (dired.el) and came across invisibility specs, which I hadn't used before. Dired uses add-to-invisibility-spec
and remove-from-invisibility-spec
to show and hide details using the invisible
property set to dired-hide-details-information
.
Now that we know what property to set, we need to find the text to apply it to. Dired offers that via dired-subdir-regexp
. All we need to do is match the regular expression and apply our invisible property to the relevant bounds.
(defun hide-dired-details-include-all-subdir-paths () (save-excursion (goto-char (point-min)) (while (re-search-forward dired-subdir-regexp nil t) (let* ((match-bounds (cons (match-beginning 1) (match-end 1))) (path (file-name-directory (buffer-substring (car match-bounds) (cdr match-bounds)))) (path-start (car match-bounds)) (path-end (+ (car match-bounds) (length path))) (inhibit-read-only t)) (put-text-property path-start path-end 'invisible 'dired-hide-details-information)))))
All that's left is for us to add our new function to a hook, and we're good to go.
(use-package dired :hook ((dired-mode . dired-hide-details-mode) (dired-after-readin . hide-dired-details-include-all-subdir-paths)))
My Dired window is even cleaner now. The current directory's absolute path is now hidden.
There may be times we need to peek at the absolute path. We can now toggle hiding this detail just like the others.
My first Emacs patch
While this is a rather small change, I figured I could use it to get my toes dipped as a first Emacs contribution. I've since reworked the patch to fit into dired.el's code and submitted for review.
I'm happy to report the tiny feature's now merged to master as of a couple of days ago. Yay! 🎉
It'll be sometime until the feature makes it to a release, but if you're living on the Emacs master edge, it should be available there. While the feature is disabled by default, it can enabled with:
(setq dired-hide-details-hide-absolute-location t)
Happy hiding!
Enjoying this content? Using one of my Emacs packages?
Help make the work sustainable. Consider sponsoring. I'm also building lmno.lol. A platform to drag and drop your blog to the web.