Subject: Re: bug#22829: Acknowledgement (25.1.50; Display number of marked files)

From: Tino Calancha <[email-masked]>
Date: Sat, 27 Feb 2016 23:41:04 +0900 (JST)

Return the correct value when number of marked files equals 1.

diff --git a/lisp/dired.el b/lisp/dired.el
index 6c7445c..5814e55 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -1505,6 +1505,7 @@ dired-mode-map
     (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-marked-files)
     (define-key map "*c" 'dired-change-marks)
     (define-key map "*s" 'dired-mark-subdir-files)
     (define-key map "*m" 'dired-mark)
@@ -1651,6 +1652,9 @@ dired-mode-map
     (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-marked-files]
+      '(menu-item "#Marked Files" dired-number-marked-files
+		  :help "Display number of marked files"))
 
     (define-key map [menu-bar immediate dashes]
       '("--"))
@@ -3345,6 +3349,18 @@ dired-mark-files-regexp
 	    (and fn (string-match-p regexp fn))))
      "matching file")))
 
+(defun dired-number-marked-files()
+  "Display number of marked files"
+  (interactive)
+  (let* ((files   (dired-get-marked-files nil nil nil t))
+         (nmarked (length files)))
+    (cond ((null (cdr files))
+           (message "No marked files"))
+          ((and (= nmarked 2) (eq (car files) t))
+           (message "1 marked file") (1- nmarked))
+          (t
+           (message "%d marked files" nmarked) nmarked))))
+
 (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.