我刚刚在维基百科上看到了这个dired mode screen。我正在研究那些自定义。
关于颜色,我想只是指定正确的面,但是如何默认显示以KB为单位的文件?以MB为单位的可用空间(顶行)?
答案 0 :(得分:19)
我想出了同样的问题,并找到了如何动态改变开关。
所以在一个直接缓冲区中
C-u s
您现在可以更改ls使用的开关。添加h
确实获得人类可读的文件大小
您也可以添加其他开关,例如我将其更改为-alsh
,现在按文件大小排序
答案 1 :(得分:14)
要获取以千字节为单位的文件大小,您可以自定义变量dired-listing-switches
以使用-k
选项:
(setq dired-listing-switches "-alk")
你需要做更多的工作来获得以MB为单位的总数/可用数。这适用于我的Linux系统,但可用部分无法在我的Windows机器上运行:
(setq directory-free-space-args "-Pm")
(defadvice insert-directory (after insert-directory-adjust-total-by-1024 activate)
"modify the total number by dividing it by 1024"
(save-excursion
(save-match-data
(goto-char (point-min))
(when (re-search-forward "^ *total used in directory \\([0-9]+\\) ")
(replace-match (number-to-string (/ (string-to-number (match-string 1)) 1024)) nil nil nil 1)))))
答案 2 :(得分:8)
实际上,该截图几乎肯定是 Dired+ ,但附带的文字给人的印象是它来自香草Emacs(XEmacs?),以及截图的归属是“Emacs开发团队”。
所以是的,答案是你可以通过使用 Dired + 轻松获得外观,只需自定义默认面孔:M-x customize-group Dired-Plus
。
答案 3 :(得分:4)
你没有问,但我想我会补充....
我希望能够通过大小和扩展名以及名称和时间轻松地对dired输出进行排序。我知道我可以使用M-x universal-argument dired-sort-toggle-or-edit
执行此操作,但我希望它可以在s
键上使用以快速完成。
;; Redefine the sorting in dired to flip between sorting on name, size,
;; time, and extension, rather than simply on name and time.
(defun dired-sort-toggle ()
;; Toggle between sort by date/name. Reverts the buffer.
(setq dired-actual-switches
(let (case-fold-search)
(cond
((string-match " " dired-actual-switches) ;; contains a space
;; New toggle scheme: add/remove a trailing " -t" " -S",
;; or " -U"
(cond
((string-match " -t\\'" dired-actual-switches)
(concat
(substring dired-actual-switches 0 (match-beginning 0))
" -X"))
((string-match " -X\\'" dired-actual-switches)
(concat
(substring dired-actual-switches 0 (match-beginning 0))
" -S"))
((string-match " -S\\'" dired-actual-switches)
(substring dired-actual-switches 0 (match-beginning 0)))
(t
(concat dired-actual-switches " -t"))))
(t
;; old toggle scheme: look for a sorting switch, one of [tUXS]
;; and switch between them. Assume there is only ONE present.
(let* ((old-sorting-switch
(if (string-match (concat "[t" dired-ls-sorting-switches "]")
dired-actual-switches)
(substring dired-actual-switches (match-beginning 0)
(match-end 0))
""))
(new-sorting-switch
(cond
((string= old-sorting-switch "t")
"X")
((string= old-sorting-switch "X")
"S")
((string= old-sorting-switch "S")
"")
(t
"t"))))
(concat
"-l"
;; strip -l and any sorting switches
(dired-replace-in-string (concat "[-lt"
dired-ls-sorting-switches "]")
""
dired-actual-switches)
new-sorting-switch))))))
(dired-sort-set-modeline)
(revert-buffer))
答案 4 :(得分:1)
此外,dired中的显示只允许9个空格,因此对于非常大的文件,dired中的显示将变得混乱。再次需要重新定义fn。在这种情况下,来自ls-lisp.el:
;; redefine this function, to fix the formatting of file sizes in dired mode
(defun ls-lisp-format-file-size (file-size human-readable)
(if (or (not human-readable)
(< file-size 1024))
(format (if (floatp file-size) " %11.0f" " %11d") file-size)
(do ((file-size (/ file-size 1024.0) (/ file-size 1024.0))
;; kilo, mega, giga, tera, peta, exa
(post-fixes (list "k" "M" "G" "T" "P" "E") (cdr post-fixes)))
((< file-size 1024) (format " %10.0f%s" file-size (car post-fixes))))))
(它只是用一个11.0替换9.0,用格式字符串替换8.0和10.0)