定制方向

发布于 2024-09-02 10:51:59 字数 220 浏览 9 评论 0原文

我刚刚在维基百科上看到了这个 dired 模式屏幕。我正在研究这些定制。

关于颜色,我想只要指定正确的面孔就可以了,但是我如何才能在默认情况下显示以千字节为单位的文件大小呢?可用空间(以 MB 为单位)(顶行)?

I just came across this dired mode screen at Wikipedia. I am looking into those customizations.

Regarding colors, I guess just specifying the correct faces will do, but how do I get dired to show file sized in kbytes by default? And the available space in MBs (top line)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

扛起拖把扫天下 2024-09-09 10:51:59

我遇到了同样的问题,并找到了如何动态更改开关。

因此,在 Dired 缓冲区

Cu s

中时,您现在可以更改 ls 使用的开关。添加 h 确实获得人类可读的文件大小

您也可以添加其他开关,例如我将其更改为 -alsh 现在它按文件大小排序

I came up with the same problem and found how to change swithes on the fly.

So while in a dired buffer

C-u s

you can now change switches used by ls. Add h do get a human readable file sizes

You can add other switches too, for example I changed it to -alsh and it now sorts by file size

橘虞初梦 2024-09-09 10:51:59

要获取以千字节为单位的文件大小,您可以自定义变量 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)))))

To get the file sizes in kbytes, you can customize the variable dired-listing-switches to use the -k option:

(setq dired-listing-switches "-alk")

You have to do a little more work to get the total/available numbers in MB. This worked on my Linux system, but the available portion failed to work on my Windows box:

(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)))))
心欲静而疯不止 2024-09-09 10:51:59

实际上,该屏幕截图几乎可以肯定是 Dired+,尽管附带的文字给人的印象是它来自普通的 Emacs(XEmacs?),并且屏幕截图的归属是“Emacs 开发团队”。

所以是的,答案是您可以通过使用 Dired+ 并简单地自定义默认面孔:Mxcustomize-group Dired-Plus 轻松获得该外观。

Actually, that screenshot is almost certainly of Dired+, though the accompanying text gives the impression that it is from vanilla Emacs (XEmacs?), and the attribution for the screenshot is "Emacs development team".

So yes, the answer is that you can easily get that appearance, by using Dired+ and simply customizing the default faces: M-x customize-group Dired-Plus.

夏至、离别 2024-09-09 10:51:59

你没有问,但我想我应该添加......

我希望能够轻松地按大小和扩展名以及名称和时间对 Dired 输出进行排序。我知道我可以使用 Mx 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))

You didn't ask, but I thought I'd add....

I wanted to be able to easily sort the dired output by size and extension, as well as name and time. I know I can do this with M-x universal-argument dired-sort-toggle-or-edit, but I wanted it available on the s key to make it quick.

;; 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))
慵挽 2024-09-09 10:51:59

另外,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)

Also, the display in dired allows only 9 spaces, so for very large files, the display in dired will get messed up. Once again that required redefining a fn. In this case, one from 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))))))

(it just replaces the 9.0 with an 11.0, and the 8.0 with a 10.0, in the format strings)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文