How do I make Dired display its files using an arbitrary function or set of columns? Basically I want to change from:
-rw-r--r-- 1 konrad konrad 3847863 Out 18 14:17 ClojureinAction.pdf
-rw-rw-r-- 1 tamara tamara 27338341 Out 20 07:16 Halliday, Resnick, Walker - Fundamentals of Physics.pdf
-rw-r--r-- 1 konrad konrad 3921024 Set 22 11:11 Pragmatic.Programming.Clojure.May.2009.pdf
To something like
644 1-5MB ClojureinAction.pdf PDF (5 days ago, 400pgs)
664 10-100MB Halliday, Resnic...pdf PDF (3 days ago, 1000pgs, Tamara's)
644 1-5MB Pragmatic.Progra...pdf PDF (1 min ago, 100 pages)
Thanks!
EDIT: Thanks for the answer, Gareth, but could you be more verbose, please? Apparently the hook will just allow me to run arbitrary code when the buffer loads up. Dired won't even stop loading up the buffer :(
(defun foo (&rest args) (unlocking-buffer (message "foo") (insert "foo\n")))
Glancing at dired's source code, it seems that it gets information from these very formats I'm trying to replace, so I wonder if it's viable to change it this way, or if I'll end up having to rewrite everything.
Write a function that transforms the output of ls
into the format you want, and then add that function to dired-after-readin-hook
.
Edited to add: dired-mode
determines the name of the file by parsing the output of ls
, so some features of dired will break when you change the format. You can make (some of) them work again by changing directory-listing-before-filename-regexp
and dired-permission-flags-regexp
. Since your change to the format is quite radical, you may prefer to rewrite the functions dired-move-to-filename
and dired-move-to-end-of-filename
.
(This sounds tough but it's not impossible. I customize the format of dired buffers in the manner I described, though not nearly so radically as you propose to do.)
You will have a lot of work if you insist on truncating the filename, because dired-mode
assumes that it can get the filename on the current line by calling
(buffer-substring (dired-move-to-filename) (dired-move-to-end-of-filename))
Dired mode makes quite a few assumptions about ls
output format, so changing the format will break many things. I think a more feasible approach is to leave the format alone, and use either text-properties or overlays to change the presentation.
This isn't nearly as drastic as what you're looking for, but it is possible to customize how Emacs calls ls
in dired-mode
.
M-x customize-variable RET dired-listing-switches RET
I used it to omit the group ID of files with the -o
option, saving some horizontal screen real estate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With