GNU bug report logs -
#22829
25.1.50; Display number of marked files
Previous Next
Reported by: Tino Calancha <f92capac <at> gmail.com>
Date: Sat, 27 Feb 2016 14:27:02 UTC
Severity: wishlist
Tags: fixed, patch
Found in version 25.1.50
Fixed in version 27.1
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 22829 in the body.
You can then email your comments to 22829 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#22829
; Package
emacs
.
(Sat, 27 Feb 2016 14:27:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Tino Calancha <f92capac <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Sat, 27 Feb 2016 14:27:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
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
[dired_show-num-marked-files.patch (text/plain, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#22829
; Package
emacs
.
(Sat, 27 Feb 2016 14:38:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 22829 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Return the correct value when number of marked files equals 1.
[dired_show-num-marked-files_2.patch (text/plain, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#22829
; Package
emacs
.
(Sun, 28 Feb 2016 05:39:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 22829 <at> debbugs.gnu.org (full text, mbox):
Tino Calancha <f92capac <at> 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
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#22829
; Package
emacs
.
(Sun, 28 Feb 2016 06:34:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 22829 <at> debbugs.gnu.org (full text, mbox):
> 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.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#22829
; Package
emacs
.
(Tue, 01 Mar 2016 16:29:02 GMT)
Full text and
rfc822 format available.
Message #17 received at 22829 <at> debbugs.gnu.org (full text, mbox):
> 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.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#22829
; Package
emacs
.
(Wed, 02 Mar 2016 00:34:01 GMT)
Full text and
rfc822 format available.
Message #20 received at 22829 <at> debbugs.gnu.org (full text, mbox):
>> 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)
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#22829
; Package
emacs
.
(Wed, 02 Mar 2016 17:30:01 GMT)
Full text and
rfc822 format available.
Message #23 received at 22829 <at> debbugs.gnu.org (full text, mbox):
Juri Linkov <juri <at> 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
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#22829
; Package
emacs
.
(Wed, 02 Mar 2016 20:05:02 GMT)
Full text and
rfc822 format available.
Message #26 received at 22829 <at> debbugs.gnu.org (full text, mbox):
On 2016-03-02, at 18:28, Lars Ingebrigtsen <larsi <at> gnus.org> wrote:
> Juri Linkov <juri <at> 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
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#22829
; Package
emacs
.
(Thu, 03 Mar 2016 00:21:02 GMT)
Full text and
rfc822 format available.
Message #29 received at 22829 <at> debbugs.gnu.org (full text, mbox):
>>> 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 '*'.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#22829
; Package
emacs
.
(Thu, 03 Mar 2016 05:53:02 GMT)
Full text and
rfc822 format available.
Message #32 received at 22829 <at> debbugs.gnu.org (full text, mbox):
Juri Linkov <juri <at> 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
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#22829
; Package
emacs
.
(Thu, 03 Mar 2016 09:56:02 GMT)
Full text and
rfc822 format available.
Message #35 received at 22829 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
>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)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#22829
; Package
emacs
.
(Thu, 03 Mar 2016 11:22:02 GMT)
Full text and
rfc822 format available.
Message #38 received at 22829 <at> debbugs.gnu.org (full text, mbox):
[[[ 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.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#22829
; Package
emacs
.
(Thu, 03 Mar 2016 11:27:01 GMT)
Full text and
rfc822 format available.
Message #41 received at 22829 <at> debbugs.gnu.org (full text, mbox):
Richard Stallman <rms <at> 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
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#22829
; Package
emacs
.
(Thu, 03 Mar 2016 12:28:02 GMT)
Full text and
rfc822 format available.
Message #44 received at 22829 <at> debbugs.gnu.org (full text, mbox):
Tino Calancha <f92capac <at> 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.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#22829
; Package
emacs
.
(Thu, 03 Mar 2016 12:53:02 GMT)
Full text and
rfc822 format available.
Message #47 received at 22829 <at> debbugs.gnu.org (full text, mbox):
> 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.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#22829
; Package
emacs
.
(Mon, 07 Mar 2016 00:30:02 GMT)
Full text and
rfc822 format available.
Message #50 received at 22829 <at> debbugs.gnu.org (full text, mbox):
> 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.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#22829
; Package
emacs
.
(Tue, 08 Mar 2016 00:25:02 GMT)
Full text and
rfc822 format available.
Message #53 received at 22829 <at> debbugs.gnu.org (full text, mbox):
> 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
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#22829
; Package
emacs
.
(Tue, 08 Mar 2016 10:18:02 GMT)
Full text and
rfc822 format available.
Message #56 received at 22829 <at> debbugs.gnu.org (full text, mbox):
> 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)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#22829
; Package
emacs
.
(Tue, 08 Mar 2016 10:32:02 GMT)
Full text and
rfc822 format available.
Message #59 received at 22829 <at> debbugs.gnu.org (full text, mbox):
> 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.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#22829
; Package
emacs
.
(Wed, 09 Mar 2016 16:41:02 GMT)
Full text and
rfc822 format available.
Message #62 received at 22829 <at> debbugs.gnu.org (full text, mbox):
[[[ 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.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#22829
; Package
emacs
.
(Tue, 25 Jun 2019 14:30:02 GMT)
Full text and
rfc822 format available.
Message #65 received at 22829 <at> debbugs.gnu.org (full text, mbox):
"Constantino Calancha" <f92capac <at> 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
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#22829
; Package
emacs
.
(Tue, 25 Jun 2019 14:30:03 GMT)
Full text and
rfc822 format available.
Message #68 received at 22829 <at> debbugs.gnu.org (full text, mbox):
Lars Ingebrigtsen <larsi <at> gnus.org> writes:
> Juri Linkov <juri <at> 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
Added tag(s) fixed.
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org
.
(Tue, 25 Jun 2019 14:30:03 GMT)
Full text and
rfc822 format available.
bug marked as fixed in version 27.1, send any further explanations to
22829 <at> debbugs.gnu.org and Tino Calancha <f92capac <at> gmail.com>
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org
.
(Tue, 25 Jun 2019 14:30:03 GMT)
Full text and
rfc822 format available.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Wed, 24 Jul 2019 11:24:06 GMT)
Full text and
rfc822 format available.
This bug report was last modified 4 years and 250 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.