From: Tino Calancha <f92capac@gmail.com>
To: 22829@debbugs.gnu.org
Cc: f92capac@gmail.com, juri@linkov.net
Subject: bug#22829: Acknowledgement (25.1.50; Display number of marked files)
Date: Tue, 8 Mar 2016 19:20:15 +0900 (JST) [thread overview]
Message-ID: <alpine.LRH.2.20.1603081910500.7709@calancha-ilc.kek.jp> (raw)
In-Reply-To: <874mcjjfs8.fsf@mail.linkov.net>
> Thank you! I have a feeling that code could be optimized more before
> installing to dired. I'll check it to estimate how well it works.
Please, test the latest `my-dired-count-sizes-opt3' (at the end of
the comments):
*) Added the tramp handlers to make this work on remote directories.
*) `du' receives all the directories at once.
> One quick comment: in defcustom my-dired-used-space-program
> you could find if an executable exists like:
>
> (defcustom my-dired-used-space-program (and (executable-find "du") du")
Thank you.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Following code requires the patch on Bug#22893
(defcustom my-dired-used-space-program
(purecopy (let ((opts (if (string-prefix-p "gnu" (symbol-name system-type))
"-sb"
"-sk"))) ; -k overestimate used space for files w/ size < 1024
(cond ((executable-find "du") (list "du" opts))
((file-executable-p "/usr/sbin/du") (list "/usr/sbin/du" opts))
((file-executable-p "/etc/du") (list "/etc/du" opts))
(t (list "du" opts)))))
"Program and its options to get recursively the total size of a directory.
We assume the output has the format of `du'.
A value of nil disables this feature."
:type '(list (string :tag "Program")
(repeat :tag "Options"
:inline t
(stting :format "%v")))
:group 'dired)
(defun my-dired-count-sizes-opt3 (&optional mark ask include-dirs)
"Count sizes of files marked by MARK mark.
When ASK non-nil user is prompted for MARK. Otherwise `dired-marker-char'
is used.
Optional arg INCLUDE-DIRS, if non-nil, run `my-dired-used-space-program'
on the markd directories. Otherwise the size of the directories is
not included."
;; TODO: add this info to mode-line and file count too, e.g.: F32 S64k
;; and make minor mode
;; see `dired-change-marks'
(interactive
(let* ((cursor-in-echo-area t)
(default current-prefix-arg)
(mark (or (and default (progn (message "Count files marked with mark: ")
(read-char)))
dired-marker-char))
(dirs (and default (car my-dired-used-space-program) (y-or-n-p "Include directories? "))))
(list mark t dirs)))
(unless mark (setq mark dired-marker-char))
;; If `my-dired-used-space-program' not available signal an error.
(when (and include-dirs
(not (equal 0 (condition-case nil
(process-file (car my-dired-used-space-program) nil nil nil null-device)
(error nil)))))
(error "Program `my-dired-used-space-program' not found"))
(require 'cl-lib) ; for cl-remove-if and cl-nset-difference
(if (eq mark ?\r)
(progn
(message "Mark cannot be \\r")
(sit-for 1)
(ding))
(let* ((files (dired-get-marked-files nil nil nil t mark))
(num-files (or (and (not (cdr files)) 0)
(and (equal t (car files)) (pop files) 1)
(length files)))
(non-dirs (cl-remove-if (lambda(x) (eq (car (file-attributes x)) t)) files))
(total-size (apply '+ (mapcar (lambda(x) (elt x 7))
(mapcar 'file-attributes non-dirs))))
(dirs (cl-nset-difference files non-dirs :test 'equal))
(num-dirs (length dirs))
(num-non-dirs (- num-files num-dirs))
(handler (and dirs (find-file-name-handler (car dirs) 'call-process)))
total-size-str)
(when (and include-dirs (not (= num-dirs 0)))
(let ((size 0)
(scale-factor (if (string= (cadr my-dired-used-space-program) "-sk")
1024.0
1.0)))
(with-temp-buffer
(if handler
(apply handler 'process-file (car my-dired-used-space-program)
nil t nil
(cadr my-dired-used-space-program)
(mapcar 'file-name-nondirectory dirs))
(apply 'process-file (car my-dired-used-space-program)
nil t nil
(cadr my-dired-used-space-program) dirs))
(goto-char 1)
(while (search-forward-regexp "^[0-9]+" nil t)
(setq size (+ size (string-to-number (match-string 0))))))
(setq total-size (+ total-size (* scale-factor size)))))
(setq total-size-str (if my-dired-human-readable
(file-size-human-readable total-size)
(my-dired-use-comma-separator total-size)))
(if (= num-files 0)
(message "No marked files with mark '%s'" (char-to-string mark))
(message "Marked %d %s (%d non-dirs/%d dirs) with '%s' and total size %s%s%s"
num-files
(or (and (= num-files 1) "file") "files")
num-non-dirs
num-dirs
(char-to-string mark)
total-size-str
(or (and my-dired-human-readable "") " bytes")
(or (and (not include-dirs) " (dirs size excluded)") ""))))))
(define-key dired-mode-map (kbd "*N") 'my-dired-count-sizes-opt3)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
next prev parent reply other threads:[~2016-03-08 10:20 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-27 14:29 bug#22829: 25.1.50; Display number of marked files Tino Calancha
[not found] ` <handler.22829.B.145658318020704.ack@debbugs.gnu.org>
2016-02-27 14:41 ` bug#22829: Acknowledgement (25.1.50; Display number of marked files) Tino Calancha
2016-02-28 5:38 ` Lars Ingebrigtsen
2016-02-28 6:36 ` Tino Calancha
2016-03-02 0:32 ` Juri Linkov
2016-03-02 17:28 ` Lars Ingebrigtsen
2016-03-02 20:04 ` Marcin Borkowski
2016-03-03 0:17 ` Juri Linkov
2016-03-03 5:52 ` Lars Ingebrigtsen
2016-03-03 11:20 ` Richard Stallman
2016-03-03 11:25 ` Lars Ingebrigtsen
2019-06-25 14:29 ` Lars Ingebrigtsen
2016-03-03 9:58 ` Tino Calancha
2016-03-03 12:27 ` Michael Heerdegen
2016-03-03 12:55 ` Constantino Calancha
2019-06-25 14:29 ` Lars Ingebrigtsen
2016-03-07 0:04 ` Juri Linkov
2016-03-08 10:20 ` Tino Calancha [this message]
2016-03-08 0:19 ` Juri Linkov
2016-03-08 10:34 ` Tino Calancha
2016-03-09 16:37 ` Richard Stallman
2016-03-01 11:26 ` bug#22829: 25.1.50; Display number of marked files Constantino Calancha
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.LRH.2.20.1603081910500.7709@calancha-ilc.kek.jp \
--to=f92capac@gmail.com \
--cc=22829@debbugs.gnu.org \
--cc=juri@linkov.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.