【发布时间】:2010-05-18 14:20:50
【问题描述】:
我刚刚在 Wikipedia 上看到了这个 dired mode screen。我正在研究这些定制。
关于颜色,我想只要指定正确的面孔就可以了,但我如何才能在默认情况下显示以千字节为单位的文件?以及以 MB 为单位的可用空间(顶行)?
【问题讨论】:
-
对这些颜色使用 dired+ 或 diredfl。
我刚刚在 Wikipedia 上看到了这个 dired mode screen。我正在研究这些定制。
关于颜色,我想只要指定正确的面孔就可以了,但我如何才能在默认情况下显示以千字节为单位的文件?以及以 MB 为单位的可用空间(顶行)?
【问题讨论】:
实际上,该屏幕截图几乎可以肯定是 Dired+,尽管随附的文字给人的印象是它来自 vanilla Emacs(XEmacs?),以及归属地截图是“Emacs 开发团队”。
所以是的,答案是您可以轻松获得该外观,只需使用 Dired+ 并简单地自定义默认面孔:M-x customize-group Dired-Plus。
【讨论】:
要获取以千字节为单位的文件大小,您可以自定义变量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)))))
【讨论】:
h 选项具有人类可读性,它不使用恒定大小(如请求一样)。总的来说,我确实喜欢h。
我遇到了同样的问题,并找到了如何即时更改开关。
所以在一个dired缓冲区中
C-u s
您现在可以更改 ls 使用的开关。添加h 获取人类可读的文件大小
您也可以添加其他开关,例如我将其更改为-alsh,现在它按文件大小排序
【讨论】:
describe-key 停在 C-u,所以它返回 universal-argument。
dired-sort-toggle-or-edit。在 dired 缓冲区中执行 C-x k 然后 s。您确实将通用参数 u 发送到 dired-sort-toggle-or-edit
你没有问,但我想我会补充......
我希望能够轻松地按大小和扩展名以及名称和时间对 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)
【讨论】: