* bug#22829: 25.1.50; Display number of marked files @ 2016-02-27 14:29 Tino Calancha [not found] ` <handler.22829.B.145658318020704.ack@debbugs.gnu.org> 2016-03-01 11:26 ` bug#22829: 25.1.50; Display number of marked files Constantino Calancha 0 siblings, 2 replies; 22+ messages in thread From: Tino Calancha @ 2016-02-27 14:29 UTC (permalink / raw) To: 22829 [-- Attachment #1: Type: text/plain, Size: 241 bytes --] Added a function displaying the number of marked files in the minibuffer. Such function could be bound to 'N'. In GNU Emacs 25.1.50.1 (x86_64-pc-linux-gnu, GTK+ Version 2.24.29) Repository revision: 25c5651951ef39f650927652dac8b4bbfccb60fa [-- Attachment #2: Type: text/plain, Size: 1720 bytes --] diff --git a/lisp/dired.el b/lisp/dired.el index 6c7445c..314a701 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" nmarked) 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. ^ permalink raw reply related [flat|nested] 22+ messages in thread
[parent not found: <handler.22829.B.145658318020704.ack@debbugs.gnu.org>]
* bug#22829: Acknowledgement (25.1.50; Display number of marked files) [not found] ` <handler.22829.B.145658318020704.ack@debbugs.gnu.org> @ 2016-02-27 14:41 ` Tino Calancha 2016-02-28 5:38 ` Lars Ingebrigtsen 0 siblings, 1 reply; 22+ messages in thread From: Tino Calancha @ 2016-02-27 14:41 UTC (permalink / raw) To: 22829 [-- Attachment #1: Type: text/plain, Size: 65 bytes --] Return the correct value when number of marked files equals 1. [-- Attachment #2: Type: text/plain, Size: 1717 bytes --] 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. ^ permalink raw reply related [flat|nested] 22+ messages in thread
* bug#22829: Acknowledgement (25.1.50; Display number of marked files) 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 0 siblings, 1 reply; 22+ messages in thread From: Lars Ingebrigtsen @ 2016-02-28 5:38 UTC (permalink / raw) To: Tino Calancha; +Cc: 22829 Tino Calancha <f92capac@gmail.com> writes: > + (define-key map "N" 'dired-number-marked-files) [...] > +(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)))) And I'm not sure I'm feeling the utility of this function, either. What's the use case? -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no ^ permalink raw reply [flat|nested] 22+ messages in thread
* bug#22829: Acknowledgement (25.1.50; Display number of marked files) 2016-02-28 5:38 ` Lars Ingebrigtsen @ 2016-02-28 6:36 ` Tino Calancha 2016-03-02 0:32 ` Juri Linkov 0 siblings, 1 reply; 22+ messages in thread From: Tino Calancha @ 2016-02-28 6:36 UTC (permalink / raw) To: Lars Ingebrigtsen; +Cc: Tino Calancha, 22829 > 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. ^ permalink raw reply [flat|nested] 22+ messages in thread
* bug#22829: Acknowledgement (25.1.50; Display number of marked files) 2016-02-28 6:36 ` Tino Calancha @ 2016-03-02 0:32 ` Juri Linkov 2016-03-02 17:28 ` Lars Ingebrigtsen 2016-03-03 9:58 ` Tino Calancha 0 siblings, 2 replies; 22+ messages in thread From: Juri Linkov @ 2016-03-02 0:32 UTC (permalink / raw) To: Tino Calancha; +Cc: Lars Ingebrigtsen, 22829 >> 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) ^ permalink raw reply [flat|nested] 22+ messages in thread
* bug#22829: Acknowledgement (25.1.50; Display number of marked files) 2016-03-02 0:32 ` Juri Linkov @ 2016-03-02 17:28 ` Lars Ingebrigtsen 2016-03-02 20:04 ` Marcin Borkowski 2019-06-25 14:29 ` Lars Ingebrigtsen 2016-03-03 9:58 ` Tino Calancha 1 sibling, 2 replies; 22+ messages in thread From: Lars Ingebrigtsen @ 2016-03-02 17:28 UTC (permalink / raw) To: Juri Linkov; +Cc: Tino Calancha, 22829 Juri Linkov <juri@linkov.net> writes: > 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). This is beginning to sound more useful. :-) Including both the number of files and the total file size is something I could see myself wanting to have. Tino, could you amend your patch to do that, too? -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no ^ permalink raw reply [flat|nested] 22+ messages in thread
* bug#22829: Acknowledgement (25.1.50; Display number of marked files) 2016-03-02 17:28 ` Lars Ingebrigtsen @ 2016-03-02 20:04 ` Marcin Borkowski 2016-03-03 0:17 ` Juri Linkov 2019-06-25 14:29 ` Lars Ingebrigtsen 1 sibling, 1 reply; 22+ messages in thread From: Marcin Borkowski @ 2016-03-02 20:04 UTC (permalink / raw) To: Lars Ingebrigtsen; +Cc: Tino Calancha, 22829, Juri Linkov On 2016-03-02, at 18:28, Lars Ingebrigtsen <larsi@gnus.org> wrote: > Juri Linkov <juri@linkov.net> writes: > >> 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). > > This is beginning to sound more useful. :-) Including both the number > of files and the total file size is something I could see myself wanting > to have. +1. What about the size of directories are marked? I assume that it is to costly to include the recursively computed size...? Best, -- Marcin Borkowski http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski Faculty of Mathematics and Computer Science Adam Mickiewicz University ^ permalink raw reply [flat|nested] 22+ messages in thread
* bug#22829: Acknowledgement (25.1.50; Display number of marked files) 2016-03-02 20:04 ` Marcin Borkowski @ 2016-03-03 0:17 ` Juri Linkov 2016-03-03 5:52 ` Lars Ingebrigtsen 0 siblings, 1 reply; 22+ messages in thread From: Juri Linkov @ 2016-03-03 0:17 UTC (permalink / raw) To: Marcin Borkowski; +Cc: Tino Calancha, Lars Ingebrigtsen, 22829 >>> 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). >> >> This is beginning to sound more useful. :-) Including both the number >> of files and the total file size is something I could see myself wanting >> to have. > > +1. > > What about the size of directories are marked? I assume that it is to > costly to include the recursively computed size...? Yes, doing `du -sh` often takes soo long... But we could include sizes of subdirs only when called with a prefix arg. Oh, and I noticed that the proposed key 'N' is already bound to dired-man in dired-x.el. Another good mnemonic key would be '#', but it's taken as well. Than maybe put it on the marking prefix key '*'. ^ permalink raw reply [flat|nested] 22+ messages in thread
* bug#22829: Acknowledgement (25.1.50; Display number of marked files) 2016-03-03 0:17 ` Juri Linkov @ 2016-03-03 5:52 ` Lars Ingebrigtsen 2016-03-03 11:20 ` Richard Stallman 0 siblings, 1 reply; 22+ messages in thread From: Lars Ingebrigtsen @ 2016-03-03 5:52 UTC (permalink / raw) To: Juri Linkov; +Cc: Tino Calancha, Marcin Borkowski, 22829 Juri Linkov <juri@linkov.net> writes: > Yes, doing `du -sh` often takes soo long... But we could include sizes > of subdirs only when called with a prefix arg. I think the default should be to compute the sizes of files in the directories, too. Perhaps a prefix to not do that... -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no ^ permalink raw reply [flat|nested] 22+ messages in thread
* bug#22829: Acknowledgement (25.1.50; Display number of marked files) 2016-03-03 5:52 ` Lars Ingebrigtsen @ 2016-03-03 11:20 ` Richard Stallman 2016-03-03 11:25 ` Lars Ingebrigtsen 0 siblings, 1 reply; 22+ messages in thread From: Richard Stallman @ 2016-03-03 11:20 UTC (permalink / raw) To: Lars Ingebrigtsen; +Cc: f92capac, mbork, 22829, juri [[[ To any NSA and FBI agents reading my email: please consider ]]] [[[ whether defending the US Constitution against all enemies, ]]] [[[ foreign or domestic, requires you to follow Snowden's example. ]]] I am concerned that features like these might make Dired painfully slow in difficult cases such as a very large directory. If they are programmed to stop counting after a certain number of matches, that bad effect will be avoided. -- Dr Richard Stallman President, Free Software Foundation (gnu.org, fsf.org) Internet Hall-of-Famer (internethalloffame.org) Skype: No way! See stallman.org/skype.html. ^ permalink raw reply [flat|nested] 22+ messages in thread
* bug#22829: Acknowledgement (25.1.50; Display number of marked files) 2016-03-03 11:20 ` Richard Stallman @ 2016-03-03 11:25 ` Lars Ingebrigtsen 0 siblings, 0 replies; 22+ messages in thread From: Lars Ingebrigtsen @ 2016-03-03 11:25 UTC (permalink / raw) To: Richard Stallman; +Cc: f92capac, mbork, 22829, juri Richard Stallman <rms@gnu.org> writes: > I am concerned that features like these might make Dired painfully > slow in difficult cases such as a very large directory. If they are > programmed to stop counting after a certain number of matches, that > bad effect will be avoided. These are new interactive commands. They do not slow down anything. -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no ^ permalink raw reply [flat|nested] 22+ messages in thread
* bug#22829: Acknowledgement (25.1.50; Display number of marked files) 2016-03-02 17:28 ` Lars Ingebrigtsen 2016-03-02 20:04 ` Marcin Borkowski @ 2019-06-25 14:29 ` Lars Ingebrigtsen 1 sibling, 0 replies; 22+ messages in thread From: Lars Ingebrigtsen @ 2019-06-25 14:29 UTC (permalink / raw) To: Juri Linkov; +Cc: Tino Calancha, 22829 Lars Ingebrigtsen <larsi@gnus.org> writes: > Juri Linkov <juri@linkov.net> writes: > >> 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). > > This is beginning to sound more useful. :-) Including both the number > of files and the total file size is something I could see myself wanting > to have. > > Tino, could you amend your patch to do that, too? I did this, and have now committed to the Emacs trunk. -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no ^ permalink raw reply [flat|nested] 22+ messages in thread
* bug#22829: Acknowledgement (25.1.50; Display number of marked files) 2016-03-02 0:32 ` Juri Linkov 2016-03-02 17:28 ` Lars Ingebrigtsen @ 2016-03-03 9:58 ` Tino Calancha 2016-03-03 12:27 ` Michael Heerdegen ` (2 more replies) 1 sibling, 3 replies; 22+ messages in thread From: Tino Calancha @ 2016-03-03 9:58 UTC (permalink / raw) To: 22829 [-- Attachment #1: Type: text/plain, Size: 15423 bytes --] >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 Thank you Juri, I like very much your idea about showing the file sizes! If we modify `dired-get-marked-files' as in the Bug#22892 we can get in a straightforward way the file sizes from the file system. I include the modified version of your code after these comments. >What about the size of directories are marked? I assume that it is to >costly to include the recursively computed size...? Good idea. >This is beginning to sound more useful. :-) Sure, now is much better. >the proposed key 'N' is already bound to dired-man in dired-x.el. >Another good mnemonic key would be '#', but it's taken as well. >Than maybe put it on the marking prefix key '*'. I do like '*#', but i like 'N' more. We can also reconsider a bit about the keybinding 'N' for dired-man. Honestly i don't see the needs for this, having `man' and `woman' working nicely. Indeed, the funtion is not working as it should: (dired "/bin") j bash RET N bash RET Can’t find the /bin/bash manpage ;; Notice how i need to introduce 'bash' by hand, because the ;; interactive specification of this func. is just (interactive). ;; I don't expect anyone will complaint if we change 'N' binding here. >Yes, doing `du -sh` often takes soo long... But we could include sizes >of subdirs only when called with a prefix arg. >I think the default should be to compute the sizes of files in the >directories, too. Perhaps a prefix to not do that... I have included the subdir sizes as an option: currently the subdir sizes are not computed by default. We can change this behaviour to the opposite, with subdir sizes computed by default, after the code being well tested. There are two functions doing the same thing: * my-dired-count-sizes-opt1: * my-dired-count-sizes-opt2: This looks nicer but it requires cl-lib. Current implementation just works for local subdirectories. If the Dired buffer is visiting a remote directory we need to introduce some tramp handlers. I need support from tramp experts. In GNU Emacs 25.1.50.1 (x86_64-pc-linux-gnu, GTK+ Version 2.24.29) of 2016-03-03 built on calancha-pc Repository revision: 887f6126c5ce9084f93083765ac026ca6b28175c ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Following code requires the patch on Bug#22892 (defcustom my-dired-used-space-program "du" "Program to get recursively the total size of a directory We assume the output has the format of `du'. The value of this variable must be just a command name or file name; if you want to specify options, use `my-dired-used-space-args'. A value of nil disables this feature." :type '(choice (string :tag "Program") (const :tag "None" nil)) :group 'dired) ;; this var is not a defcustom because current implementation ;; of `my-dired-count-sizes-opt1' and `my-dired-count-sizes-opt2' expect ;; sizes in bytes; then, depending of the value `my-dired-human-readable' ;; those sizes and shown in human readable units or keep in byts. (defvar my-dired-used-space-args "-sk" "Options to use when running `my-dired-used-space-program'.") (defvar my-dired-human-readable nil "When Non-nil, `my-dired-count-sizes' display file sizes using `file-size-human-readable'.") (defun my-dired-toggle-human-readable () (interactive) (setq my-dired-human-readable (not my-dired-human-readable)) (let ((string (if my-dired-human-readable "Using human-readable units in `my-dired-count-sizes'" "Using comma separator in `my-dired-count-sizes'"))) (message string))) (defun my-dired-use-comma-separator (num) "Return number NUM as an string using comma separator" (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 num))))))))))) (defun my-dired-file-marked-with-char-p (&optional mark) "Return t if file at current line is marked with MARK When MARK nil, `dired-marked-char' is used. If MARK equals any, any marker is accepted." (let ((marker (cond ((null mark) (dired-marker-regexp)) ((characterp mark) (concat "^" (regexp-quote (char-to-string mark)))) (t (dired-marker-regexp 'all-marks))))) (save-excursion (forward-line 0) (looking-at-p marker)))) ;;; ;;; Doesn't require cl-lib ;;; (defun my-dired-count-sizes-opt1 (&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 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 my-dired-used-space-program nil nil nil null-device) (error nil))))) (error "Program `my-dired-used-space-program' not found")) (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)) (ndirectories 0) (nreg-files 0) (total-size (or (and (not (cdr files)) 0) (apply '+ (mapcar (lambda(fname-attrb) (let ((fname (car fname-attrb)) (attrb (cdr fname-attrb))) (if (eq (elt attrb 0) t) (progn (setq ndirectories (1+ ndirectories)) (if (not include-dirs) 0 (with-temp-buffer (call-process my-dired-used-space-program nil t nil my-dired-used-space-args fname) (goto-char 1) (search-forward-regexp "^[[:alnum:]]+" nil t) (* 1024.0 (string-to-number (match-string 0)))))) (setq nreg-files (1+ nreg-files)) (elt attrb 7)))) (mapcar (lambda(x) (cons x (file-attributes x))) (delq t files)))))) (total-size-str (if my-dired-human-readable (file-size-human-readable total-size) (my-dired-use-comma-separator total-size))) (total-count (if (eq (car files) t) 1 (length files)))) (if (null (cdr files)) (message "No marked files with mark '%s'" (char-to-string mark)) (message "Marked %s %s (%d non-dirs/%d dirs) with '%s' and total size %s%s%s" total-count (or (and (eq (car files) t) "file") "files") nreg-files ndirectories (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 [(shift f5)] 'my-dired-count-sizes-opt1) ;(define-key dired-mode-map (kbd "N") 'my-dired-count-sizes-opt1); dired-man (define-key dired-mode-map (kbd "*#") 'my-dired-count-sizes-opt1) ;;; ;;; Following function requires cl-lib ;;; (defun my-dired-count-sizes-opt2 (&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 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 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-set-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)) (non-dirs (cl-remove-if (lambda(x) (eq (car (file-attributes x)) t)) files)) (dirs (cl-set-difference files non-dirs :test 'equal)) (ndirectories (length dirs)) (nreg-files (length non-dirs)) (total-size (apply '+ (mapcar (lambda(x) (elt x 7)) (mapcar 'file-attributes (delq t non-dirs))))) total-size-str total-count) (when (and include-dirs (not (= ndirectories 0))) (let ((size 0)) (with-temp-buffer (apply 'call-process my-dired-used-space-program nil t nil my-dired-used-space-args dirs) (goto-char 1) (while (search-forward-regexp "^[[:alnum:]]+" nil t) (setq size (+ size (string-to-number (match-string 0)))))) (setq total-size (+ total-size (* 1024.0 size))))) (setq total-size-str (if my-dired-human-readable (file-size-human-readable total-size) (my-dired-use-comma-separator total-size)) total-count (if (eq (car files) t) 1 (length files))) (if (null (cdr files)) (message "No marked files with mark '%s'" (char-to-string mark)) (message "Marked %s %s (%d non-dirs/%d dirs) with '%s' and total size %s%s%s" total-count (or (and (eq (car files) t) "file") "files") nreg-files ndirectories (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 [(shift f5)] 'my-dired-count-sizes-opt2) ;; ;;(define-key dired-mode-map (kbd "N") 'my-dired-count-sizes-opt2); dired-man ;; (define-key dired-mode-map (kbd "*#") 'my-dired-count-sizes-opt2) ;; Bound for comparison with `my-dired-count-sizes-opt1' (bound to '*#') (define-key dired-mode-map (kbd "N") 'my-dired-count-sizes-opt2) (defun my-dired-mark (&optional arg mark) "Mark ARG files and print the total size of marked files In interactive calls, if ARG equals to '(4), the user is asked for arg and marker-char." (interactive (let* ((default current-prefix-arg) (mark (cond ((equal default '(4)) (progn (message "Mark files with mark: ") (read-char))) (t dired-marker-char))) (nfiles (and default (string-to-number (read-string "Number of files to mark: " nil nil "1"))))) (list (list nfiles) mark))) (let ((dired-marker-char (or mark dired-marker-char))) (dired-mark arg)) (my-dired-count-sizes mark)) (define-key dired-mode-map [insert] 'my-dired-mark) (defun my-dired-unmark-backward (&optional arg) "Move ARG up lines, remove deletion flag there and print size of marked files In interactive calls, if `current-prefix-arg' equals '(4), the user is prompt for ARG." (interactive (let* ((default current-prefix-arg) (nfiles (and (equal default '(4)) (string-to-number (read-string "Number of files to unmark: " nil nil "1"))))) (list (or nfiles 1)))) (let (files) (save-excursion (cond ((null arg) (dired-next-line -1) (push (dired-get-filename nil 'noerror) files)) ((or (numberp arg) (and (consp arg) (numberp (car arg)))) (let ((times (or (and (atom arg) arg) (car arg)))) (while (not (= times 0)) (dired-next-line -1) (when (my-dired-file-marked-with-char-p ?a) (push (dired-get-filename nil 'noerror) files)) (setq times (1- times))) (setq files (delq nil files)))))) (dired-unmark-backward arg) (let* ((total-size (apply '+ (mapcar (lambda(x) (elt x 7)) (mapcar 'file-attributes files)))) (total-size-str (if my-dired-human-readable (file-size-human-readable total-size) (my-dired-use-comma-separator total-size)))) (if (null files) (message "No marked files") (message "Unmarked %s %s with %s%s" (length files) (or (and (cdr files) "files") "file") total-size-str (or (and my-dired-human-readable "") " bytes")))))) (define-key dired-mode-map [backspace] 'my-dired-unmark-backward) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ^ permalink raw reply [flat|nested] 22+ messages in thread
* bug#22829: Acknowledgement (25.1.50; Display number of marked files) 2016-03-03 9:58 ` Tino Calancha @ 2016-03-03 12:27 ` Michael Heerdegen 2016-03-03 12:55 ` Constantino Calancha 2016-03-07 0:04 ` Juri Linkov 2016-03-08 0:19 ` Juri Linkov 2 siblings, 1 reply; 22+ messages in thread From: Michael Heerdegen @ 2016-03-03 12:27 UTC (permalink / raw) To: Tino Calancha; +Cc: 22829 Tino Calancha <f92capac@gmail.com> writes: > We can also reconsider a bit about the keybinding 'N' > for dired-man. Honestly i don't see the needs for this, having `man' > and `woman' working nicely. Indeed, the funtion is not working as it > should: > (dired "/bin") > j bash RET N bash RET > Can’t find the /bin/bash manpage > ;; Notice how i need to introduce 'bash' by hand, because the > ;; interactive specification of this func. is just (interactive). > ;; I don't expect anyone will complaint if we change 'N' binding here. You misinterpret what this command is for (I am using it). The command expects a man page at point (not an executable having a man page). This is like `dired-info' which displays info files from dired. The prompt is for asking for a man command to render the page. This is e.g. useful for software that you didn't install via "make install", or for browsing "/usr/share/man" from within dired. Michael. ^ permalink raw reply [flat|nested] 22+ messages in thread
* bug#22829: Acknowledgement (25.1.50; Display number of marked files) 2016-03-03 12:27 ` Michael Heerdegen @ 2016-03-03 12:55 ` Constantino Calancha 2019-06-25 14:29 ` Lars Ingebrigtsen 0 siblings, 1 reply; 22+ messages in thread From: Constantino Calancha @ 2016-03-03 12:55 UTC (permalink / raw) To: 22829@debbugs.gnu.org > You misinterpret what this command is for (I am using it). > > The command expects a man page at point (not an executable having a man > page). This is like `dired-info' which displays info files from dired. > The prompt is for asking for a man command to render the page. > > This is e.g. useful for software that you didn't install via "make > install", or for browsing "/usr/share/man" from within dired. Thanks Michael for the clarification. Let's forget about my proposal of binding the new commands with 'N'. '*#' and '*N' are available: both bindings are quite mnemonic and in my keyboard (american one) both looks suitable for carrying this task. ^ permalink raw reply [flat|nested] 22+ messages in thread
* bug#22829: Acknowledgement (25.1.50; Display number of marked files) 2016-03-03 12:55 ` Constantino Calancha @ 2019-06-25 14:29 ` Lars Ingebrigtsen 0 siblings, 0 replies; 22+ messages in thread From: Lars Ingebrigtsen @ 2019-06-25 14:29 UTC (permalink / raw) To: Constantino Calancha; +Cc: 22829@debbugs.gnu.org "Constantino Calancha" <f92capac@gmail.com> writes: > '*#' and '*N' are available: both bindings are quite mnemonic > and in my keyboard (american one) both looks suitable for carrying > this task. `* N' sounds nice. -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no ^ permalink raw reply [flat|nested] 22+ messages in thread
* bug#22829: Acknowledgement (25.1.50; Display number of marked files) 2016-03-03 9:58 ` Tino Calancha 2016-03-03 12:27 ` Michael Heerdegen @ 2016-03-07 0:04 ` Juri Linkov 2016-03-08 10:20 ` Tino Calancha 2016-03-08 0:19 ` Juri Linkov 2 siblings, 1 reply; 22+ messages in thread From: Juri Linkov @ 2016-03-07 0:04 UTC (permalink / raw) To: Tino Calancha; +Cc: 22829 > I have included the subdir sizes as an option: currently the subdir sizes are > not computed by default. We can change this behaviour to the opposite, > with subdir sizes computed by default, after the code being well tested. 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. 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") For more examples, please see defcustom dired-chown-program or defcustom archive-zip-extract how to define a command with its arguments in one defcustom. > There are two functions doing the same thing: > * my-dired-count-sizes-opt1: > * my-dired-count-sizes-opt2: This looks nicer but it requires cl-lib. dired-aux.el already includes (require 'cl-lib) - twice (just in case :), so there is no problem in using 'cl-lib. ^ permalink raw reply [flat|nested] 22+ messages in thread
* bug#22829: Acknowledgement (25.1.50; Display number of marked files) 2016-03-07 0:04 ` Juri Linkov @ 2016-03-08 10:20 ` Tino Calancha 0 siblings, 0 replies; 22+ messages in thread From: Tino Calancha @ 2016-03-08 10:20 UTC (permalink / raw) To: 22829; +Cc: f92capac, juri > 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) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ^ permalink raw reply [flat|nested] 22+ messages in thread
* bug#22829: Acknowledgement (25.1.50; Display number of marked files) 2016-03-03 9:58 ` Tino Calancha 2016-03-03 12:27 ` Michael Heerdegen 2016-03-07 0:04 ` Juri Linkov @ 2016-03-08 0:19 ` Juri Linkov 2016-03-08 10:34 ` Tino Calancha 2 siblings, 1 reply; 22+ messages in thread From: Juri Linkov @ 2016-03-08 0:19 UTC (permalink / raw) To: Tino Calancha; +Cc: 22829 > If we modify `dired-get-marked-files' as in the Bug#22892 > we can get in a straightforward way the file sizes from the file system. > I include the modified version of your code after these comments. I still doubt if old code could be of any help. When using file-attributes instead of parsing the ls output in the dired buffer it would be easier for you to implement new code from scratch with much shorter result. Some parts of old code (to parse the dired buffer) would be useful only in case if you decide to implement displaying recursive directory sizes in-line as was requested yesterday in http://emacs.stackexchange.com/questions/20766/display-recursive-folder-sizes-in-line-in-dired ^ permalink raw reply [flat|nested] 22+ messages in thread
* bug#22829: Acknowledgement (25.1.50; Display number of marked files) 2016-03-08 0:19 ` Juri Linkov @ 2016-03-08 10:34 ` Tino Calancha 2016-03-09 16:37 ` Richard Stallman 0 siblings, 1 reply; 22+ messages in thread From: Tino Calancha @ 2016-03-08 10:34 UTC (permalink / raw) To: Juri Linkov; +Cc: Tino Calancha, 22829 > Some parts of old code (to parse the dired buffer) would be useful > only in case if you decide to implement displaying recursive > directory sizes in-line as was requested yesterday in > http://emacs.stackexchange.com/questions/20766/display-recursive-folder-sizes-in-line-in-dired I guess that request is related with the Richard's concern mentioned before in this thread. Adding such information by default in the dired buffer may slow down things too much. If the ls command would add a new switch to show such recursive directory sizes, maybe it could be reasonable to implement such option. Otherwise, i don't think it could be practical. ^ permalink raw reply [flat|nested] 22+ messages in thread
* bug#22829: Acknowledgement (25.1.50; Display number of marked files) 2016-03-08 10:34 ` Tino Calancha @ 2016-03-09 16:37 ` Richard Stallman 0 siblings, 0 replies; 22+ messages in thread From: Richard Stallman @ 2016-03-09 16:37 UTC (permalink / raw) To: Tino Calancha; +Cc: f92capac, 22829, juri [[[ To any NSA and FBI agents reading my email: please consider ]]] [[[ whether defending the US Constitution against all enemies, ]]] [[[ foreign or domestic, requires you to follow Snowden's example. ]]] > I guess that request is related with the Richard's concern mentioned before in this thread. > Adding such information by default in the dired buffer may slow down > things too much. It might be possible to implement somethin to show a certain total by default and avoid a painful slowdown, if the code stops counting when it reaches a certain limit. -- Dr Richard Stallman President, Free Software Foundation (gnu.org, fsf.org) Internet Hall-of-Famer (internethalloffame.org) Skype: No way! See stallman.org/skype.html. ^ permalink raw reply [flat|nested] 22+ messages in thread
* bug#22829: 25.1.50; Display number of marked files 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-03-01 11:26 ` Constantino Calancha 1 sibling, 0 replies; 22+ messages in thread From: Constantino Calancha @ 2016-03-01 11:26 UTC (permalink / raw) To: 22829@debbugs.gnu.org > 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. Well not just in that case. The main use if as a fast way to know the number of files in the current directory: t N (Maybe it could optionally prompt for `dired-marker-char'). If you don't find this useful then we can just ignore it. No problem. ^ permalink raw reply [flat|nested] 22+ messages in thread
end of thread, other threads:[~2019-06-25 14:29 UTC | newest] Thread overview: 22+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 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
Code repositories for project(s) associated with this public inbox https://git.savannah.gnu.org/cgit/emacs.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).