From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#22829: Acknowledgement (25.1.50; Display number of marked files) Date: Wed, 02 Mar 2016 02:32:39 +0200 Organization: LINKOV.NET Message-ID: <87fuw9203w.fsf@mail.linkov.net> References: <87mvqlv1h4.fsf@gnus.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1456878866 5518 80.91.229.3 (2 Mar 2016 00:34:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 2 Mar 2016 00:34:26 +0000 (UTC) Cc: Lars Ingebrigtsen , 22829@debbugs.gnu.org To: Tino Calancha Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Mar 02 01:34:15 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 1aaujz-0004wz-W1 for geb-bug-gnu-emacs@m.gmane.org; Wed, 02 Mar 2016 01:34:12 +0100 Original-Received: from localhost ([::1]:53323 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aaujz-0003LJ-Hg for geb-bug-gnu-emacs@m.gmane.org; Tue, 01 Mar 2016 19:34:11 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35022) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aaujv-0003Jm-3F for bug-gnu-emacs@gnu.org; Tue, 01 Mar 2016 19:34:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aaujq-0003eQ-2I for bug-gnu-emacs@gnu.org; Tue, 01 Mar 2016 19:34:07 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:59707) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aaujp-0003eH-V7 for bug-gnu-emacs@gnu.org; Tue, 01 Mar 2016 19:34:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84) (envelope-from ) id 1aaujp-00057s-Nb for bug-gnu-emacs@gnu.org; Tue, 01 Mar 2016 19:34:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 02 Mar 2016 00:34:01 +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 Original-Received: via spool by 22829-submit@debbugs.gnu.org id=B22829.145687881919676 (code B ref 22829); Wed, 02 Mar 2016 00:34:01 +0000 Original-Received: (at 22829) by debbugs.gnu.org; 2 Mar 2016 00:33:39 +0000 Original-Received: from localhost ([127.0.0.1]:56834 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aaujS-00057H-Mi for submit@debbugs.gnu.org; Tue, 01 Mar 2016 19:33:38 -0500 Original-Received: from sub3.mail.dreamhost.com ([69.163.253.7]:59865 helo=homiemail-a101.g.dreamhost.com) by debbugs.gnu.org with esmtp (Exim 4.84) (envelope-from ) id 1aaujQ-000579-Cp for 22829@debbugs.gnu.org; Tue, 01 Mar 2016 19:33:36 -0500 Original-Received: from homiemail-a101.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a101.g.dreamhost.com (Postfix) with ESMTP id DF83D117E06A; Tue, 1 Mar 2016 16:33:34 -0800 (PST) Original-Received: from localhost.linkov.net (82.131.10.45.cable.starman.ee [82.131.10.45]) (Authenticated sender: jurta@jurta.org) by homiemail-a101.g.dreamhost.com (Postfix) with ESMTPA id A21BB117E065; Tue, 1 Mar 2016 16:33:33 -0800 (PST) In-Reply-To: (Tino Calancha's message of "Sun, 28 Feb 2016 15:36:48 +0900 (JST)") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.91 (x86_64-pc-linux-gnu) 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:114278 Archived-At: >> And I'm not sure I'm feeling the utility of this function, either. >> What's the use case? > > For those marking files in several directories quite often, and using > dired-change-marks to separate files in different categories: those > people may be interested in counting number of marked files. I need > this every day, but I agree not too many people would find it useful. I confirm this is very useful. I'm using the same for a long time, but additionally also displaying a total sum of sizes on every mark (this emulates the behavior of File Commanders on marking files by INS). The code I'm using in ~/.emacs is very very old, and nowadays you could implement the same with less code. ;; 2 new functions: (defun dired-get-file-info () "Get file info files for which PREDICATE returns non-nil." ;; code for this function is borrowed from dired-x.el::dired-mark-sexp (let (inode s mode nlink uid gid size time name sym) (save-excursion (if (dired-move-to-filename) (let (pos (mode-len 10) (dired-re-inode-size "\\s *\\([0-9]*\\)\\s *\\([0-9]*\\) ?")) (beginning-of-line) (forward-char 2) (if (looking-at dired-re-inode-size) (progn (goto-char (match-end 0)) (setq inode (string-to-int (buffer-substring (match-beginning 1) (match-end 1))) s (string-to-int (buffer-substring (match-beginning 2) (match-end 2))))) (setq inode nil s nil)) (setq mode (buffer-substring (point) (+ mode-len (point)))) (forward-char mode-len) (setq nlink (read (current-buffer))) (setq uid (buffer-substring (+ (point) 1) (progn (forward-word 1) (point)))) ;; works only with ls patch ;; patched in dired.el:dired-move-to-filename-regexp ;; (re-search-forward "\\([0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]\\)") ;; try standard expression (re-search-forward directory-listing-before-filename-regexp) (goto-char (match-beginning 2)) (forward-char -1) (setq size (string-to-int (replace-regexp-in-string ;; handle thousand separators in sizes "," "" (buffer-substring (save-excursion ;; (backward-word 1) (skip-chars-backward "[0-9,.]") (setq pos (point))) (point))))) (goto-char pos) (backward-word 1) (setq gid (buffer-substring (save-excursion (forward-word 1) (point)) (point)) time (buffer-substring (match-beginning 1) (1- (dired-move-to-filename))) name (buffer-substring (point) (or (dired-move-to-end-of-filename t) (point))) sym (progn (if (looking-at " -> ") (buffer-substring (progn (forward-char 4) (point)) (progn (end-of-line) (point))) ""))) (list (cons 'inode inode) (cons 's s) (cons 'mode mode) (cons 'nlink nlink) (cons 'uid uid) (cons 'gid gid) (cons 'size size) (cons 'time time) (cons 'name name) (cons 'sym sym))) nil)))) ;; TODO: use `pint2hrstr' in Lisp (defun dired-count-sizes (&optional mark) "Count sizes of files marked by MARK mark." ;; 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) (mark (progn (message "Count files marked by mark: ") (read-char)))) (list mark))) (if (or (eq mark ?\r)) (ding) (let ((string (format "\n%c" mark)) (buffer-read-only) (total-size 0) total-size-str (total-count 0)) (save-excursion (goto-char (point-min)) (while (search-forward string nil t) (if (if (= mark ?\ ) (save-match-data (dired-get-filename 'no-dir t)) t) (if (equal (buffer-substring-no-properties (match-beginning 0) (match-end 0)) string) (setq total-size (+ total-size (*;;(/ (cdr (assoc 'size (dired-get-file-info))) 1.0);;1024) ) total-count (+ total-count 1)))))) (setq total-size-str (replace-regexp-in-string "^," "" (apply 'string (reverse (string-to-list (replace-regexp-in-string "\\([0-9]\\{3\\}\\)" "\\1," (apply 'string (reverse (string-to-list (replace-regexp-in-string "\.0$" "" (number-to-string total-size))))))))))) (message "Marked %s files with %s bytes" total-count total-size-str)))) (define-key dired-mode-map [(shift f5)] 'dired-count-sizes) (defun my-dired-mark (arg) "Mark ARG files and print the total size of marked files." (interactive "P") (dired-mark arg) (dired-count-sizes dired-marker-char)) (define-key dired-mode-map [insert] 'my-dired-mark) (defun my-dired-unmark-backward (arg) "Move up lines, remove deletion flag there and print size of marked files." (interactive "p") (dired-unmark-backward arg) (dired-count-sizes dired-marker-char)) (define-key dired-mode-map [backspace] 'my-dired-unmark-backward)