* patch for Dired second header line info @ 2008-03-01 1:03 Drew Adams 2008-03-01 13:31 ` Richard Stallman 2008-03-02 2:55 ` Juri Linkov 0 siblings, 2 replies; 23+ messages in thread From: Drew Adams @ 2008-03-01 1:03 UTC (permalink / raw) To: emacs-devel [-- Attachment #1: Type: text/plain, Size: 1739 bytes --] The second header line in a Dired buffer currently looks like this: total used in directory 49439 available 56233408 Attached is a patch (for `files.el' and `ls-lisp.el') that changes that text to this: files 691 space used 49439 available 56233408 IOW, it adds the number of files and directories (`files'), and it shortens `total used in directory' to `space used'. That also makes it clearer what "total used" means (total what?). We might want to change `space used' to `Kbytes used' or whatever, to be even clearer. Entries `.' and `..' are not counted, but other directories are, along with non-directory files. The patch works for `-lR' listings also, updating the subdir totals. Room for improvement: 1. Like the current code, this code replaces the initial text `total' that is written to the buffer. Perhaps we could just write the correct text to begin with, instead of doing a text substitution for the placeholder `total'? 2. The proposed code does this: (add-hook 'dired-after-readin-hook 'update-dired-files-count) Perhaps we could do the `update-dired-files-count' directly in the code that runs the hook, instead? As it stands now, the file count and the space counts are updated only during directory read-in - e.g. when you hit `g' (nothing new in that, BTW). I could not find a hook for when a file or dir is added/deleted (or hidden/shown), etc. Wouldn't it be useful to have a hook for whenever the Dired display changes? Here's a change-log entry: 2008-02-29 Drew Adams <drew.adams@oracle.com> * files.el: (insert-directory): Print number of files. (count-dired-files): New function. (update-dired-files-count): New function. * ls-lisp.el (insert-directory): Print number of files. [-- Attachment #2: ls-lisp-2008-02-29.patch --] [-- Type: application/octet-stream, Size: 1434 bytes --] diff -c -w "ls-lisp-CVS-2008-02-29.el" "ls-lisp-patched-2008-02-29.el" *** ls-lisp-CVS-2008-02-29.el Fri Feb 29 14:58:50 2008 --- ls-lisp-patched-2008-02-29.el Fri Feb 29 15:01:32 2008 *************** *** 263,274 **** ;; Try to insert the amount of free space. (save-excursion (goto-char (point-min)) ! ;; 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 "total used", to avoid confusion. - (replace-match "total used in directory") (end-of-line) (insert " available " available))))))))) --- 263,279 ---- ;; Try to insert the amount of free space. (save-excursion (goto-char (point-min)) ! (while (re-search-forward "^total" nil t) ! (beginning-of-line) ! (insert "files " ! (number-to-string (save-match-data (count-dired-files))) ! " ") ! (goto-char (point-min)) ! (re-search-forward "^files [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 ".")))) (when available (end-of-line) (insert " available " available))))))))) Diff finished at Fri Feb 29 15:19:17 [-- Attachment #3: files-2008-02-29.patch --] [-- Type: application/octet-stream, Size: 3667 bytes --] diff -c -w files-CVS-2008-02-29.el" "files-patched-2008-02-29.el" *** files-CVS-2008-02-29.el Fri Feb 29 14:59:08 2008 --- files-patched-2008-02-29.el Fri Feb 29 15:17:20 2008 *************** *** 5284,5303 **** (if val (put-text-property pos (point) 'dired-filename t))))))) ! ! (if full-directory-p ! ;; Try to insert the amount of free space. (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))))))))))) (defun insert-directory-adj-pos (pos error-lines) "Convert `ls --dired' file name position value POS to a buffer position. File name position values returned in ls --dired output --- 5284,5336 ---- (if val (put-text-property pos (point) 'dired-filename t))))))) ! (when full-directory-p (save-excursion (goto-char beg) ! (while (re-search-forward "^ *\\(total\\)" nil t) ! (beginning-of-line) ! (insert "files " (number-to-string (save-match-data ! (count-dired-files))) ! " ") ! (goto-char beg) ! (re-search-forward "^files [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 ".")))) (when available (end-of-line) (insert " available " available))))))))))) + (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 `..'." + ;; Should we skip `#' files also, as in `dired-trivial-filenames'? Dunno. + (save-excursion + (re-search-backward "^$" nil 'to-bob) + (re-search-forward dired-move-to-filename-regexp nil t) + (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." + (let ((num-files (number-to-string (count-dired-files)))) + (save-excursion + (goto-char (point-min)) + (while (re-search-forward "^ files \\([0-9]+\\)" nil t) + (let ((buffer-read-only nil)) + (replace-match (number-to-string (save-match-data (count-dired-files))) + nil nil nil 1)) + (set-buffer-modified-p nil))))) + (defun insert-directory-adj-pos (pos error-lines) "Convert `ls --dired' file name position value POS to a buffer position. File name position values returned in ls --dired output Diff finished at Fri Feb 29 15:17:44 ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: patch for Dired second header line info 2008-03-01 1:03 patch for Dired second header line info Drew Adams @ 2008-03-01 13:31 ` Richard Stallman 2008-03-01 16:31 ` Drew Adams 2008-03-02 2:55 ` Juri Linkov 1 sibling, 1 reply; 23+ messages in thread From: Richard Stallman @ 2008-03-01 13:31 UTC (permalink / raw) To: Drew Adams; +Cc: emacs-devel The "files 691" may be misleading if it means the number of files listed in this dired buffer, rather than the number in the directory. ^ permalink raw reply [flat|nested] 23+ messages in thread
* RE: patch for Dired second header line info 2008-03-01 13:31 ` Richard Stallman @ 2008-03-01 16:31 ` Drew Adams 2008-03-01 23:09 ` Richard Stallman 0 siblings, 1 reply; 23+ messages in thread From: Drew Adams @ 2008-03-01 16:31 UTC (permalink / raw) To: rms; +Cc: emacs-devel > The "files 691" may be misleading if it means the number > of files listed in this dired buffer, rather than the number > in the directory. True, just as it might be misleading because it says "files" instead of "files and directories". And it doesn't say "in this directory" instead of "in this directory and below". And the space indication doesn't say "in this directory" for the used space and "on the whole disk" for available space. That's why we have doc. We can change the label if you like. But if this wasn't a problem before, for "total used" (total what? what units? in what scope?) and "available (ditto, and the scope here is presumably the disk, not the dir), then I don't think it will be much of a problem now. I think it's good to keep the labels short, but you can change it to, say, "files listed" or "files shown". You might also want to use a colon after each label, some commas, and perhaps title case. This is clearer, perhaps - shorten as desired: Files & dirs shown: 691, Kbytes used in dir: 49439, Kbytes available on disk: 56233408 Personally, I think it's clear enough as is, but it should be mentioned in the doc somewhere - I don't think it is mentioned at all now. Also, someone using wildcards or hiding lines will discover soon enough that the "files" figure changes. ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: patch for Dired second header line info 2008-03-01 16:31 ` Drew Adams @ 2008-03-01 23:09 ` Richard Stallman 0 siblings, 0 replies; 23+ messages in thread From: Richard Stallman @ 2008-03-01 23:09 UTC (permalink / raw) To: Drew Adams; +Cc: emacs-devel > The "files 691" may be misleading if it means the number > of files listed in this dired buffer, rather than the number > in the directory. True, just as it might be misleading because it says "files" instead of "files and directories". And it doesn't say "in this directory" instead of "in this directory and below". And the space indication doesn't say "in this directory" for the used space and "on the whole disk" for available space. Each of these is a different issue. Each one of these might or might not be confusing. The answer to one question is not the answer to all. I think it's good to keep the labels short, but you can change it to, say, "files listed" That sounds like a big improvement. ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: patch for Dired second header line info 2008-03-01 1:03 patch for Dired second header line info Drew Adams 2008-03-01 13:31 ` Richard Stallman @ 2008-03-02 2:55 ` Juri Linkov 2008-03-02 8:05 ` Drew Adams 1 sibling, 1 reply; 23+ messages in thread From: Juri Linkov @ 2008-03-02 2:55 UTC (permalink / raw) To: Drew Adams; +Cc: emacs-devel > The second header line in a Dired buffer currently looks like this: > > total used in directory 49439 available 56233408 > > Attached is a patch (for `files.el' and `ls-lisp.el') that changes that text > to this: > > files 691 space used 49439 available 56233408 Are you sure this change will not break other packages that rely on the first word `total' at the beginning of a dired buffer? It seems it would be safer to leave it as is, and add new information to the end of this line like: total used in directory 49439 available 56233408 files 691 Also I think instead of displaying the number of files listed in the current dired buffer, more useful would be to display the total number of files in the current directory. There are features that hide files in the dired buffer (e.g. dired-omit-mode), so displaying the total number of files will be helpful for users to see that there are more hidden files. This also will simplify the implementation of the feature you propose, so instead of a new function `count-dired-files' you can just use (length (directory-files dir nil t)) -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 23+ messages in thread
* RE: patch for Dired second header line info 2008-03-02 2:55 ` Juri Linkov @ 2008-03-02 8:05 ` Drew Adams 2008-03-02 14:36 ` Juri Linkov 0 siblings, 1 reply; 23+ messages in thread From: Drew Adams @ 2008-03-02 8:05 UTC (permalink / raw) To: 'Juri Linkov'; +Cc: emacs-devel > > The second header line in a Dired buffer currently looks like this: > > > > total used in directory 49439 available 56233408 > > > > Attached is a patch (for `files.el' and `ls-lisp.el') that > > changes that text to this: > > > > files 691 space used 49439 available 56233408 > > Are you sure this change will not break other packages that > rely on the first word `total' at the beginning of a dired > buffer? How could I (or anyone) be sure of that? Who knows what some package might rely on? > It seems it would be safer to leave it as is, and > add new information to the end of this line like: > > total used in directory 49439 available 56233408 files 691 Go for it, if you think that's right. I think that the text I used is clearer - see my comments about "total" and "used"/"available". And if some package were to break because of my proposed change, then we would fix the code as needed. If things are so fragile that we don't dare change text such as this, then the design is wrong. In fact, the right way to do this kind of thing is to use a function or variable instead of hard-coded text. But a change to do that might also break some package somewhere. (if omelette (break eggs)) But do as you like. > Also I think instead of displaying the number of files listed > in the current dired buffer, more useful would be to display > the total number of files in the current directory. There are > features that hide files in the dired buffer (e.g. > dired-omit-mode), so displaying the total number of > files will be helpful for users to see that there are more > hidden files. I disagree - it's a feature, not a bug, to see how many files are currently visible. For example, if I use Dired with wildcards, I want to see how many matching files there are. If I hide the files with extension `elc', I want to see how many files are left. And so on. The figure should reflect the current display state. BTW, I did not check until now, but that is also apparently the approach Windows Explorer uses (FWIW). If you hide system files, for instance, the file count excludes them. > This also will simplify the implementation of the feature you propose, > so instead of a new function `count-dired-files' you can just use > (length (directory-files dir nil t)) I purposefully avoided that approach, preferring to have it tell you how many files were currently visible. But do whatever you like with it. Whatever semantics you choose, the doc needs to make clear what the meaning is. Likewise for the other fields. Actually, instead of changing the patch, please ignore it and leave the code as it is. At least that way my extension will continue to work for me. ;-) ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: patch for Dired second header line info 2008-03-02 8:05 ` Drew Adams @ 2008-03-02 14:36 ` Juri Linkov 2008-03-02 16:27 ` Drew Adams 0 siblings, 1 reply; 23+ messages in thread From: Juri Linkov @ 2008-03-02 14:36 UTC (permalink / raw) To: Drew Adams; +Cc: emacs-devel >> Are you sure this change will not break other packages that >> rely on the first word `total' at the beginning of a dired >> buffer? > > How could I (or anyone) be sure of that? Who knows what some package might > rely on? Using one of several code search engines, for instance, http://www.krugle.org/kse/files?query=%22total+used%22&lang=elisp you can find a few packages that rely on the format of this string, including your ls-lisp+.el http://www.emacswiki.org/cgi-bin/wiki/ls-lisp%2B.el. >> Also I think instead of displaying the number of files listed >> in the current dired buffer, more useful would be to display >> the total number of files in the current directory. There are >> features that hide files in the dired buffer (e.g. >> dired-omit-mode), so displaying the total number of >> files will be helpful for users to see that there are more >> hidden files. > > I disagree - it's a feature, not a bug, to see how many files are currently > visible. > > For example, if I use Dired with wildcards, I want to see how many matching > files there are. If I hide the files with extension `elc', I want to see how > many files are left. And so on. The figure should reflect the current > display state. Sorry, it didn't appear to me that the number of listed files would be useful too. But we can display both numbers on the same line using the traditional notation "listed/total", e.g. total used in directory 49439 available 56233408 files 691/1000 > BTW, I did not check until now, but that is also apparently the approach > Windows Explorer uses (FWIW). If you hide system files, for instance, the > file count excludes them. BTW, such file managers also display the number and total size of selected files. I have a function `dired-count-marked-files' that does the same and displays this information in the echo area after marking a file. Maybe instead of the echo area and instead of the header line beginning with `total' we could display this information in the mode line? There is a special mode-line symbol %i and %I (`size-indication-mode') that is not very useful in dired mode. We could use it (or create a new %-construct) to display the total number of selected/all files and their sizes in the mode line in more concise format. -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 23+ messages in thread
* RE: patch for Dired second header line info 2008-03-02 14:36 ` Juri Linkov @ 2008-03-02 16:27 ` Drew Adams 2008-03-02 17:49 ` Drew Adams 2008-03-02 17:56 ` Juri Linkov 0 siblings, 2 replies; 23+ messages in thread From: Drew Adams @ 2008-03-02 16:27 UTC (permalink / raw) To: 'Juri Linkov'; +Cc: emacs-devel > >> Are you sure this change will not break other packages that > >> rely on the first word `total' at the beginning of a dired > >> buffer? > > > > How could I (or anyone) be sure of that? Who knows what > > some package might rely on? > > Using one of several code search engines, for instance, > http://www.krugle.org/kse/files?query=%22total+used%22&lang=elisp > you can find a few packages that rely on the format of this string, > including your ls-lisp+.el > http://www.emacswiki.org/cgi-bin/wiki/ls-lisp%2B.el. 1. It was a rhetorical question. The right way is to use a function or variable, and external packages can then adapt. Avoiding hard-coding would also facilitate translation and other transformations. If there are libraries today that depend on "total" at the beginning of the line, it is because they have no choice. 2. My package ls-lisp+.el is 1/2 of the patch I sent. The other half is in files+.el. IOW, ls-lisp+.el is not an example of an existing package that will be broken by my patch - it _is_ my patch. (These libraries let users of older Emacs users also have the new feature.) > >> Also I think instead of displaying the number of files listed > >> in the current dired buffer, more useful would be to display > >> the total number of files in the current directory. There are > >> features that hide files in the dired buffer (e.g. > >> dired-omit-mode), so displaying the total number of > >> files will be helpful for users to see that there are more > >> hidden files. > > > > I disagree - it's a feature, not a bug, to see how many > > files are currently visible. > > > > For example, if I use Dired with wildcards, I want to see > > how many matching files there are. If I hide the files with > > extension `elc', I want to see how many files are left. > > And so on. The figure should reflect the current > > display state. > > Sorry, it didn't appear to me that the number of listed files would be > useful too. But we can display both numbers on the same line > using the traditional notation "listed/total", e.g. > > total used in directory 49439 available 56233408 files 691/1000 Good idea. Go for it. And perhaps that will obviate the need for `files listed' instead of `files'. I still prefer the order I suggested, and shortening and clarifying `total used in directory' to `space used' or `kbytes used'. > > BTW, I did not check until now, but that is also apparently > > the approach Windows Explorer uses (FWIW). If you hide system > > files, for instance, the file count excludes them. > > BTW, such file managers also display the number and total > size of selected files. Yes. I agree that `files 691/1000' is preferable. BTW, if the meanings of `space used' and `available' were comparable, we could do the same thing there. But one is presumably the space used in the directory, and the other is presumably the space available on the disk, so two labels are needed in that case. > I have a function `dired-count-marked-files' that > does the same and displays this information in the echo area > after marking a file. > > Maybe instead of the echo area and instead of the header line > beginning with `total' we could display this information in the > mode line? That was in fact the starting point for my patch: a help-gnu-emacs question was answered by a post from Kevin Rodgers that used the mode line that way. I specifically want to avoid putting such stuff in the mode line - especially in the minor-mode lighter list. The lighter list has a specific meaning that should not be muddied, and the list is already busy enough. I typically have 3 or 4 minor modes active at the same time. It's true that we already do that kind of thing in some modes (e.g. `grep'), but I think it's bad practice in general and should not be expanded. And this file/space info is not as important as the info we put in the `grep' lighter. A temporary indication of something can sometimes be appropriate in a lighter area, but we shouldn't turn lighters into essays or status lines. Would you also add the space used/available to the Dired lighter? And would you list the used/available figures for every inserted subdir in the mode line? This is a bad idea, IMO. So no, I disagree that the mode line is a good place to put this info. > There is a special mode-line symbol %i and %I (`size-indication-mode') > that is not very useful in dired mode. We could use it (or > create a new %-construct) to display the total number of selected/all > files and their sizes in the mode line in more concise format. I vote against it. Just one vote. ^ permalink raw reply [flat|nested] 23+ messages in thread
* RE: patch for Dired second header line info 2008-03-02 16:27 ` Drew Adams @ 2008-03-02 17:49 ` Drew Adams 2008-03-02 17:57 ` Juri Linkov 2008-03-03 18:27 ` Richard Stallman 2008-03-02 17:56 ` Juri Linkov 1 sibling, 2 replies; 23+ messages in thread From: Drew Adams @ 2008-03-02 17:49 UTC (permalink / raw) To: 'Juri Linkov'; +Cc: emacs-devel [-- Attachment #1: Type: text/plain, Size: 500 bytes --] > > Sorry, it didn't appear to me that the number of listed > > files would be useful too. But we can display both numbers on > > the same line using the traditional notation "listed/total"... > > Good idea. Go for it. And perhaps that will obviate the need > for `files listed' instead of `files'. Attached: patch for this. The text is now: files 420/694 space used 19646 available 56456000 Meaning: 420 files shown now, out of 694 total in the directory. Subdirs are treated the same way. [-- Attachment #2: files-2008-03-02.patch --] [-- Type: application/octet-stream, Size: 3805 bytes --] diff -c -w "files-CVS-2008-02-29.el" "files-patched-2008-03-02.el" *** files-CVS-2008-02-29.el Fri Feb 29 14:59:08 2008 --- files-patched-2008-03-02.el Sun Mar 2 09:39:54 2008 *************** *** 5284,5303 **** (if val (put-text-property pos (point) 'dired-filename t))))))) ! ! (if full-directory-p ! ;; Try to insert the amount of free space. (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))))))))))) (defun insert-directory-adj-pos (pos error-lines) "Convert `ls --dired' file name position value POS to a buffer position. File name position values returned in ls --dired output --- 5284,5338 ---- (if val (put-text-property pos (point) 'dired-filename t))))))) ! (when full-directory-p (save-excursion (goto-char beg) ! (while (re-search-forward "^ *\\(total\\)" nil t) ! (beginning-of-line) ! (insert "files " (number-to-string (save-match-data ! (count-dired-files))) ! "/" (number-to-string ! (- (length (directory-files file 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 ".")))) (when available (end-of-line) (insert " available " available))))))))))) + (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 `..'." + ;; Should we skip `#' files also, as in `dired-trivial-filenames'? Dunno. + (save-excursion + (re-search-backward "^$" nil 'to-bob) + (re-search-forward dired-move-to-filename-regexp nil t) + (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." + (let ((num-files (number-to-string (count-dired-files)))) + (save-excursion + (goto-char (point-min)) + (while (re-search-forward "^ files \\([0-9]+\\)" nil t) + (let ((buffer-read-only nil)) + (replace-match (number-to-string (save-match-data (count-dired-files))) + nil nil nil 1)) + (set-buffer-modified-p nil))))) + (defun insert-directory-adj-pos (pos error-lines) "Convert `ls --dired' file name position value POS to a buffer position. File name position values returned in ls --dired output Diff finished at Sun Mar 02 09:41:59 [-- Attachment #3: ls-lisp-2008-03-02.patch --] [-- Type: application/octet-stream, Size: 1592 bytes --] diff -c -w "ls-lisp-CVS-2008-02-29.el" "ls-lisp-patched-2008-03-02.el" *** ls-lisp-CVS-2008-02-29.el Fri Feb 29 14:58:50 2008 --- ls-lisp-patched-2008-03-02.el Sun Mar 2 09:41:04 2008 *************** *** 263,274 **** ;; Try to insert the amount of free space. (save-excursion (goto-char (point-min)) ! ;; 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 "total used", to avoid confusion. - (replace-match "total used in directory") (end-of-line) (insert " available " available))))))))) --- 263,281 ---- ;; Try to insert the amount of free space. (save-excursion (goto-char (point-min)) ! (while (re-search-forward "^total" nil t) ! (beginning-of-line) ! (insert "files " (number-to-string (save-match-data ! (count-dired-files))) ! "/" (number-to-string ! (- (length (directory-files file nil nil t)) 2)) ! " ") ! (goto-char (point-min)) ! (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 ".")))) (when available (end-of-line) (insert " available " available))))))))) Diff finished at Sun Mar 02 09:43:22 ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: patch for Dired second header line info 2008-03-02 17:49 ` Drew Adams @ 2008-03-02 17:57 ` Juri Linkov 2008-03-02 18:56 ` Drew Adams 2008-03-03 18:27 ` Richard Stallman 2008-03-03 18:27 ` Richard Stallman 1 sibling, 2 replies; 23+ messages in thread From: Juri Linkov @ 2008-03-02 17:57 UTC (permalink / raw) To: Drew Adams; +Cc: emacs-devel >> > Sorry, it didn't appear to me that the number of listed >> > files would be useful too. But we can display both numbers on >> > the same line using the traditional notation "listed/total"... >> >> Good idea. Go for it. And perhaps that will obviate the need >> for `files listed' instead of `files'. > > Attached: patch for this. The text is now: > > files 420/694 space used 19646 available 56456000 The string `total' is the standard string printed by `ls' so maybe we should keep it. Also what do you think about further compacting this line as: total files 420/694 space 19646/56456000 or using the same function in `size-indication-mode' that displays the size in the mode line in human-readable format: total files 420/694 space 19KB/56MB Also we could add a tooltip explaining what these numbers mean if they are not obvious. > Meaning: 420 files shown now, out of 694 total in the directory. Subdirs are > treated the same way. In your patch maybe better to move dired functionality to dired.el or dired-aux.el and rename `count-dired-files' to `dired-count-files'. -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 23+ messages in thread
* RE: patch for Dired second header line info 2008-03-02 17:57 ` Juri Linkov @ 2008-03-02 18:56 ` Drew Adams 2008-03-02 19:06 ` Drew Adams 2008-03-03 18:27 ` Richard Stallman 1 sibling, 1 reply; 23+ messages in thread From: Drew Adams @ 2008-03-02 18:56 UTC (permalink / raw) To: 'Juri Linkov'; +Cc: emacs-devel [-- Attachment #1: Type: text/plain, Size: 1322 bytes --] > > Attached: patch for this. The text is now: > > > > files 420/694 space used 19646 available 56456000 > > The string `total' is the standard string printed by `ls' so maybe we > should keep it. Also what do you think about further compacting > this line as: > > total files 420/694 space 19646/56456000 I already said that I find "total" unclear and I prefer the form I proposed. > or using the same function in `size-indication-mode' that displays the > size in the mode line in human-readable format: > > total files 420/694 space 19KB/56MB That might be OK, but what's wrong with giving a more precise number? That's typically what is given for this kind of thing. > Also we could add a tooltip explaining what these numbers mean if they > are not obvious. > > > Meaning: 420 files shown now, out of 694 total in the > directory. Subdirs are > > treated the same way. Great minds think alike. I was already doing that - new patch attached. (Also fixed a bug introduced in last patch.) (The text should say nothing about subdirs, BTW - each subdir has its own tooltip.) > In your patch maybe better to move dired functionality to dired.el or > dired-aux.el and rename `count-dired-files' to `dired-count-files'. I'll leave that to others to decide. My proposal just leaves things where they are now. [-- Attachment #2: files-2008-03-02b.patch --] [-- Type: application/octet-stream, Size: 4039 bytes --] diff -c -w files-CVS-2008-02-29.el files-patched-2008-03-02b.el *** files-CVS-2008-02-29.el Fri Feb 29 14:59:08 2008 --- files-patched-2008-03-02b.el Sun Mar 2 10:49:54 2008 *************** *** 5284,5302 **** (if val (put-text-property pos (point) 'dired-filename t))))))) ! ! (if full-directory-p ! ;; Try to insert the amount of free space. (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))))))))))) (defun insert-directory-adj-pos (pos error-lines) "Convert `ls --dired' file name position value POS to a buffer position. --- 5284,5342 ---- (if val (put-text-property pos (point) 'dired-filename t))))))) ! (when full-directory-p (save-excursion (goto-char beg) ! (while (re-search-forward "^ *\\(total\\)" nil t) ! (beginning-of-line) ! (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 ".")))) (when available (end-of-line) ! (insert " available " available))) ! (put-text-property (progn (beginning-of-line) (point)) ! (progn (end-of-line) (point)) ! 'help-echo "Files shown, total files in \ ! dir, Kbytes used in dir, Kbytes available on disk"))))))))) ! ! (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 `..'." ! ;; Should we skip `#' files also, as in `dired-trivial-filenames'? Dunno. ! (save-excursion ! (re-search-backward "^$" nil 'to-bob) ! (re-search-forward dired-move-to-filename-regexp nil t) ! (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." ! (let ((num-files (number-to-string (count-dired-files)))) ! (save-excursion ! (goto-char (point-min)) ! (while (re-search-forward "^ files \\([0-9]+\\)" nil t) ! (let ((buffer-read-only nil)) ! (replace-match (number-to-string (save-match-data (count-dired-files))) ! nil nil nil 1)) ! (set-buffer-modified-p nil))))) (defun insert-directory-adj-pos (pos error-lines) "Convert `ls --dired' file name position value POS to a buffer position. Diff finished. Sun Mar 02 10:53:36 2008 [-- Attachment #3: ls-lisp-2008-03-02b.patch --] [-- Type: application/octet-stream, Size: 2360 bytes --] diff -c -w ls-lisp-CVS-2008-02-29.el ls-lisp-patched-2008-03-02b.el *** ls-lisp-CVS-2008-02-29.el Fri Feb 29 14:58:50 2008 --- ls-lisp-patched-2008-03-02b.el Sun Mar 2 10:51:18 2008 *************** *** 260,276 **** file switches (ls-lisp-time-index switches) nil full-directory-p)) (signal (car err) (cdr err))))) - ;; Try to insert the amount of free space. (save-excursion (goto-char (point-min)) ! ;; 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 "total used", to avoid confusion. - (replace-match "total used in directory") (end-of-line) ! (insert " available " available))))))))) (defun ls-lisp-insert-directory (file switches time-index wildcard-regexp full-directory-p) --- 260,287 ---- file switches (ls-lisp-time-index switches) nil full-directory-p)) (signal (car err) (cdr err))))) (save-excursion (goto-char (point-min)) ! (while (re-search-forward "^total" nil t) ! (beginning-of-line) ! (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 (point-min)) ! (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 ".")))) (when available (end-of-line) ! (insert " available " available))) ! (put-text-property (progn (beginning-of-line) (point)) ! (progn (end-of-line) (point)) ! 'help-echo "Files shown, total files in \ ! dir, Kbytes used in dir, Kbytes available on disk"))))))) (defun ls-lisp-insert-directory (file switches time-index wildcard-regexp full-directory-p) Diff finished. Sun Mar 02 10:51:42 2008 ^ permalink raw reply [flat|nested] 23+ messages in thread
* RE: patch for Dired second header line info 2008-03-02 18:56 ` Drew Adams @ 2008-03-02 19:06 ` Drew Adams 2008-03-03 0:47 ` Drew Adams 0 siblings, 1 reply; 23+ messages in thread From: Drew Adams @ 2008-03-02 19:06 UTC (permalink / raw) To: 'Juri Linkov'; +Cc: emacs-devel [-- Attachment #1: Type: text/plain, Size: 196 bytes --] > Great minds think alike. I was already doing that - new patch > attached. (Also fixed a bug introduced in last patch.) Sorry, I forgot to include that bug fix in the files.el patch. Attached. [-- Attachment #2: files-2008-03-02c.patch --] [-- Type: application/octet-stream, Size: 4289 bytes --] diff -c -w "files-CVS-2008-02-29.el" "files-patched-2008-03-02c.el" *** files-CVS-2008-02-29.el Fri Feb 29 14:59:08 2008 --- files-patched-2008-03-02c.el Sun Mar 2 11:02:58 2008 *************** *** 5284,5302 **** (if val (put-text-property pos (point) 'dired-filename t))))))) ! ! (if full-directory-p ! ;; Try to insert the amount of free space. (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))))))))))) (defun insert-directory-adj-pos (pos error-lines) "Convert `ls --dired' file name position value POS to a buffer position. --- 5284,5346 ---- (if val (put-text-property pos (point) 'dired-filename t))))))) ! (when full-directory-p (save-excursion (goto-char beg) ! (while (re-search-forward "^ *\\(total\\)" nil t) ! (beginning-of-line) ! (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 ".")))) (when available (end-of-line) ! (insert " available " available))) ! (put-text-property (progn (beginning-of-line) (point)) ! (progn (end-of-line) (point)) ! 'help-echo "Files shown, total files in \ ! dir, Kbytes used in dir, Kbytes available on disk"))))))))) ! ! (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 `..'." ! ;; Should we skip `#' files also, as in `dired-trivial-filenames'? Dunno. ! (save-excursion ! (re-search-backward "^$" nil 'to-bob) ! (re-search-forward dired-move-to-filename-regexp nil t) ! (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." ! (let ((num-files (number-to-string (count-dired-files)))) ! (save-excursion ! (goto-char (point-min)) ! (while (re-search-forward "^ files \\([0-9]+\\)/\\([0-9]+\\)" nil t) ! (let ((buffer-read-only nil)) ! (replace-match (number-to-string (save-match-data (count-dired-files))) ! nil nil nil 1) ! (replace-match (number-to-string ! (- (length (directory-files default-directory ! nil nil t)) 2)) ! nil nil nil 2)) ! (set-buffer-modified-p nil))))) (defun insert-directory-adj-pos (pos error-lines) "Convert `ls --dired' file name position value POS to a buffer position. Diff finished at Sun Mar 02 11:03:47 [-- Attachment #3: ls-lisp-2008-03-02b.patch --] [-- Type: application/octet-stream, Size: 2360 bytes --] diff -c -w ls-lisp-CVS-2008-02-29.el ls-lisp-patched-2008-03-02b.el *** ls-lisp-CVS-2008-02-29.el Fri Feb 29 14:58:50 2008 --- ls-lisp-patched-2008-03-02b.el Sun Mar 2 10:51:18 2008 *************** *** 260,276 **** file switches (ls-lisp-time-index switches) nil full-directory-p)) (signal (car err) (cdr err))))) - ;; Try to insert the amount of free space. (save-excursion (goto-char (point-min)) ! ;; 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 "total used", to avoid confusion. - (replace-match "total used in directory") (end-of-line) ! (insert " available " available))))))))) (defun ls-lisp-insert-directory (file switches time-index wildcard-regexp full-directory-p) --- 260,287 ---- file switches (ls-lisp-time-index switches) nil full-directory-p)) (signal (car err) (cdr err))))) (save-excursion (goto-char (point-min)) ! (while (re-search-forward "^total" nil t) ! (beginning-of-line) ! (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 (point-min)) ! (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 ".")))) (when available (end-of-line) ! (insert " available " available))) ! (put-text-property (progn (beginning-of-line) (point)) ! (progn (end-of-line) (point)) ! 'help-echo "Files shown, total files in \ ! dir, Kbytes used in dir, Kbytes available on disk"))))))) (defun ls-lisp-insert-directory (file switches time-index wildcard-regexp full-directory-p) Diff finished. Sun Mar 02 10:51:42 2008 ^ permalink raw reply [flat|nested] 23+ messages in thread
* RE: patch for Dired second header line info 2008-03-02 19:06 ` Drew Adams @ 2008-03-03 0:47 ` Drew Adams 0 siblings, 0 replies; 23+ messages in thread From: Drew Adams @ 2008-03-03 0:47 UTC (permalink / raw) To: 'Juri Linkov'; +Cc: emacs-devel [-- Attachment #1: Type: text/plain, Size: 1542 bytes --] New patch attached, for consideration as an alternative to the previous one. They are the same except for the following new feature, which you might or might not like: The directory info line has mouse-face highlighting. Hitting RET or clicking mouse-2 on it displays more info about the directory, in buffer *Help*. This is what the *Help* display looks like: Properties of `c:/foobar': Type: Directory Permissions: drwxrwxrwx Time of last access: Sun Mar 2 00:00:00 2008 (Pacific Standard Time) Time of last modification: Tue Aug 21 19:21:00 2007 (Pacific Standard Time) Time of last status change: Tue Aug 21 19:20:59 2007 (Pacific Standard Time) Number of links: 1 User ID (UID): 5 Group ID (GID): 5 Inode: 26687 Device number: 240391127 [back] Obviously, a different choice could be made for the time format. Just as obviously, some of this info is already displayed in the Dired buffer, unless you use `dired-details-hide' (did that ever get added to Emacs?) to hide the details. The help commands involved are general. I added them to files.el, but you might want to do one or more of the following: 1. Move `describe-file' to help-fns.el (and bind it to, say, `C-h M-f'). 2. Move `dired(-mouse)-describe-file' to dired.el. 3. Move `dired(-mouse)-describe-listed-directory' to dired.el. The commands in #3 are used only in `insert-directory', however, so you might prefer to keep them in files.el. [-- Attachment #2: ls-lisp-2008-03-02c.patch --] [-- Type: application/octet-stream, Size: 2729 bytes --] diff -c -w ls-lisp-CVS-2008-02-29.el ls-lisp-patched-2008-03-02c.el *** ls-lisp-CVS-2008-02-29.el Fri Feb 29 14:58:50 2008 --- ls-lisp-patched-2008-03-02c.el Sun Mar 2 15:53:20 2008 *************** *** 260,276 **** file switches (ls-lisp-time-index switches) nil full-directory-p)) (signal (car err) (cdr err))))) - ;; Try to insert the amount of free space. (save-excursion (goto-char (point-min)) ! ;; 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 "total used", to avoid confusion. - (replace-match "total used in directory") (end-of-line) ! (insert " available " available))))))))) (defun ls-lisp-insert-directory (file switches time-index wildcard-regexp full-directory-p) --- 260,295 ---- file switches (ls-lisp-time-index switches) nil full-directory-p)) (signal (car err) (cdr err))))) (save-excursion (goto-char (point-min)) ! (while (re-search-forward "^total" nil t) ! (beginning-of-line) ! (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 (point-min)) ! (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 ".")))) (when available (end-of-line) ! (insert " available " available))) ! (add-text-properties ! (save-excursion (beginning-of-line) (point)) ! (save-excursion (end-of-line) (point)) ! `(mouse-face highlight ! keymap ! ,(let ((map (make-sparse-keymap))) ! (define-key map [mouse-2] ! 'dired-mouse-describe-listed-directory) ! (define-key map "\r" 'dired-describe-listed-directory) ! map) ! help-echo "Files shown, total files in dir, Kbytes \ ! used in dir, Kbytes available on disk [RET, mouse-2: more info]")))))))) (defun ls-lisp-insert-directory (file switches time-index wildcard-regexp full-directory-p) Diff finished. Sun Mar 02 15:53:46 2008 [-- Attachment #3: files-2008-03-02d.patch --] [-- Type: application/octet-stream, Size: 9008 bytes --] diff -c -w "files-CVS-2008-02-29.el" "files-patched-2008-03-02e.el" *** files-CVS-2008-02-29.el Fri Feb 29 14:59:08 2008 --- files-patched-2008-03-02e.el Sun Mar 2 16:31:56 2008 *************** *** 5284,5302 **** (if val (put-text-property pos (point) 'dired-filename t))))))) ! ! (if full-directory-p ! ;; Try to insert the amount of free space. (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))))))))))) (defun insert-directory-adj-pos (pos error-lines) "Convert `ls --dired' file name position value POS to a buffer position. --- 5284,5446 ---- (if val (put-text-property pos (point) 'dired-filename t))))))) ! (when full-directory-p (save-excursion (goto-char beg) ! (while (re-search-forward "^ *\\(total\\)" nil t) ! (beginning-of-line) ! (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 ".")))) (when available (end-of-line) ! (insert " available " available))) ! (add-text-properties ! (save-excursion (beginning-of-line) (point)) ! (save-excursion (end-of-line) (point)) ! `(mouse-face highlight ! keymap ! ,(let ((map (make-sparse-keymap))) ! (define-key map [mouse-2] ! 'dired-mouse-describe-listed-directory) ! (define-key map "\r" 'dired-describe-listed-directory) ! map) ! help-echo "Files shown, total files in dir, Kbytes \ ! used in dir, Kbytes available on disk [RET, mouse-2: more info]")))))))))) ! ! (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 `..'." ! ;; Should we skip `#' files also, as in `dired-trivial-filenames'? Dunno. ! (save-excursion ! (re-search-backward "^$" nil 'to-bob) ! (re-search-forward dired-move-to-filename-regexp nil t) ! (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." ! (let ((num-files (number-to-string (count-dired-files)))) ! (save-excursion ! (goto-char (point-min)) ! (while (re-search-forward "^ files \\([0-9]+\\)/\\([0-9]+\\)" nil t) ! (let ((buffer-read-only nil)) ! (replace-match (number-to-string (save-match-data (count-dired-files))) ! nil nil nil 1) ! (replace-match (number-to-string ! (- (length (directory-files default-directory ! nil nil t)) 2)) ! nil nil nil 2) ! (add-text-properties ! (save-excursion (beginning-of-line) (point)) ! (save-excursion (end-of-line) (point)) ! `(mouse-face highlight ! keymap ! ,(let ((map (make-sparse-keymap))) ! (define-key map [mouse-2] ! 'dired-mouse-describe-listed-directory) ! (define-key map "\r" 'dired-describe-listed-directory) ! map) ! help-echo "Files shown, total files in dir, Kbytes \ ! used in dir, Kbytes available on disk [RET, mouse-2: more info]"))) ! (set-buffer-modified-p nil))))) ! ! (defun dired-describe-listed-directory () ! "In Dired, describe the current listed directory." ! (interactive) ! (let ((dirname (save-excursion ! (forward-line -1) ! (skip-syntax-forward " ") ! (buffer-substring ! (point) ! (save-excursion (end-of-line) (1- (point))))))) ; Up to colon. ! ! (describe-file dirname))) ! ! (defun dired-mouse-describe-listed-directory (event) ! "Describe the current listed directory." ! (interactive "e") ! (save-excursion ! (set-buffer (window-buffer (posn-window (event-end event)))) ! (goto-char (posn-point (event-end event))) ! (dired-describe-listed-directory))) ! ! (defun dired-describe-file () ! "In Dired, describe this file or directory." ! (interactive) ! (describe-file (dired-get-filename nil t))) ! ! (defun dired-mouse-describe-file (event) ! "Describe the clicked file." ! (interactive "e") ! (let (file) ! (save-excursion ! (set-buffer (window-buffer (posn-window (event-end event)))) ! (goto-char (posn-point (event-end event))) ! (setq file (dired-get-filename nil t))) ! (describe-file file))) ! ! ;; This is the same definition as in `help-fns+.el' and `help+20.el'. ! (defun describe-file (filename) ! "Describe the file named FILENAME. ! If FILENAME is nil, describe the current directory." ! (interactive "FDescribe file: ") ! (unless filename (setq filename default-directory)) ! (help-setup-xref (list #'describe-file filename) (interactive-p)) ! (let ((attrs (file-attributes filename))) ! (unless attrs (error(format "Cannot open file `%s'" filename))) ! (let* ((type (nth 0 attrs)) ! (numlinks (nth 1 attrs)) ! (uid (nth 2 attrs)) ! (gid (nth 3 attrs)) ! (last-access (nth 4 attrs)) ! (last-mod (nth 5 attrs)) ! (last-status-chg (nth 6 attrs)) ! (size (nth 7 attrs)) ! (permissions (nth 8 attrs)) ! ;; Skip 9: t iff file's gid would change if file were deleted ! ;; and recreated. ! (inode (nth 10 attrs)) ! (device (nth 11 attrs)) ! (help-text ! (concat ! (format "Properties of `%s':\n\n" filename) ! (format "Type: %s\n" ! (cond ((eq t type) "Directory") ! ((stringp type) (format "Symbolic link to `%s'" type)) ! (t "Normal file"))) ! (format "Permissions: %s\n" permissions) ! (and (not (eq t type)) (format "Size in bytes: %g\n" size)) ! (format-time-string ! "Time of last access: %a %b %e %T %Y (%Z)\n" last-access) ! (format-time-string ! "Time of last modification: %a %b %e %T %Y (%Z)\n" last-mod) ! (format-time-string ! "Time of last status change: %a %b %e %T %Y (%Z)\n" last-status-chg) ! (format "Number of links: %d\n" numlinks) ! (format "User ID (UID): %s\n" uid) ! (format "Group ID (GID): %s\n" gid) ! (format "Inode: %S\n" inode) ! (format "Device number: %s\n" device)))) ! (with-output-to-temp-buffer "*Help*" (princ help-text)) ! help-text))) ; Return displayed text. (defun insert-directory-adj-pos (pos error-lines) "Convert `ls --dired' file name position value POS to a buffer position. Diff finished at Sun Mar 02 16:32:32 ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: patch for Dired second header line info 2008-03-02 17:57 ` Juri Linkov 2008-03-02 18:56 ` Drew Adams @ 2008-03-03 18:27 ` Richard Stallman 2008-03-03 21:45 ` Stefan Monnier 1 sibling, 1 reply; 23+ messages in thread From: Richard Stallman @ 2008-03-03 18:27 UTC (permalink / raw) To: Juri Linkov; +Cc: drew.adams, emacs-devel The string `total' is the standard string printed by `ls' so maybe we should keep it. Also what do you think about further compacting this line as: total files 420/694 space 19646/56456000 That is extremely misleading, since the first is VISIBLE/IN-DIR and the second is IN-DIR/TOTAL. In other words, the 694 is analogous to the 19646, but 694 comes second in a pair, while 19646 comes first in a pair. Also we could add a tooltip explaining what these numbers mean if they are not obvious. Using a tooltip to explain could be a good idea, but we should still try to make it clearer in the text. There is no shortage of space in that line. ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: patch for Dired second header line info 2008-03-03 18:27 ` Richard Stallman @ 2008-03-03 21:45 ` Stefan Monnier 2008-03-03 22:29 ` Drew Adams 0 siblings, 1 reply; 23+ messages in thread From: Stefan Monnier @ 2008-03-03 21:45 UTC (permalink / raw) To: rms; +Cc: Juri Linkov, drew.adams, emacs-devel > total files 420/694 space 19646/56456000 > That is extremely misleading, since the first is > VISIBLE/IN-DIR and the second is IN-DIR/TOTAL. > In other words, the 694 is analogous to the 19646, > but 694 comes second in a pair, while 19646 comes first in a pair. I believe it's worse than that: it's not IN-DIR/TOTAL but BYES-USED-IN-DIR/BYTES-LEFT-ON-DISK, i.e. the second number may be smaller than the first. Stefan ^ permalink raw reply [flat|nested] 23+ messages in thread
* RE: patch for Dired second header line info 2008-03-03 21:45 ` Stefan Monnier @ 2008-03-03 22:29 ` Drew Adams 2008-03-04 17:38 ` Richard Stallman 0 siblings, 1 reply; 23+ messages in thread From: Drew Adams @ 2008-03-03 22:29 UTC (permalink / raw) To: 'Stefan Monnier', rms; +Cc: 'Juri Linkov', emacs-devel > > total files 420/694 space 19646/56456000 > > > That is extremely misleading, since the first is > > VISIBLE/IN-DIR and the second is IN-DIR/TOTAL. > > In other words, the 694 is analogous to the 19646, > > but 694 comes second in a pair, while 19646 comes first in a pair. > > I believe it's worse than that: it's not IN-DIR/TOTAL but > BYES-USED-IN-DIR/BYTES-LEFT-ON-DISK, i.e. the second number may be > smaller than the first. That was my guess also. Which is why, although I used "files 420/694", I used "space used 19646 available 56456000". The tooltip also helps: "Files shown, total files in dir, Kbytes used in dir, Kbytes available on disk [RET, mouse-2: more info]" IMO, it's not worth adding a lot of text for this to the buffer, but a tooltip can help clarify things - for example, that "space used" refers to the directory, but "available" refers to free disk space (independent of any directory). ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: patch for Dired second header line info 2008-03-03 22:29 ` Drew Adams @ 2008-03-04 17:38 ` Richard Stallman 2008-03-04 19:44 ` Drew Adams 0 siblings, 1 reply; 23+ messages in thread From: Richard Stallman @ 2008-03-04 17:38 UTC (permalink / raw) To: Drew Adams; +Cc: juri, monnier, emacs-devel The tooltip also helps: "Files shown, total files in dir, Kbytes used in dir, Kbytes available on disk [RET, mouse-2: more info]" Each number should have its own tooltip which explains that number and not the others. ^ permalink raw reply [flat|nested] 23+ messages in thread
* RE: patch for Dired second header line info 2008-03-04 17:38 ` Richard Stallman @ 2008-03-04 19:44 ` Drew Adams 2008-03-04 22:28 ` Drew Adams 2008-03-05 21:33 ` Richard Stallman 0 siblings, 2 replies; 23+ messages in thread From: Drew Adams @ 2008-03-04 19:44 UTC (permalink / raw) To: rms; +Cc: juri, monnier, emacs-devel > The tooltip also helps: > > "Files shown, total files in dir, Kbytes used in dir, > Kbytes available on disk [RET, mouse-2: more info]" > > Each number should have its own tooltip which explains that number > and not the others. Sorry; I don't agree. The meanings of the numbers are related (similar), at least in pairs. Four separate tooltips would be more an annoyance than a help, because the similarities and differences can't be grasped without a silly back-and-forth: 420: Number of files and subdirectories currently shown in directory 694: Number of files and subdirectories in directory, including hidden ones 19646: Kbytes used in directory 56456000: Kbytes available (free) on disk To understand 420 or 694, for instance, you would need to go back and forth between their tooltips, trying to remember what the non-displayed tooltip said while reading the displayed one, and comparing them mentally, in order to grasp the difference. Two tooltips, for the two pairs, might be reasonable, however. In any case, change it however you like. ^ permalink raw reply [flat|nested] 23+ messages in thread
* RE: patch for Dired second header line info 2008-03-04 19:44 ` Drew Adams @ 2008-03-04 22:28 ` Drew Adams 2008-03-05 21:33 ` Richard Stallman 1 sibling, 0 replies; 23+ messages in thread From: Drew Adams @ 2008-03-04 22:28 UTC (permalink / raw) To: rms; +Cc: juri, monnier, emacs-devel [-- Attachment #1: Type: text/plain, Size: 1742 bytes --] > > The tooltip also helps: > > > > "Files shown, total files in dir, Kbytes used in dir, > > Kbytes available on disk [RET, mouse-2: more info]" > > > > Each number should have its own tooltip which explains that number > > and not the others. > > Sorry; I don't agree. The meanings of the numbers are related > (similar), at > least in pairs. Four separate tooltips would be more an > annoyance than a > help, because the similarities and differences can't be > grasped without a > silly back-and-forth: > > 420: Number of files and subdirectories currently shown in directory > > 694: Number of files and subdirectories in directory, > including hidden ones > > 19646: Kbytes used in directory > > 56456000: Kbytes available (free) on disk > > To understand 420 or 694, for instance, you would need to go > back and forth between their tooltips, trying to remember what the > non-displayed tooltip said while reading the displayed one, and > comparing them mentally, in order to grasp the difference. > > Two tooltips, for the two pairs, might be reasonable, however. > > In any case, change it however you like. 1. OK, attached is a patch that does what I suggested (two tooltips, not 1 or 4). 2. The patch also fixes the problem of not updating when you perform update operations, such as add a file or directory. However, there remains a case where updating does not refresh the info line: file deletion. For some reason, `dired-after-readin-hook' is not run when you delete files. Is that perhaps a dired bug, or is it by design? `dired-internal-do-deletions' is called whether you flag a file and then use `x' or you mark it and then use `D'. Should `dired-internal-do-deletions' run the hook? HTH. [-- Attachment #2: files-2008-03-04a.patch --] [-- Type: application/octet-stream, Size: 9006 bytes --] diff -c -w "files-CVS-2008-02-29.el" "files-patched-2008-03-04a.el" *** files-CVS-2008-02-29.el Fri Feb 29 14:59:08 2008 --- files-patched-2008-03-04a.el Tue Mar 4 14:04:36 2008 *************** *** 5284,5302 **** (if val (put-text-property pos (point) 'dired-filename t))))))) ! ! (if full-directory-p ! ;; Try to insert the amount of free space. (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))))))))))) (defun insert-directory-adj-pos (pos error-lines) "Convert `ls --dired' file name position value POS to a buffer position. --- 5284,5444 ---- (if val (put-text-property pos (point) 'dired-filename t))))))) ! (when full-directory-p ! (save-excursion ! (goto-char beg) ! (while (re-search-forward "^ *\\(total\\)" nil t) ! (beginning-of-line) ! (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 ! (save-excursion (beginning-of-line) (+ 2 (point))) ! (1- (match-beginning 1)) ! `(mouse-face highlight keymap ,map ! help-echo "Files shown / total files in directory \ ! \[RET, mouse-2: more info]")) ! (add-text-properties ! (match-beginning 1) (save-excursion (end-of-line) (point)) ! `(mouse-face highlight keymap ,map ! help-echo "Kbytes used in directory, Kbytes \ ! available on disk [RET, mouse-2: more info]"))))))))))) ! ! (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 `..'." ! ;; Should we skip `#' files also, as in `dired-trivial-filenames'? Dunno. (save-excursion + (re-search-backward "^$" nil 'to-bob) + (re-search-forward dired-move-to-filename-regexp nil t) + (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 (number-to-string (count-dired-files)))) ! (save-excursion ! (goto-char (point-min)) ! (while (re-search-forward "^ files \\([0-9]+\\)/\\([0-9]+\\)" nil t) ! (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 (number-to-string (save-match-data (count-dired-files))) ! nil nil nil 1) ! (replace-match (number-to-string ! (- (length (directory-files default-directory ! nil nil t)) 2)) ! nil nil nil 2) ! (add-text-properties ! (save-excursion (beginning-of-line) (+ 2 (point))) (match-end 2) ! `(mouse-face highlight keymap ,map ! help-echo "Files shown / total files in directory \ ! \[RET, mouse-2: more info]"))) ! (set-buffer-modified-p nil)))))) ! ! (defun dired-describe-listed-directory () ! "In Dired, describe the current listed directory." ! (interactive) ! (let ((dirname (save-excursion ! (forward-line -1) ! (skip-syntax-forward " ") ! (buffer-substring ! (point) ! (save-excursion (end-of-line) (1- (point))))))) ; Up to colon. ! ! (describe-file dirname))) ! ! (defun dired-mouse-describe-listed-directory (event) ! "Describe the current listed directory." ! (interactive "e") ! (save-excursion ! (set-buffer (window-buffer (posn-window (event-end event)))) ! (goto-char (posn-point (event-end event))) ! (dired-describe-listed-directory))) ! ! (defun dired-describe-file () ! "In Dired, describe this file or directory." ! (interactive) ! (describe-file (dired-get-filename nil t))) ! ! (defun dired-mouse-describe-file (event) ! "Describe the clicked file." ! (interactive "e") ! (let (file) ! (save-excursion ! (set-buffer (window-buffer (posn-window (event-end event)))) ! (goto-char (posn-point (event-end event))) ! (setq file (dired-get-filename nil t))) ! (describe-file file))) ! ! ;; This is the same definition as in `help-fns+.el' and `help+20.el'. ! (defun describe-file (filename) ! "Describe the file named FILENAME. ! If FILENAME is nil, describe the current directory." ! (interactive "FDescribe file: ") ! (unless filename (setq filename default-directory)) ! (help-setup-xref (list #'describe-file filename) (interactive-p)) ! (let ((attrs (file-attributes filename))) ! (unless attrs (error(format "Cannot open file `%s'" filename))) ! (let* ((type (nth 0 attrs)) ! (numlinks (nth 1 attrs)) ! (uid (nth 2 attrs)) ! (gid (nth 3 attrs)) ! (last-access (nth 4 attrs)) ! (last-mod (nth 5 attrs)) ! (last-status-chg (nth 6 attrs)) ! (size (nth 7 attrs)) ! (permissions (nth 8 attrs)) ! ;; Skip 9: t iff file's gid would change if file were deleted ! ;; and recreated. ! (inode (nth 10 attrs)) ! (device (nth 11 attrs)) ! (help-text ! (concat ! (format "Properties of `%s':\n\n" filename) ! (format "Type: %s\n" ! (cond ((eq t type) "Directory") ! ((stringp type) (format "Symbolic link to `%s'" type)) ! (t "Normal file"))) ! (format "Permissions: %s\n" permissions) ! (and (not (eq t type)) (format "Size in bytes: %g\n" size)) ! (format-time-string ! "Time of last access: %a %b %e %T %Y (%Z)\n" last-access) ! (format-time-string ! "Time of last modification: %a %b %e %T %Y (%Z)\n" last-mod) ! (format-time-string ! "Time of last status change: %a %b %e %T %Y (%Z)\n" last-status-chg) ! (format "Number of links: %d\n" numlinks) ! (format "User ID (UID): %s\n" uid) ! (format "Group ID (GID): %s\n" gid) ! (format "Inode: %S\n" inode) ! (format "Device number: %s\n" device)))) ! (with-output-to-temp-buffer "*Help*" (princ help-text)) ! help-text))) ; Return displayed text. (defun insert-directory-adj-pos (pos error-lines) "Convert `ls --dired' file name position value POS to a buffer position. [-- Attachment #3: ls-lisp-2008-03-04a.patch --] [-- Type: application/octet-stream, Size: 2911 bytes --] diff -c -w "ls-lisp-CVS-2008-02-29.el" "ls-lisp-patched-2008-03-04a.el" *** ls-lisp-CVS-2008-02-29.el Fri Feb 29 14:58:50 2008 --- ls-lisp-patched-2008-03-04a.el Tue Mar 4 14:03:20 2008 *************** *** 260,276 **** file switches (ls-lisp-time-index switches) nil full-directory-p)) (signal (car err) (cdr err))))) - ;; Try to insert the amount of free space. (save-excursion (goto-char (point-min)) ! ;; 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 "total used", to avoid confusion. ! (replace-match "total used in directory") ! (end-of-line) ! (insert " available " available))))))))) (defun ls-lisp-insert-directory (file switches time-index wildcard-regexp full-directory-p) --- 260,298 ---- file switches (ls-lisp-time-index switches) nil full-directory-p)) (signal (car err) (cdr err))))) (save-excursion (goto-char (point-min)) ! (while (re-search-forward "^total" nil t) ! (beginning-of-line) ! (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 (point-min)) ! (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 ! (save-excursion (beginning-of-line) (+ 2 (point))) ! (1- (match-beginning 1)) ! `(mouse-face highlight keymap ,map ! help-echo "Files shown / total files in directory \ ! \[RET, mouse-2: more info]")) ! (add-text-properties ! (match-beginning 1) ! (save-excursion (end-of-line) (point)) ! `(mouse-face highlight keymap ,map ! help-echo "Kbytes used in directory, Kbytes \ ! available on disk [RET, mouse-2: more info]"))))))))) (defun ls-lisp-insert-directory (file switches time-index wildcard-regexp full-directory-p) ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: patch for Dired second header line info 2008-03-04 19:44 ` Drew Adams 2008-03-04 22:28 ` Drew Adams @ 2008-03-05 21:33 ` Richard Stallman 1 sibling, 0 replies; 23+ messages in thread From: Richard Stallman @ 2008-03-05 21:33 UTC (permalink / raw) To: Drew Adams; +Cc: juri, monnier, emacs-devel > Each number should have its own tooltip which explains that number > and not the others. Sorry; I don't agree. The meanings of the numbers are related (similar), at least in pairs. Four separate tooltips would be more an annoyance than a help, because the similarities and differences can't be grasped without a silly back-and-forth: I am not convinced, but I won't argue about it. ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: patch for Dired second header line info 2008-03-02 17:49 ` Drew Adams 2008-03-02 17:57 ` Juri Linkov @ 2008-03-03 18:27 ` Richard Stallman 2008-03-03 19:01 ` Drew Adams 1 sibling, 1 reply; 23+ messages in thread From: Richard Stallman @ 2008-03-03 18:27 UTC (permalink / raw) To: Drew Adams; +Cc: juri, emacs-devel files 420/694 space used 19646 available 56456000 I think files shown 420 in dir 694 their size 19646 available 56456000 is cleaner, for the usual case where the buffer shows one directory (or a subset of it). Does the "files shown" get updated by all the Dired commands that alter which files are shown? If not, I think it is misleading. ^ permalink raw reply [flat|nested] 23+ messages in thread
* RE: patch for Dired second header line info 2008-03-03 18:27 ` Richard Stallman @ 2008-03-03 19:01 ` Drew Adams 0 siblings, 0 replies; 23+ messages in thread From: Drew Adams @ 2008-03-03 19:01 UTC (permalink / raw) To: rms; +Cc: juri, emacs-devel > files 420/694 space used 19646 available 56456000 > I think > files shown 420 in dir 694 their size 19646 available 56456000 > > is cleaner, for the usual case where the buffer shows one > directory (or a subset of it). Feel free to adjust it as you like. BTW, what you propose works not only for the usual case, but also for any included subdirs. Each subdir listing has its own such info line. > Does the "files shown" get updated by all the Dired commands > that alter which files are shown? If not, I think it is misleading. No, unfortunately. I use `dired-after-readin-hook' to trigger the update, because I don't know of a better way. But that hook is sometimes run without all the files being shown (for some reason). For example, if you use `+' to create a directory, the hook is run with only the new directory shown. However, in that case, the directory header is also now showing, so it is at least not updated incorrectly to 1 - it remains (incorrectly) what it was before the `+'. Anyone know of a better hook to use for this or a better way to trigger the update? Wrt it being misleading: If no better implementation is found, to have it update automatically in all cases (e.g. chmod, deletion, file copy,...), then the doc should say that it is updated only when the directory is read in. It should be enough to say that you can use `g' at any time to update the files figures. ^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: patch for Dired second header line info 2008-03-02 16:27 ` Drew Adams 2008-03-02 17:49 ` Drew Adams @ 2008-03-02 17:56 ` Juri Linkov 1 sibling, 0 replies; 23+ messages in thread From: Juri Linkov @ 2008-03-02 17:56 UTC (permalink / raw) To: Drew Adams; +Cc: emacs-devel > It's true that we already do that kind of thing in some modes (e.g. `grep'), > but I think it's bad practice in general and should not be expanded. And > this file/space info is not as important as the info we put in the `grep' > lighter. A temporary indication of something can sometimes be appropriate in > a lighter area, but we shouldn't turn lighters into essays or status lines. > > Would you also add the space used/available to the Dired lighter? And would > you list the used/available figures for every inserted subdir in the mode line? No, I would only add the number/size of marked files as a temporary indication. -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 23+ messages in thread
end of thread, other threads:[~2008-03-05 21:33 UTC | newest] Thread overview: 23+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2008-03-01 1:03 patch for Dired second header line info Drew Adams 2008-03-01 13:31 ` Richard Stallman 2008-03-01 16:31 ` Drew Adams 2008-03-01 23:09 ` Richard Stallman 2008-03-02 2:55 ` Juri Linkov 2008-03-02 8:05 ` Drew Adams 2008-03-02 14:36 ` Juri Linkov 2008-03-02 16:27 ` Drew Adams 2008-03-02 17:49 ` Drew Adams 2008-03-02 17:57 ` Juri Linkov 2008-03-02 18:56 ` Drew Adams 2008-03-02 19:06 ` Drew Adams 2008-03-03 0:47 ` Drew Adams 2008-03-03 18:27 ` Richard Stallman 2008-03-03 21:45 ` Stefan Monnier 2008-03-03 22:29 ` Drew Adams 2008-03-04 17:38 ` Richard Stallman 2008-03-04 19:44 ` Drew Adams 2008-03-04 22:28 ` Drew Adams 2008-03-05 21:33 ` Richard Stallman 2008-03-03 18:27 ` Richard Stallman 2008-03-03 19:01 ` Drew Adams 2008-03-02 17:56 ` Juri Linkov
Code repositories for project(s) associated with this external index https://git.savannah.gnu.org/cgit/emacs.git https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.