Subject: bug#61785: [PATCH] Add option to keep some columns in dired-hide-details-mode

From: Augusto Stoffel <[email-masked]>
Date: Sat, 25 Feb 2023 12:30:14 +0100

Tags: patch

I find the normal dired buffer a bit too busy but
dired-hide-details-mode a bit too lacking.  So I'd like show only the
details I care most about, for instance like this:

--8<---------------cut here---------------start------------->8---
  /home/augusto/emacs:
  4.0K Feb 25 .
  4.0K Feb 20 ..
  4.0K Feb 25 admin
  4.0K Feb 20 autom4te.cache
  4.0K Feb 25 build-aux
  3.6K Feb 20 aclocal.m4
   11K Feb 25 autogen.sh
   932 Jun  6 BUGS
  ...
--8<---------------cut here---------------end--------------->8---

The above can be obtained by setting

  (setq dired-hide-details-preserved-columns '(5 6 7))

After writing this, I realized one could easily modify the new user
option to be an alist mapping column numbers to arbitrary text
properties to be applied to that column.  If anyone thinks this variant
is useful, I'd be happy to adapt the patch.

>From 58ed1d179e4b9a66f21a3507787033bd94d7107d Mon Sep 17 00:00:00 2001
From: Augusto Stoffel <[email-masked]>
Date: Sat, 25 Feb 2023 12:15:43 +0100
Subject: [PATCH] Add option to keep some columns in dired-hide-details-mode

* lisp/dired.el (dired-hide-details-preserved-columns): New user
option.
(dired-insert-set-properties): Use it.
---
 lisp/dired.el | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/lisp/dired.el b/lisp/dired.el
index 2bcb28a0e00..7a9076ecb49 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -490,6 +490,11 @@ dired-guess-shell-znew-switches
                  (string :tag "Switches"))
   :version "29.1")
 
+(defcustom dired-hide-details-preserved-columns nil
+  "List of columns which are not hidden in `dired-hide-details-mode'."
+  :type '(repeat integer)
+  :version "30.1")
+
 
 ;;; Internal variables
 
@@ -1880,8 +1885,15 @@ dired-insert-set-properties
 	      (put-text-property (line-beginning-position)
 				 (1+ (line-end-position))
 				 'invisible 'dired-hide-details-information))
-	  (put-text-property (+ (line-beginning-position) 1) (1- (point))
-			     'invisible 'dired-hide-details-detail)
+	  (save-excursion
+            (let ((end (1- (point)))
+                  (opoint (goto-char (1+ (pos-bol))))
+                  (i 0))
+              (put-text-property opoint end 'invisible 'dired-hide-details-detail)
+              (while (re-search-forward "[^ ]+" end t)
+                (when (member (cl-incf i) dired-hide-details-preserved-columns)
+                  (put-text-property opoint (point) 'invisible nil))
+                (setq opoint (point)))))
           (when (and dired-mouse-drag-files (fboundp 'x-begin-drag))
             (put-text-property (point)
 	                       (save-excursion
-- 
2.39.2