]> git.eshelyaron.com Git - emacs.git/commitdiff
Add a new command to report the number and size of the marked files
authorLars Ingebrigtsen <larsi@gnus.org>
Tue, 25 Jun 2019 14:29:03 +0000 (16:29 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Tue, 25 Jun 2019 14:29:03 +0000 (16:29 +0200)
2019-06-25  Constantino Calancha  <f92capac@gmail.com>

* lisp/dired.el (dired-mode-map): New keystroke and menu binding
(bug#22829).

2019-06-25  Lars Ingebrigtsen  <larsi@gnus.org>

* doc/emacs/dired.texi (Marks vs Flags): Document it.

* lisp/dired.el (dired-number-of-marked-files): New command.

doc/emacs/dired.texi
etc/NEWS
lisp/dired.el

index 9f454ea2ad69414333fc4ded694713af621a472d..4ada2a8df4f05b23823e6b0ee66a4086902c7129 100644 (file)
@@ -435,6 +435,12 @@ the previous @minus{}@var{n} files).  If invoked on a subdirectory
 header line (@pxref{Subdirectories in Dired}), this command marks all
 the files in that subdirectory.
 
+@item * N
+@kindex * N @r{(Dired)}
+@findex dired-number-of-marked-files
+Report what the number and size of the marked files are
+(@code{dired-number-of-marked-files}).
+
 @item * *
 @kindex * * @r{(Dired)}
 @findex dired-mark-executables
index eac7a7f6947591392348ca8dc39e7e45ac05f5cb..efe250146368455a7c29d911f117106d32d10665 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -607,6 +607,10 @@ remapped to these, respectively.
 +++
 *** New command 'dired-create-empty-file'.
 
++++
+*** New command and keystroke `dired-number-of-marked-files' bound to
+`* N'.
+
 ** Find-Dired
 
 *** New customizable variable 'find-dired-refine-function'.
index ea1943de1db24065b5c3dc6c9626d7ace7d6d26d..ce82093bf09bcfd55dd5c97dacfc38e433365cfd 100644 (file)
@@ -1669,6 +1669,7 @@ Do so according to the former subdir alist OLD-SUBDIR-ALIST."
     (define-key map "*/" 'dired-mark-directories)
     (define-key map "*@" 'dired-mark-symlinks)
     (define-key map "*%" 'dired-mark-files-regexp)
+    (define-key map "*N" 'dired-number-of-marked-files)
     (define-key map "*c" 'dired-change-marks)
     (define-key map "*s" 'dired-mark-subdir-files)
     (define-key map "*m" 'dired-mark)
@@ -1815,6 +1816,9 @@ Do so according to the former subdir alist OLD-SUBDIR-ALIST."
     (define-key map [menu-bar immediate revert-buffer]
       '(menu-item "Refresh" revert-buffer
                  :help "Update contents of shown directories"))
+    (define-key map [menu-bar immediate dired-number-of-marked-files]
+      '(menu-item "#Marked Files" dired-number-of-marked-files
+                 :help "Display the number and size of the marked files"))
 
     (define-key map [menu-bar immediate dashes]
       '("--"))
@@ -3607,6 +3611,30 @@ object files--just `.o' will mark more than you might think."
            (and fn (string-match-p regexp fn))))
      "matching file")))
 
+(defun dired-number-of-marked-files ()
+  "Display the number and total size of the marked files."
+  (interactive)
+  (let* ((files (dired-get-marked-files nil nil nil t))
+         (nmarked
+          (cond ((null (cdr files))
+                 0)
+                ((and (= (length files) 2)
+                      (eq (car files) t))
+                 1)
+                (t
+                 (length files))))
+         (size (cl-loop for file in files
+                        when (stringp file)
+                        sum (file-attribute-size (file-attributes file)))))
+    (if (zerop nmarked)
+        (message "No marked files"))
+    (message "%d marked file%s (%sB total size)"
+             nmarked
+             (if (= nmarked 1)
+                 ""
+               "s")
+             (file-size-human-readable size))))
+
 (defun dired-mark-files-containing-regexp (regexp &optional marker-char)
   "Mark all files with contents containing REGEXP for use in later commands.
 A prefix argument means to unmark them instead.