15

ウィキペディアでこのdired モードの画面に出くわしました。そちらのカスタマイズを検討中です。

色に関しては、正しい顔を指定するだけで十分だと思いますが、デフォルトでファイルサイズをキロバイトで表示するにはどうすればよいですか? MB 単位の空き容量 (一番上の行) は?

4

5 に答える 5

19

私は同じ問題を思いつき、その場でスイッチを変更する方法を見つけました。

したがって、dired バッファにいる間

C-u s

ls が使用するスイッチを変更できるようになりました。人間hが読めるファイルサイズを取得する

他のスイッチも追加できます。たとえば、に変更する-alshと、ファイルサイズでソートされるようになりました

于 2013-04-15T10:27:42.850 に答える
14

ファイル サイズを KB 単位で取得するには、オプション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)))))
于 2010-05-18T16:13:58.823 に答える
8

実際、そのスクリーンショットはほぼ確実にDired+のものですが、付随するテキストはバニラ Emacs (XEmacs?) からのものであるという印象を与え、スクリーンショットの帰属は「Emacs 開発チーム」です。

そうです、答えは、Dired+を使用してデフォルトの顔をカスタマイズするだけで、その外観を簡単に取得できるということですM-x customize-group Dired-Plus

于 2011-08-21T08:13:57.277 に答える
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))
于 2010-05-18T20:13:32.517 に答える
1

また、dired の表示では 9 スペースしか使用できないため、非常に大きなファイルの場合、dired の表示が乱れます。ここでも、fn を再定義する必要がありました。この場合、 ls-lisp.el からの 1 つ:

;; 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 に置き換えるだけです)

于 2010-05-18T20:17:48.500 に答える