From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.bugs Subject: bug#22829: Acknowledgement (25.1.50; Display number of marked files) Date: Tue, 8 Mar 2016 19:20:15 +0900 (JST) Message-ID: References: <87mvqlv1h4.fsf@gnus.org> <87fuw9203w.fsf@mail.linkov.net> <874mcjjfs8.fsf@mail.linkov.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII X-Trace: ger.gmane.org 1457432308 32685 80.91.229.3 (8 Mar 2016 10:18:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 8 Mar 2016 10:18:28 +0000 (UTC) Cc: f92capac@gmail.com, juri@linkov.net To: 22829@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Mar 08 11:18:21 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1adEiZ-0005aD-8V for geb-bug-gnu-emacs@m.gmane.org; Tue, 08 Mar 2016 11:18:19 +0100 Original-Received: from localhost ([::1]:33532 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adEiQ-0005eC-91 for geb-bug-gnu-emacs@m.gmane.org; Tue, 08 Mar 2016 05:18:10 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39532) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adEiL-0005e3-VS for bug-gnu-emacs@gnu.org; Tue, 08 Mar 2016 05:18:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1adEiI-0003h9-Op for bug-gnu-emacs@gnu.org; Tue, 08 Mar 2016 05:18:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:41529) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adEiI-0003gu-Lm for bug-gnu-emacs@gnu.org; Tue, 08 Mar 2016 05:18:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84) (envelope-from ) id 1adEiI-0007RK-I9 for bug-gnu-emacs@gnu.org; Tue, 08 Mar 2016 05:18:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 08 Mar 2016 10:18:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 22829 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-Cc: Tino Calancha , 22829@debbugs.gnu.org, Juri Linkov Original-Received: via spool by 22829-submit@debbugs.gnu.org id=B22829.145743222828537 (code B ref 22829); Tue, 08 Mar 2016 10:18:02 +0000 Original-Received: (at 22829) by debbugs.gnu.org; 8 Mar 2016 10:17:08 +0000 Original-Received: from localhost ([127.0.0.1]:38656 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1adEhQ-0007QD-1q for submit@debbugs.gnu.org; Tue, 08 Mar 2016 05:17:08 -0500 Original-Received: from calancha-ilc.kek.jp ([130.87.234.234]:58831) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1adEhO-0007Pf-NE for 22829@debbugs.gnu.org; Tue, 08 Mar 2016 05:17:07 -0500 Original-Received: by calancha-ilc.kek.jp (Postfix, from userid 500) id 0D0E4DA86; Tue, 8 Mar 2016 19:20:15 +0900 (JST) Original-Received: from localhost (localhost [127.0.0.1]) by calancha-ilc.kek.jp (Postfix) with ESMTP id EA6FB642E; Tue, 8 Mar 2016 19:20:15 +0900 (JST) X-X-Sender: calancha@calancha-ilc.kek.jp In-Reply-To: <874mcjjfs8.fsf@mail.linkov.net> User-Agent: Alpine 2.20 (LRH 67 2015-01-07) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:114566 Archived-At: > 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) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;