Commit bfa48b37 authored by Lev Lamberov's avatar Lev Lamberov

New upstream version 0.5

parents
language: emacs-lisp
notifications:
email:
on_success: never
on_failure: always
env:
- EVM_EMACS=emacs-24.4-travis
- EVM_EMACS=emacs-24.5-travis
- EVM_EMACS=emacs-git-snapshot-travis
before_install:
- git clone https://github.com/rejeep/evm.git $HOME/.evm
- export PATH=$HOME/.evm/bin:$PATH
- evm config path /tmp
- evm install $EVM_EMACS --use --skip
script:
- make test
2017-05-27 Tino Calancha <tino.calancha@gmail.com>
Add command to update cache size for the marked files
* dired-du.el (dired-du-update-dir-info): New command.
2017-05-26 Tino Calancha <tino.calancha@gmail.com>
Add library dired-du
This diff is collapsed.
emacs ?= emacs
LOAD = -l dired-du.el
all: test
test:
$(emacs) -batch $(LOAD) -l dired-du-tests.el -f ert-run-tests-batch-and-exit
compile:
$(emacs) -batch --eval "(progn (add-to-list 'load-path default-directory) (byte-compile-file \"dired-du.el\"))"
clean:
rm -f *.elc
.PHONY: all compile clean test
# dired-du
[![Build Status](https://api.travis-ci.org/calancha/dired-du.svg?branch=master)](https://travis-ci.org/calancha/dired-du)
## Display the recursive size of directories in Dired
This file defines a minor mode **dired-du-mode** to show
the recursive size of directories in Dired buffers.
If *du* program is available, then the directory sizes are
obtained with it. Otherwise, the directory sizes are obtained
with Lisp. The former is much faster.
For directories where the user doesn't have read permission,
the recursive size is not obtained.
Once this mode is enabled, every new Dired buffer displays
recursive dir sizes.
To enable the mode at start up:
1. Store the file in a directory within *load-path*.
2. Add the following into .emacs file:
```(add-hook 'dired-mode-hook #'dired-du-mode)```
Note that obtaining the recursive size of all the directories
in a Dired buffer might be very slow: 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 an interfaz to
the *du* program: you can enable it in the current Dired buffer,
and disable it once you have finished checking the used space.
## Number of marked files and their size
In adition, this library adds a command, **dired-du-count-sizes**,
to count the number of marked files and how much space
they use; the command accepts a particular character mark
i.e., '*' or all kind of marks i.e, any character other than ?\s.
;; 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 "http://elpa.gnu.org/packages/dired-du.html" :keywords '("files" "unix" "convenience"))
;;; dired-du-tests.el --- Tests for dired-du.el -*- lexical-binding: t; -*-
;; Copyright (C) 2017 Free Software Foundation, Inc.
;; Author: Tino Calancha <tino.calancha@gmail.com>,
;; Keywords:
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;;; code:
(require 'ert)
(require 'dired-du)
(ert-deftest dired-du-test1 ()
(let* ((dir (make-temp-file "dired-du" 'dir))
(dir2 (expand-file-name "foo" dir))
(dired-du-used-space-program nil)
(buffers '())
mode-on)
(unwind-protect
(progn
(make-directory dir2)
(push (dired dir2) buffers)
(setq mode-on dired-du-mode)
(dotimes (i 9)
(write-region "1234" nil (format "baz%d" i)))
(push (dired dir) buffers)
(dired-goto-file dir2)
(should (= 36 (dired-du-get-recursive-dir-size))))
(if mode-on
(dired-du-mode 1)
(dired-du-mode 0))
(mapc #'kill-buffer buffers)
(delete-directory dir 'recursive))))
(ert-deftest dired-du-test2 ()
(let* ((dir (make-temp-file "dired-du" 'dir))
(dir2 (expand-file-name "foo" dir))
(buffers '()) mode-on)
(unwind-protect
(progn
(make-directory dir2)
(add-to-list 'buffers (dired dir2))
(setq mode-on dired-du-mode)
(dotimes (i 9)
(write-region "1234" nil (format "baz%d" i)))
(add-to-list 'buffers (dired dir))
(dired-goto-file dir2)
(let ((size-orig (floor (dired-du--read-size-from-buffer)))
(size-du (dired-du-get-recursive-dir-size)))
(dolist (dired-du-size-format (list nil 'comma t))
(unwind-protect
(progn
(should (/= size-orig size-du))
(dired-du-mode 1)
(unless (eq dired-du-size-format t)
(should (= (floor (dired-du--read-size-from-buffer))
size-du)))
;; Disable user write permissions on this dir: The size shown
;; must be equal to `size-orig'.
(set-file-modes dir2 #o000)
(dired-du-mode 0)
(dired-du--reset)
(revert-buffer)
(dired-du-mode 1)
(unless dired-du-used-space-program
(should (= size-orig
(floor (dired-du--read-size-from-buffer))))))
;; Clean up
(set-file-modes dir2 #o755)
(dired-du-mode 0)
(dired-du--reset)))))
(if mode-on
(dired-du-mode 1)
(dired-du-mode 0))
(mapc #'kill-buffer buffers)
(delete-directory dir 'recursive))))
(ert-deftest dired-du-test3 ()
(let* ((dir (make-temp-file "dired-du" 'dir))
(dir2 (expand-file-name "foo" dir))
(dir3 (expand-file-name "bar" dir))
(file (expand-file-name "qux" dir))
(dired-du-used-space-program nil)
(buffers '()) mode-on info)
(unwind-protect
(let ((name2 (file-name-nondirectory dir2))
(name3 (file-name-nondirectory dir3)))
(make-directory dir2)
(make-directory dir3)
(write-region "" nil file)
(add-to-list 'buffers (dired dir))
(setq mode-on dired-du-mode)
(dired-du-mode 1)
;; (should (dired-du--get-position name2))
(should (dired-du--file-in-dir-info-p name2))
(should (dired-du--get-value name2 'size))
;; (should (dired-du--get-position name3))
(should (dired-du--file-in-dir-info-p name3))
(should (dired-du--get-value name3 'size))
(setq info (assoc name3
(cdr (nth 0 dired-du-dir-info))))
(dired-du--delete-entry name3)
(should-not (dired-du--file-in-dir-info-p name3))
;; Reinsert it.
(dired-du--global-update-dir-info
(progn
(dired-goto-file dir3)
(list (dired-du-get-file-info)))
0)
(should (dired-du--file-in-dir-info-p name3))
(delete-directory dir3 t)
(should (dired-du--file-in-dir-info-p name3))
(dired-mark 1)
(dired-do-kill-lines nil)
(dired-du--drop-unexistent-files)
(should-not (dired-du--file-in-dir-info-p name3))
;; `dired-du-dir-info' just stored directories.
(should-not (dired-du--get-position (file-name-nondirectory file))))
(if mode-on
(dired-du-mode 1)
(dired-du-mode 0))
(mapc #'kill-buffer buffers)
(delete-directory dir 'recursive))))
(ert-deftest dired-du-test4 ()
(let* ((dir (make-temp-file "dired-du" 'dir))
(dir2 (expand-file-name "foo" dir))
(dir3 (expand-file-name "bar" dir))
(file (expand-file-name "qux" dir))
(buffers '()))
(unwind-protect
(let ((name2 (file-name-nondirectory dir2))
(name3 (file-name-nondirectory dir3))
(marks '()))
(make-directory dir2)
(make-directory dir3)
(write-region "" nil file)
(add-to-list 'buffers (dired dir))
(dired-mark-directories nil)
(dired-change-marks ?* ?1)
(dired-toggle-marks)
(setq marks
(sort (dired-du-get-all-marks) #'<))
(should (equal (sort (list ?* ?1) #'<) marks)))
(mapc #'kill-buffer buffers)
(delete-directory dir 'recursive))))
(ert-deftest dired-du-test5 ()
(let* ((dir (make-temp-file "dired-du" 'dir))
(dir2 (expand-file-name "foo" dir))
(dir3 (expand-file-name "bar" dir))
(file1 (expand-file-name "qux" dir))
(file2 (expand-file-name "qux" dir2))
(file3 (expand-file-name "qux" dir3))
(buffers '()) mode-on)
(unwind-protect
(let ((name2 (file-name-nondirectory dir2))
(name3 (file-name-nondirectory dir3))
(marks '()))
(make-directory dir2)
(make-directory dir3)
(dolist (file (list file1 file2 file3))
(write-region "" nil file))
(add-to-list 'buffers (dired dir))
(setq mode-on dired-du-mode)
(dired-du-mode 1)
(dired-insert-subdir dir2)
(dired-insert-subdir dir3)
(should (= 3 (length dired-du-dir-info)))
(dired-goto-file file2)
(dired-kill-subdir)
(dired-du--drop-unexistent-files)
(should (= 2 (length dired-du-dir-info))))
(if mode-on
(dired-du-mode 1)
(dired-du-mode 0))
(mapc #'kill-buffer buffers)
(delete-directory dir 'recursive))))
(ert-deftest dired-du-count-sizes-test ()
(let* ((dir (make-temp-file "dired-du" 'dir))
(dir2 (expand-file-name "foo" dir))
(dir3 (expand-file-name "bar" dir))
(file1 (expand-file-name "file1" dir))
(file2 (expand-file-name "file2" dir))
(file3 (expand-file-name "file3" dir))
(buffers '()) mode-on)
(unwind-protect
(let ((name2 (file-name-nondirectory dir2))
(name3 (file-name-nondirectory dir3))
(marks '()))
(make-directory dir2)
(make-directory dir3)
(dolist (file (list file1 file2 file3))
(write-region "" nil file))
(add-to-list 'buffers (dired dir))
(setq mode-on dired-du-mode)
(dired-du-mode 1)
(should (string-match "No marked files with mark"
(dired-du-count-sizes ?*)))
;; Mark dirs.
(dired-mark-directories nil)
(should (dired-du-count-sizes ?*))
(dired-change-marks ?* ?1)
(should (dired-du-count-sizes ?1))
(dired-mark-files-regexp "\\`file[1-3]\\'")
(should (string-match "Marked with [^ ]+ 3 files"
(dired-du-count-sizes ?*)))
(should (windowp (dired-du-count-sizes ?* 'all-marks))))
(if mode-on
(dired-du-mode 1)
(dired-du-mode 0))
(mapc #'kill-buffer buffers)
(delete-directory dir 'recursive))))
(provide 'dired-du-tests)
;;; dired-du-tests.el ends here
This source diff could not be displayed because it is too large. You can view the blob instead.
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