aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ingebrigtsen2019-06-25 16:29:03 +0200
committerLars Ingebrigtsen2019-06-25 16:29:03 +0200
commitb26c2767edd98787297879c4570a2702eef031be (patch)
treedb03a45239248e3c296b115366ef3b6ace374d93
parent9e81b22113de41ba80df9c5a7aaf08a056180785 (diff)
downloademacs-b26c2767edd98787297879c4570a2702eef031be.tar.gz
emacs-b26c2767edd98787297879c4570a2702eef031be.zip
Add a new command to report the number and size of the marked files
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.
-rw-r--r--doc/emacs/dired.texi6
-rw-r--r--etc/NEWS4
-rw-r--r--lisp/dired.el28
3 files changed, 38 insertions, 0 deletions
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
435header line (@pxref{Subdirectories in Dired}), this command marks all 435header line (@pxref{Subdirectories in Dired}), this command marks all
436the files in that subdirectory. 436the files in that subdirectory.
437 437
438@item * N
439@kindex * N @r{(Dired)}
440@findex dired-number-of-marked-files
441Report what the number and size of the marked files are
442(@code{dired-number-of-marked-files}).
443
438@item * * 444@item * *
439@kindex * * @r{(Dired)} 445@kindex * * @r{(Dired)}
440@findex dired-mark-executables 446@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.
607+++ 607+++
608*** New command 'dired-create-empty-file'. 608*** New command 'dired-create-empty-file'.
609 609
610+++
611*** New command and keystroke `dired-number-of-marked-files' bound to
612`* N'.
613
610** Find-Dired 614** Find-Dired
611 615
612*** New customizable variable 'find-dired-refine-function'. 616*** 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."
1669 (define-key map "*/" 'dired-mark-directories) 1669 (define-key map "*/" 'dired-mark-directories)
1670 (define-key map "*@" 'dired-mark-symlinks) 1670 (define-key map "*@" 'dired-mark-symlinks)
1671 (define-key map "*%" 'dired-mark-files-regexp) 1671 (define-key map "*%" 'dired-mark-files-regexp)
1672 (define-key map "*N" 'dired-number-of-marked-files)
1672 (define-key map "*c" 'dired-change-marks) 1673 (define-key map "*c" 'dired-change-marks)
1673 (define-key map "*s" 'dired-mark-subdir-files) 1674 (define-key map "*s" 'dired-mark-subdir-files)
1674 (define-key map "*m" 'dired-mark) 1675 (define-key map "*m" 'dired-mark)
@@ -1815,6 +1816,9 @@ Do so according to the former subdir alist OLD-SUBDIR-ALIST."
1815 (define-key map [menu-bar immediate revert-buffer] 1816 (define-key map [menu-bar immediate revert-buffer]
1816 '(menu-item "Refresh" revert-buffer 1817 '(menu-item "Refresh" revert-buffer
1817 :help "Update contents of shown directories")) 1818 :help "Update contents of shown directories"))
1819 (define-key map [menu-bar immediate dired-number-of-marked-files]
1820 '(menu-item "#Marked Files" dired-number-of-marked-files
1821 :help "Display the number and size of the marked files"))
1818 1822
1819 (define-key map [menu-bar immediate dashes] 1823 (define-key map [menu-bar immediate dashes]
1820 '("--")) 1824 '("--"))
@@ -3607,6 +3611,30 @@ object files--just `.o' will mark more than you might think."
3607 (and fn (string-match-p regexp fn)))) 3611 (and fn (string-match-p regexp fn))))
3608 "matching file"))) 3612 "matching file")))
3609 3613
3614(defun dired-number-of-marked-files ()
3615 "Display the number and total size of the marked files."
3616 (interactive)
3617 (let* ((files (dired-get-marked-files nil nil nil t))
3618 (nmarked
3619 (cond ((null (cdr files))
3620 0)
3621 ((and (= (length files) 2)
3622 (eq (car files) t))
3623 1)
3624 (t
3625 (length files))))
3626 (size (cl-loop for file in files
3627 when (stringp file)
3628 sum (file-attribute-size (file-attributes file)))))
3629 (if (zerop nmarked)
3630 (message "No marked files"))
3631 (message "%d marked file%s (%sB total size)"
3632 nmarked
3633 (if (= nmarked 1)
3634 ""
3635 "s")
3636 (file-size-human-readable size))))
3637
3610(defun dired-mark-files-containing-regexp (regexp &optional marker-char) 3638(defun dired-mark-files-containing-regexp (regexp &optional marker-char)
3611 "Mark all files with contents containing REGEXP for use in later commands. 3639 "Mark all files with contents containing REGEXP for use in later commands.
3612A prefix argument means to unmark them instead. 3640A prefix argument means to unmark them instead.