emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master b26c276 2/2: Add a new command to report the number


From: Lars Ingebrigtsen
Subject: [Emacs-diffs] master b26c276 2/2: Add a new command to report the number and size of the marked files
Date: Tue, 25 Jun 2019 10:31:30 -0400 (EDT)

branch: master
commit b26c2767edd98787297879c4570a2702eef031be
Author: Lars Ingebrigtsen <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>

    Add a new command to report the number and size of the marked files
    
    2019-06-25  Constantino Calancha  <address@hidden>
    
        * lisp/dired.el (dired-mode-map): New keystroke and menu binding
        (bug#22829).
    
    2019-06-25  Lars Ingebrigtsen  <address@hidden>
    
        * doc/emacs/dired.texi (Marks vs Flags): Document it.
    
        * lisp/dired.el (dired-number-of-marked-files): New command.
---
 doc/emacs/dired.texi |  6 ++++++
 etc/NEWS             |  4 ++++
 lisp/dired.el        | 28 ++++++++++++++++++++++++++++
 3 files changed, 38 insertions(+)

diff --git a/doc/emacs/dired.texi b/doc/emacs/dired.texi
index 9f454ea..4ada2a8 100644
--- a/doc/emacs/dired.texi
+++ b/doc/emacs/dired.texi
@@ -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
diff --git a/etc/NEWS b/etc/NEWS
index eac7a7f..efe2501 100644
--- 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'.
diff --git a/lisp/dired.el b/lisp/dired.el
index ea1943d..ce82093 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]