;;; dired-dirs-files.el --- display numbers of dirs and files in dired. ;; Copyright (C) 2004-2009 Daisuke Kakura ;; This program 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 2, or (at your option) ;; any later version. ;; ;; This program 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; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;;; Install: ;; ;; Add the following line to your .emacs. ;; ** dired-dirs-files works for emacs 22.0.90+ ;; ;; (require 'dired-dirs-files) ;; ;;; History: ;; ;; 2009-06-21 v0.3 Daisuke: fixed dired-dirs-files-dir-regex. ;; changed default color. ;; 2008-12-07 v0.2a Daisuke: fixed problem with accessing d: drive. ;; 2007-05-15 v0.2 Daisuke: fixed kill-line bug and added face to status line. ;; 2007-04-13 v0.1d Daisuke: fixed some for meadow3. ;; 2004-10-11 v0.1c Daisuke: ange-ftp support, bug fixed. ;; 2004-10-11 v0.1b Daisuke: ange-ftp support. ;; 2004-10-06 v0.1a Daisuke: wildcard support. ;; 2004-10-04 v0.1 Daisuke: created. ;;; Code: ;; (defvar dired-dirs-files-dir-regex "^ d[-r]" "Regex to match directories.") (defvar dired-dirs-files-file-regex "^ -" "Regex to match files.") (defadvice dired-insert-directory (after dired-insert-directory-dirs-files activate) "Display numbers of dirs and files." (let ((files 0) (dirs 0) (manyd "") (manyf "") (name nil)) (save-excursion ; count dirs (goto-char (point-min)) (while (re-search-forward dired-dirs-files-dir-regex nil t) (if dired-omit-mode (progn (setq name (dired-get-filename 'no-dir t)) (unless (or (string-match "^\\.+$" name) (string-match dired-omit-files name)) (setq dirs (+ dirs 1)))) (setq dirs (+ dirs 1)))) ; count files (goto-char (point-min)) (while (re-search-forward dired-dirs-files-file-regex nil t) (if dired-omit-mode (progn (setq name (dired-get-filename 'no-dir t)) (unless (string-match dired-omit-files name) (setq files (+ files 1)))) (setq files (+ files 1)))) ; display numbers (if (> dirs 1) (setq manyd "s")) (if (> files 1) (setq manyf "s")) (goto-char (point-min)) (when (re-search-forward "available [0-9]+" nil t) (if (not (looking-at "\n")) (delete-line)) (insert (format " / %d dir%s %d file%s" dirs manyd files manyf)))))) (defface face-dired-status '((t (:foreground "burlywood"))) nil) (defvar face-dired-status 'face-dired-status) (defun my-dired-status-search (arg) "Fontlock search function for dired." (search-forward-regexp "total used in directory.*$" arg t)) (add-hook 'dired-mode-hook '(lambda () (font-lock-add-keywords nil (list '(my-dired-status-search . face-dired-status))))) (provide 'dired-dirs-files) ;;; dired-dirs-files.el ends here.