help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to get `item in directory' count in dired


From: Kevin Rodgers
Subject: Re: How to get `item in directory' count in dired
Date: Sat, 16 Feb 2008 08:25:15 -0700
User-agent: Thunderbird 2.0.0.9 (Macintosh/20071031)

address@hidden wrote:
How can I have a permanent item count in the directory view.  Maybe in
the mode line or something.

I want to see how many files/directories are in the dired buffer at a glance
without keyboard cmds or other effort.

Nice exercise:

(define-minor-mode dired-count-files-mode
  "*Display the number of files in the Dired mode line."
  nil (:eval (format " %d files" dired-count-files)) nil
  (if dired-count-files-mode
      (progn
        (add-hook 'dired-before-readin-hook 'dired-count-files-reset)
        (add-hook 'dired-after-readin-hook 'dired-count-files-total))
    (progn
      (remove-hook 'dired-before-readin-hook 'dired-count-files-reset)
      (remove-hook 'dired-after-readin-hook 'dired-count-files-total))))

(defvar dired-count-files 0
  "The number of files in the Dired buffer.")

(defun dired-count-files-reset ()
  (set (make-local-variable 'dired-count-files) 0))

(defun dired-count-files-total ()
  (goto-char (point-min))
  (search-forward-regexp dired-move-to-filename-regexp nil t)
  (set (make-local-variable 'dired-count-files)
(+ dired-count-files (count-lines (line-beginning-position) (point-max)))))


--
Kevin Rodgers
Denver, Colorado, USA





reply via email to

[Prev in Thread] Current Thread [Next in Thread]