Commit 767f853f authored by Lev Lamberov's avatar Lev Lamberov

New upstream version 0.5.1

parent bfa48b37
2018-10-01 Stefan Monnier <>
Remove redundant nil keywords to define-minor-mode. Sprinkle some FIXMEs
for good measure. Add some cosmetic changes. Fix copyright notice. Bump
verion to v0.5.1.
* packages/dired-du/dired-du.el (dired-du): Fix dired-du group.
(dired-du--toggle-human-readable, dired-du-mode): Use `add-function' for
(dired-du--revert): Try and avoid hiding arguments behind other
(dired-du--change-human-sizes, dired-du--cache-dir-info)
(dired-du--count-sizes-2): Prefer the return form of a `let' or `while'
on its own line.
(dired-du-run-in-parallel, (dired-du--create-or-check-dir-info)
(dired-du--change-human-sizes, dired-du--drop-unexistent-files)
(dired-du--replace, (dired-du-insert-marked-dirs): Use `function'
instead of `quote' with `mapcar'.
(dired-du-dir-info, dired-du--user-warned)
(dired-du-on-find-dired-ok, dired-du-find-dired-buffer): Remove
redundant :group args.
2018-09-24 Tino Calancha <>
Speed up the load of the dired buffer
It has been noted that we can significantly speed up the load of the
Dired buffer by checking more often the completion of the
`du' processes. Problem reported by Pierre Neidhardt here:
* packages/dired-du/dired-du.el
(dired-du-get-recursive-dir-size-in-parallel): check for `du' process
completion more often.
2017-05-27 Tino Calancha <>
Add command to update cache size for the marked files
;; Generated package description from dired-du.el
(define-package "dired-du" "0.5" "Dired with recursive directory sizes" '((emacs "24.4") (cl-lib "0.5")) :url "" :keywords '("files" "unix" "convenience"))
(define-package "dired-du" "0.5.1" "Dired with recursive directory sizes" '((emacs "24.4") (cl-lib "0.5")) :url "" :keywords '("files" "unix" "convenience"))
;;; dired-du.el --- Dired with recursive directory sizes -*- lexical-binding: t -*-
;; Copyright (C) 2016-2017 Free Software Foundation, Inc.
;; Copyright (C) 2016-2018 Free Software Foundation, Inc.
;; Author: Tino Calancha <>
;; Maintainer: Tino Calancha <>
;; Keywords: files, unix, convenience
;; Created: Wed Mar 23 22:54:00 2016
;; Version: 0.5
;; Version: 0.5.1
;; Package-Requires: ((emacs "24.4") (cl-lib "0.5"))
;; Last-Updated: Sat May 27 18:30:02 JST 2017
;; Last-Updated: Mon Oct 01 17:40:32 JST 2018
;; By: calancha
;; Update #: 339
;; Update #: 341
;; Compatibility: GNU Emacs: 24.4
......@@ -150,7 +150,7 @@
(defgroup dired-du nil
"Dired with recursive size dir."
:prefix "dired-du-"
:group 'dired-du)
:group 'dired)
(defvar dired-du-dir-info nil
"Alist of cached (DIRNAME . DIR-INFO) in Dired buffer.
......@@ -191,8 +191,7 @@ A value of nil disables this feature."
(list (string :tag "Program")
(repeat :tag "Options"
:inline t
(string :format "%v"))))
:group 'dired-du)
(string :format "%v")))))
(defvar dired-du--user-warned (and dired-du-used-space-program t)
"Nil if the user must be warned about \
......@@ -210,14 +209,13 @@ Otherwise display file sizes in default numeric format."
:type '(choice
(const :tag "Use default numeric format" nil)
(const :tag "Use human readable string" t)
(const :tag "Use thousands comma separator" 'comma))
:group 'dired-du)
(const :tag "Use thousands comma separator" 'comma)))
(defcustom dired-du-on-find-dired-ok nil
"If Non-nil show recursive dir sizes in `find-dired'.
The format to display the file sizes is control by
:type 'boolean :group 'dired-du)
:type 'boolean)
(defvar dired-du-find-dired-buffer nil
"Non-nil if current buffer is a `find-dired' buffer.
......@@ -229,7 +227,7 @@ buffer show recursive dir sizes with format according with
(defcustom dired-du-update-headers nil
"If Non-nil, update the subdir headers.
The total used space shown contains the recursive size of the directories."
:type 'boolean :group 'dired-du)
:type 'boolean)
(defvar dired-du-local-subdir-header
"^ total used in directory \\([,.0-9]+[BkKMGTPEZY]?\\) \
......@@ -601,7 +599,8 @@ If there is not a directory in the current line return nil."
(insert (format "%d" tmp)))))
(goto-char 1)
(while (re-search-forward "^[0-9]+" nil t)
(setq size (+ size (string-to-number (match-string 0)))))) size)))
(setq size (+ size (string-to-number (match-string 0))))))
(defun dired-du-run-in-parallel (command out-buf)
"Run COMMAND for several files in parallel.
......@@ -633,7 +632,7 @@ DIRS is a list of directories.
The return value is an alist (DIRNAME . SIZE)."
(let ((dirs-rel (mapcar 'file-relative-name dirs))
(let ((dirs-rel (mapcar #'file-relative-name dirs))
(command (format "%s %s&" (car dired-du-used-space-program)
(cadr dired-du-used-space-program)))
(prep (make-progress-reporter
......@@ -647,7 +646,8 @@ The return value is an alist (DIRNAME . SIZE)."
(let ((buff (current-buffer)))
command files 'on-each) buff)
command files 'on-each)
(let ((proc (get-buffer-process buff)))
;; wait until all files processed.
(while (eq (process-status proc) 'run)
......@@ -665,7 +665,10 @@ The return value is an alist (DIRNAME . SIZE)."
(setq old completed))
(setq completed (count-lines (point-min)
(sleep-for 1))))
;; Give a bit of time to the process to end. Initially we
;; were waiting 1 s; it turned out to be too conservative value.
;; TODO: Shouldn't this be run in a sentinel?
(sleep-for 0 10))))
;; collect dir sizes.
(goto-char 1)
(while (re-search-forward "^[0-9]+" nil t)
......@@ -794,7 +797,7 @@ performance reasons."
(mapcar (lambda (x) (cons (car x) nil)) subdir-alist)))
((> num-subdirs ; add missing subdirs.
(length dired-du-dir-info))
(let ((subdirs (mapcar 'car subdir-alist)))
(let ((subdirs (mapcar #'car subdir-alist)))
(dolist (dir subdirs)
(unless (assoc-string dir dired-du-dir-info)
(push (list dir) dired-du-dir-info)))))
......@@ -1355,12 +1358,10 @@ Return nil."
;;; Change format of file sizes.
(defun dired-du--revert (&optional ignore-auto noconfirm preserve-modes)
(defun dired-du--revert (orig-fun &rest args)
"Revert current dired buffer.
(let ((switches dired-actual-switches)
(ignore ignore-auto noconfirm preserve-modes)
(let ((switches dired-actual-switches))
(when (string-match "--human-readable" switches)
(setq switches (replace-match "" t t switches)))
(setq switches (apply #'string (delete ?h (string-to-list switches)))
......@@ -1369,11 +1370,12 @@ Arguments IGNORE-AUTO, NOCONFIRM and PRESERVE-MODES are ignored."
(let ((dired-actual-switches switches)
(prep (make-progress-reporter "Wait until find process finish")))
(setq proc (get-buffer-process (current-buffer)))
(while (and proc (memq 'run (process-status proc)))
(progress-reporter-update prep)
(sleep-for 1))))
(apply orig-fun args)
(let ((proc (get-buffer-process (current-buffer))))
(while (and proc (memq 'run (process-status proc)))
(progress-reporter-update prep)
;; FIXME: (accept-process-output proc 1)?
(sleep-for 1)))))
(defun dired-du--change-human-sizes (&optional human-readable)
......@@ -1408,7 +1410,7 @@ requires revert buffer. Revert? ")))
(setq res t)
(let* ((max-lens (make-list 4 0))
(subdirs (mapcar 'car dired-subdir-alist))
(subdirs (mapcar #'car dired-subdir-alist))
(num-subdirs (length subdirs))
(counter 0)
(done nil)
......@@ -1486,13 +1488,15 @@ comma separator..."))
(cond ((eq t human-readable) size-human)
((null human-readable) size-no-human)
(t size-comma))))) nil)))))
(t size-comma)))))
(dired-du-mark-subdir-files nil 'must-exist)
(dired-du-map-over-marks (funcall fn) nil nil nil))))))
(progress-reporter-done prep))))) res))
(progress-reporter-done prep)))))
(defun dired-du--toggle-human-readable (&optional no-message)
"Toggle to show file sizes with human readable string in Dired buffers.
......@@ -1619,14 +1623,14 @@ If no marked files, update the file at point."
(info (list (dired-du-get-file-info))))
(dired-du--global-update-dir-info info pos))
(funcall revert-buffer-function))
(defun dired-du--drop-unexistent-files ()
"Remove from `dired-du-dir-info' records of unexistent files."
(when (or (not dired-du-find-dired-buffer)
(and dired-du-find-dired-buffer
(let ((subdirs (mapcar 'car dired-subdir-alist)))
(let ((subdirs (mapcar #'car dired-subdir-alist)))
(dolist (dir subdirs)
(let* ((glob-pos (dired-du--subdir-position dir))
......@@ -1939,7 +1943,7 @@ Return file info for current subdir."
(unless dired-du-mode
(error "Recursive dir sizes is disabled: \
Use `dired-du-mode' to enable it"))
(let ((subdirs (mapcar 'car dired-subdir-alist))
(let ((subdirs (mapcar #'car dired-subdir-alist))
empty-info result)
......@@ -1986,25 +1990,30 @@ in a Dired buffer might be slow; thus, it may significantly delay
the time to display a new Dired buffer.
Instead of enabling `dired-du-mode' by default in all Dired buffers
you might prefer to use this mode as a convenient interfaz to
you might prefer to use this mode as a convenient interface to
the `du' program: just enable it in the current Dired buffer,
and disable it once you have finished checking the used space."
:init-value nil
:lighter (:eval (if dired-du-mode
" Dired-du"
:keymap nil
;; FIXME: Is this intended to be a global or local minor-mode? The paragraph
;; above makes it sound like it's intended to be local, but the code below
;; tries to have a global effect, yet the dired-du-mode var itself is
;; buffer-local and you use a hook on dired-mode-hook to enable the mode
;; every time we enter dired-mode.
:lighter " Dired-du"
:variable dired-du-mode
;; Propagate the state to all Dired buffers.
;; Only the current buffer is reverted.
;; FIXME: I don't see any code that causes the buffer to be reverted?
;; FIXME: Why is the code below in `after-hook'?
:after-hook (let ((state dired-du-mode))
(dolist (buff dired-buffers)
(with-current-buffer (cdr buff)
(setq dired-du-mode state)
(setq revert-buffer-function
(or (and state #'dired-du--revert)
(if state
(add-function :around (local 'revert-buffer-function)
(remove-function (local 'revert-buffer-function)
;; If `major-mode' not dired mode, set `dired-du-mode' nil and exit.
(unless (derived-mode-p 'dired-mode)
......@@ -2098,7 +2107,8 @@ Optional arg ALL-MARKS, if non-nil, acept all mark characters."
(lambda (x)
(let ((basename (file-name-nondirectory x)))
(and (dired-du--file-in-dir-info-p x info)
(not (member basename '("." "..")))))) files))
(not (member basename '("." ".."))))))
(num-files (length files))
(collect-str "Dired-Du catching file info ...")
......@@ -2196,7 +2206,8 @@ Please, consider install a 'du' executable suitable to your platform.")
(unless (dired-du-directory-at-current-line-p)
nil nil 'distinguish-one-marked mark all-marks)))
(info (dired-du-distinguish-one-marked info))) info))))
(info (dired-du-distinguish-one-marked info)))
;; (info (delq nil (dired-du-map-over-marks
;; (if (and (dired-du-directory-at-current-line-p)
;; include-dirs)
......@@ -2233,7 +2244,8 @@ Please, consider install a 'du' executable suitable to your platform.")
(or (and size
(dired-du-string-to-number size))
0))) dirs))))
(setq total-size
(+ total-size (* scale-factor dirs-size)))))
(t ; Get size dir with `dired-du-dir-info'.
......@@ -2244,7 +2256,8 @@ Please, consider install a 'du' executable suitable to your platform.")
(or (and (dired-goto-file fullname)
0))) dirs))
(dirs-size (apply #'+ sizes)))
(setq total-size
(+ total-size (* scale-factor dirs-size))))))))
......@@ -2363,7 +2376,7 @@ with total size %s%s%s\n"
(when dired-du (dired-du-mode -1))
(mapc 'dired-maybe-insert-subdir (dired-du-get-marked-files)))
(mapc #'dired-maybe-insert-subdir (dired-du-get-marked-files)))
(when dired-du (dired-du-mode)))))
(defun dired-du-drop-all-subdirs ()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment