我刚刚在维基百科上看到了这个可怕的模式屏幕。我正在研究这些定制。
关于颜色,我想只要指定正确的面孔就可以了,但是我如何才能在默认情况下显示以千字节为单位的文件?以及以 MB 为单位的可用空间(顶线)?
我提出了同样的问题,并找到了如何即时更改开关。
所以在一个干涸的缓冲区中
C-u s
您现在可以更改 ls 使用的开关。添加h
做得到人类可读的文件大小
您也可以添加其他开关,例如我将其更改为-alsh
现在按文件大小排序
要以千字节为单位获取文件大小,您可以自定义变量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)))))
实际上,该截图几乎可以肯定是Dired+的,尽管随附的文字给人的印象是它来自 vanilla Emacs(XEmacs?),并且截图的署名是“Emacs 开发团队”。
所以是的,答案是您可以通过使用Dired+并简单地自定义默认面来轻松获得该外观:M-x customize-group Dired-Plus
.
你没有问,但我想我会补充......
我希望能够轻松地按大小和扩展名以及名称和时间对 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))
此外,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))))))
(它只是在格式字符串中将 9.0 替换为 11.0,将 8.0 替换为 10.0)