From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.devel Subject: dired: More verbose subdir headers; show #files in subdir Date: Sat, 10 Sep 2016 02:50:21 +0900 (JST) Message-ID: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset=US-ASCII X-Trace: blaine.gmane.org 1473443900 21956 195.159.176.226 (9 Sep 2016 17:58:20 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 9 Sep 2016 17:58:20 +0000 (UTC) User-Agent: Alpine 2.20 (DEB 67 2015-01-07) To: Emacs developers Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Sep 09 19:58:16 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1biQ44-0004tt-Oi for ged-emacs-devel@m.gmane.org; Fri, 09 Sep 2016 19:58:13 +0200 Original-Received: from localhost ([::1]:59482 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1biQ45-0008Vv-OK for ged-emacs-devel@m.gmane.org; Fri, 09 Sep 2016 13:58:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51593) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1biPwd-0001Wh-Gf for emacs-devel@gnu.org; Fri, 09 Sep 2016 13:50:33 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1biPwX-0001HL-Hn for emacs-devel@gnu.org; Fri, 09 Sep 2016 13:50:30 -0400 Original-Received: from mail-pf0-x236.google.com ([2607:f8b0:400e:c00::236]:32933) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1biPwX-0001HB-6j for emacs-devel@gnu.org; Fri, 09 Sep 2016 13:50:25 -0400 Original-Received: by mail-pf0-x236.google.com with SMTP id g202so31598246pfb.0 for ; Fri, 09 Sep 2016 10:50:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:date:to:subject:message-id:user-agent:mime-version; bh=QDpWmPHLUSNzGL7wCAC2IZA8ioaOK766UWrHAqt3+wU=; b=aaa8vYIBt+8lAY96621MTIFQdf4tEw3ntVqU43qlkfRtweW5Aln934P07krM1TI3qF 40cG2Ef86Eca8a/1/Od7gtrVYhR5Lmqz1bkyQ0qD02bXNsh7yj7hio2nR54bZfWRgLOd Dam5JZCF0DCyVHtLjIdfQbvPadrQ597kDbWWlm02Rat3UR6jb9XUhzXTOFRCrJy1RZKW knqEbKQbh+uJELiqeuXrpjyk9keOftWUFRER+zNSTbuvO5UOJaCNoA/VEuI5W2isJtex c4LE98xqVINrD1DuP4pL9gN9aSvA87bbXGgdry8Edr3jvllyBoFcgudkV/32EV+x/Tt+ zjRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:date:to:subject:message-id:user-agent :mime-version; bh=QDpWmPHLUSNzGL7wCAC2IZA8ioaOK766UWrHAqt3+wU=; b=bSlw3xlNi7NoDpVkWitxbfdrXpvNEcG7h5xMwNJ0ixpoZbA39SXRQP7Pm+smPVhKD7 4clEIVN9fHisaM9xDvHOF6Dh5QzxJn2ML6iEvDeBATu2OBn/Rn95LvJ0rbTbJiAG4TMF WpQeImWf2WRKVKK1EopEr1mjmH1MNu3j1X2+b2yFo4vm6WYXVe9Y2JtXGpr20T32T08Z Q2DLMVtI408lXz/hn4soK1ab+LqIpytHMI5TzkrzThg2GE8EtIRbsN5E6ERpaVx6qvy8 5HpMO+DnvLfIPLnbxNl1CE412lxDzOzP/K0hiYvPu20PKHuYyKoBDORani6ZfNjrxKSs MEmQ== X-Gm-Message-State: AE9vXwNDRjdscRHhmsTzs9RZ7W/K7EdshuxvC3Ui7dkoR3tuibI7GxWG8/CAA2Mn+o7LMA== X-Received: by 10.98.26.16 with SMTP id a16mr8563150pfa.46.1473443424177; Fri, 09 Sep 2016 10:50:24 -0700 (PDT) Original-Received: from calancha-pc (57.92.100.220.dy.bbexcite.jp. [220.100.92.57]) by smtp.gmail.com with ESMTPSA id f62sm6771188pfj.75.2016.09.09.10.50.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Sep 2016 10:50:23 -0700 (PDT) X-Google-Original-From: Tino Calancha X-X-Sender: calancha@calancha-pc X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c00::236 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:207320 Archived-At: Drew Adams define in files+ Dired header lines with information on the number of files (see patch below). Following shows the Emacs (1) and files+ (2) header lines for my home directory: 1) total used in directory 87648 available 372113104 2) files 226/226 space used 87648 available 372086532 Where in X/Y, X is the number of files in the current subdir; Y is the number of files in default-directory: in this example, both numbers are the same because default-directory and (dired-current-directory) are the same. Note that the entries '.' and '..' are not counted. If you have some directories in the listing you might try: > i then, another subdirectory will be added. In my case, the header line for that subdir is: files 0/226 space used 44K available 372086532 The 0 means that the directory is empty (i.e., just '.' and '..'). I like showing X in the Dired header line. I think is nice if Emacs add this feature. I am not sure about the convenience of showing Y though. Most of the times i just look at X and ignore Y. Furthermore, for Dired buffers with just one subdir you get X/X which looks strange, specially when you have many files. For example, if i visit /usr/bin with Dired the header line is: files 2349/2349 space used 376M available 41182232 Do you like adding # files info in the Dired header lines? What is your opinion? Tino ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; >From 5fdde63547761dc2ea226b3ac6df3ffab576234c Mon Sep 17 00:00:00 2001 From: Tino Calancha Date: Sat, 10 Sep 2016 02:42:12 +0900 Subject: [PATCH] dired: More verbose subdir headers * lisp/files (count-dired-files): New defun; return the number of files in the current directory listing. (insert-directory): Add in each Dired header line the number of files in the current subdir and the total number of files in default-directory. (update-dired-files-count): New defun; update file count in each Dired header line. --- lisp/files.el | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 75 insertions(+), 7 deletions(-) diff --git a/lisp/files.el b/lisp/files.el index 4bd708d..dce69a2 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -6431,6 +6431,59 @@ directory-listing-before-filename-regexp (defvar insert-directory-ls-version 'unknown) +(defun count-dired-files () + "Returns the number of files in the current Dired directory listing. +This includes directory entries, as well as files, but it excludes `.' +and `..'." + (save-excursion + (when (save-restriction (widen) (eobp)) (goto-char (1- (point)))) + (re-search-backward "^$" nil 'to-bob) + (if (not (re-search-forward dired-move-to-filename-regexp nil t)) + 0 + (let* ((beg (line-beginning-position)) + (end (save-excursion (re-search-forward "^$" nil t))) + (dots-p (save-excursion ; Is `..' present? + (goto-char beg) + (re-search-forward + (concat directory-listing-before-filename-regexp + "\\.\\./?$") + end t)))) + (if dots-p (- (count-lines beg end) 2) (count-lines beg end)))))) + +(add-hook 'dired-after-readin-hook 'update-dired-files-count) +(defun update-dired-files-count () + "Update file count in Dired header for each directory listed." + (save-restriction + (widen) + (let* ((num-files (count-dired-files)) + (str-num-files (number-to-string num-files))) + (save-excursion + (goto-char (point-min)) + (while (re-search-forward "^ files \\([0-9]+\\)/\\([0-9]+\\)" nil t) + ;; No-op if the line should be hidden. + (unless (eq (get-text-property (match-beginning 0) 'invisible) + 'dired-hide-details-information) + (let ((buffer-read-only nil) + (map (make-sparse-keymap))) + (define-key map [mouse-2] 'dired-mouse-describe-listed-directory) + (define-key map "\r" 'dired-describe-listed-directory) + (replace-match str-num-files nil nil nil 1) + (replace-match (if (zerop num-files) + str-num-files + (number-to-string (- (length (directory-files + default-directory + nil nil t)) + 2))) + nil nil nil 2) + ;; Ignore any error, e.g. from `dired-details.el' hiding text. + (condition-case nil + (add-text-properties + (save-excursion (beginning-of-line) (+ 2 (point))) (match-end 2) + `(mouse-face highlight keymap ,map + help-echo "Files in subdir / files in default-directory")) + (error nil))))) + (set-buffer-modified-p nil))))) + ;; insert-directory ;; - must insert _exactly_one_line_ describing FILE if WILDCARD and ;; FULL-DIRECTORY-P is nil. @@ -6706,13 +6759,28 @@ insert-directory (save-excursion (goto-char beg) ;; First find the line to put it on. - (when (re-search-forward "^ *\\(total\\)" nil t) - (let ((available (get-free-disk-space "."))) - (when available - ;; Replace "total" with "used", to avoid confusion. - (replace-match "total used in directory" nil nil nil 1) - (end-of-line) - (insert " available " available)))))))))) + (while (re-search-forward "^ *\\(total\\)" nil t) + (goto-char (match-beginning 1)) + (insert "files " (number-to-string (save-match-data + (count-dired-files))) + "/" (number-to-string + (- (length (directory-files default-directory + nil nil t)) 2)) + " ") + (goto-char beg) + (re-search-forward "^ *files [0-9]+/[0-9]+ \\(total\\)" nil t) + (replace-match "space used" nil nil nil 1) + (let ((available (and (fboundp 'get-free-disk-space) + (get-free-disk-space "."))) + (map (make-sparse-keymap))) + (define-key map [mouse-2] 'dired-mouse-describe-listed-directory) + (define-key map "\r" 'dired-describe-listed-directory) + (when available (end-of-line) (insert " available " available)) + (add-text-properties (line-beginning-position) + (1- (match-beginning 1)) + `(mouse-face highlight keymap ,map + help-echo "Files in subdir / files in \ +default-directory")))))))))) (defun insert-directory-adj-pos (pos error-lines) "Convert `ls --dired' file name position value POS to a buffer position. -- 2.9.3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; In GNU Emacs 25.1.50.1 (x86_64-pc-linux-gnu, GTK+ Version 3.21.5) of 2016-09-08 built on calancha-pc Repository revision: 367f8568bc9e759ebdfb423648891efa0346456b