diff --git a/doc/emacs/dired.texi b/doc/emacs/dired.texi index 9f454ea2ad6..4ada2a8df4f 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 eac7a7f6947..efe25014636 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 ea1943de1db..ce82093bf09 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.