in Emacs, how to enable automatic hiding of dired details?
Asked Answered
T

2

10

I use a library called dired-details and dired-details+ to simplify dired's display, such that a line like this:

-rw-r--r--@  1 peter  staff  22571 Apr 15 16:05 foo.txt

displays like this:

foo.txt

However, I have another function, which places all directories at the top of the list:

(defun mydired-sort ()
"Sort dired listings with directories first."
(save-excursion
 (let (buffer-read-only)
  (forward-line 2) ;; beyond dir. header
  (sort-regexp-fields t "^.*$" "[ ]*." (point) (point-max)))
(set-buffer-modified-p nil)))

(defadvice dired-readin
(after dired-after-updating-hook first () activate)
 "Sort dired listings with directories first before adding marks."
 (mydired-sort))

and this second function interferes with dired-details, such that when I C-x d to open a dired buffer, the initial display shows the full extraneous details. Only by pressing g to revert-buffer to refresh the display do the directory details become hidden.

How do I enable hiding of dired details by default in all dired displays?

Toy answered 21/4, 2014 at 23:51 Comment(0)
S
11

First, if you use Emacs 24.4 or later (or a developement version past 24.3), then you no longer need either dired-details.el or dired-details+.el. Starting with Emacs 24.4, Dired listing details are hidden by default. dired-hide-details-mode is the relevant mode.

If you use dired+.el (Dired+) then you can more easily take advantage of this new behavior -- it gives you all of the features offered by dired-details+.el. Use ( anytime to toggle this hiding. You can use Dired+ option diredp-hide-details-initially-flag to change the default/initial state. See also option diredp-hide-details-propagate-flag.

If you use an Emacs version that is prior to Emacs 24.4 (so you need dired-details[+].el) then try loading dired-details+.el (which will load dired-details.el) after you have evaluated your code above. If that does not help, then try also adding this to your defadvice body, just after (mydired-sort): (dired-details-hide). If that does not work then we will need to look a bit further.

If you can upgrade your Emacs version then you will soon be able to use Emacs 24.4 (it is in pretest now), in which case you should be able to just load dired+.el and set option diredp-hide-details-initially-flag to non-nil.

Wrt sorting directories first: Are you on MS Windows? If so, consider using libraries dired-sort-menu.el and dired-sort-menu+.el. It lets you do that and much more.


UPDATE

The problem is that dired-details caches the list of overlays it uses to hide details. It has already done its job (because of dired-after-readin-hook), before your sorting is done, and that changes the buffer without updating the cache info. This will fix the problem (there is probably a more elegant way, but this will do):

(defadvice dired-readin
    (after dired-after-updating-hook first () activate)
  "Sort dired listings with directories first before adding marks."
  (mydired-sort)
  (let ((dired-details-internal-overlay-list  ())) (dired-details-hide)))
Scan answered 22/4, 2014 at 2:20 Comment(3)
Thanks for the extensive reply. I'm on OSX using GNU Emacs. Current version of GNU Emacs for OSX appears to be 24.3.1. So I followed your directions above (I think) and it still doesn't work. Here is the way the dired section of my .emacs looks at the moment: pastebin.com/73ZdazyKToy
Preliminary remarks, before I take a look: (1) You don't need your own defcustoms -- just set the option value you want, using customize-set-variable (or using M-x customize-option). (2) You need not quote lambda forms, so don't do that. (3) Try to narrow down your code to just what is essential to the problem. E.g. try getting rid of the omit stuff if it is not pertinent to the problem. Likewise for the rest: bisect your code recursively until you have minimal code to produce the problem. Don't make yourself and others wade through stuff that is irrelevant to the problem.Scan
Try the code above (bind the overlays cache to nil).Scan
T
1

This is a late answer but I am hopeful this will help people heading here.

Adding the below line in .emacs or init.el should hide details in all dired buffers.

(add-hook 'dired-mode-hook (lambda () (dired-hide-details-mode 1)))
Tumescent answered 6/8 at 8:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.