[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: dired-details[+].el
From: |
Stefan Monnier |
Subject: |
Re: dired-details[+].el |
Date: |
Wed, 16 May 2012 11:24:37 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux) |
>> I discovered dired-details and dired-details+ and found them useful.
>> Could they be added to emacs?
>> http://www.emacswiki.org/emacs/DiredDetails
> They were supposed to be added. Rob Giardina submitted an Emacs 23 patch two
> years ago that integrates the functionality of both in a better way even than
> the separate libraries dired-details[+].el.
Thanks.
> I don't think any reason was ever given for why the patch wasn't
> incorporated (committed).
A technical reason is lack of copyright paperwork. I'm not sure if the
email I used in the Cc is valid. If so, Rob, could you contact me to
get this copyright business out of the way?
> Rob's change log and RMS's call for comment:
> http://lists.gnu.org/archive/html/emacs-devel/2007-07/msg01187.html
This was mangled by the non-MIME forwarding, but I think I managed to
unmangle it (see after my sig). Some of the hunks don't apply any more,
but they're trivial to fix. There are a few minor details to make
before we can install the code:
> * dired.el: new functions to support hiding file details in dired.
Please capitalize all the phrases in your changelog.
> (dired-revert): delete cached overlay lists
And please punctuate them properly.
> (dired-details): new customize group
> New customizable vars.
> (dired-details-hidden-string)
> (dired-details-hide-link-targets)
> (dired-details-initially-hide)
> New buffer local vars.
There's some ":" missing somewhere.
> --- old/lisp/dired-x.el Sun Jul 15 21:25:37 2007
> +++ new/lisp/dired-x.el Sun Jul 15 22:00:23 2007
> @@ -755,7 +755,8 @@
> (set (make-local-variable 'dired-subdir-alist) nil)
> (dired-build-subdir-alist)
> (goto-char (point-min))
> - (dired-initial-position dirname))
> + (dired-initial-position dirname)
> + (run-hooks 'dired-after-readin-hook))
I'm not sure if this is appropriate. But I think it's OK to just try it
and fix it later if someone reports a problem.
> + (dired-details-delete-overlays) ;;ditch the entire overlay cache
Please capitalize and punctuate your comments.
> + (define-key map "(" 'dired-details-hide)
> + (define-key map ")" 'dired-details-show)
> + (define-key map ";" 'dired-details-toggle)
I'd rather place the bindings on a "dired-details" prefix.
> +(defcustom dired-details-hidden-string "[...]"
> + "*This string will be shown in place of file details and symbolic links."
> + :group 'dired-details
> + :type 'string)
No need for "*" in defcustoms.
> +(defcustom dired-details-hide-link-targets t
> + "*Hide symbolic link target paths."
> + :group 'dired-details
> + :type 'boolean)
FWIW I find something like (setq truncate-lines t) to be better.
Since line truncation is the default in tabulated-list-mode, maybe we
should also make it the default in dired.
> +(defvar dired-details-state nil
> + "Three possible values: nil (has not been set), 'hidden (details are
> +hidden), 'shown (details are visible).")
> +(make-variable-buffer-local 'dired-details-state)
The first line of a docstring should stand on its own.
> +(add-hook 'dired-after-readin-hook 'dired-details-activate)
Rather than unconditionally adding to dired-after-readin-hook, I think
we should add/remove from this hook when toggling.
> + (dolist (overlay (cdr dir-and-overlays))
> + (delete-overlay overlay)))
Aka (mapc #'delete-overlay (cdr dir-and-overlays)).
> +(defun dired-details-toggle (&optional arg default-too)
> + "Toggle visibility of dired details.
> +With positive prefix argument ARG hide the details, with negative
> +show them."
> + (interactive "P")
> + (let ((hide (if (null arg)
> + (not (eq 'hidden dired-details-state))
> + (> (prefix-numeric-value arg) 0))))
> + (if default-too
> + (setq dired-details-initially-hide hide))
> + (if hide (dired-details-hide)
> + (dired-details-show))))
Use define-minor-mode.
> +(defun dired-details-hide()
Add a space before open parentheses.
> + "Make an invisible, evaporable overlay for each visible file
> +details in this dired buffer. This is called from
Again, the first line of a docstring should stand on its own.
> + (unless (memq major-mode '(dired-mode vc-dired-mode))
Use derived-mode-p.
> + (error "dired-details-hide can only be called in dired mode"))
Actually, why bother signaling an error here?
> + (cached-overlays
> + (assoc dir dired-details-internal-overlay-cache)))
BTW, why do we bother with this business of caching overlays?
> +(defun dired-details-hide-overlay (o)
> + (overlay-put o 'invisible t)
> + (overlay-put o 'before-string dired-details-hidden-string))
Why use dired-details-hidden-string rather than just using the
traditional ellipsis with buffer-invisibility-spec?
Stefan
2007-07-15 Rob Giardina <address@hidden>
* dired.el: new functions to support hiding file details in dired.
(dired-revert): delete cached overlay lists
(dired-details): new customize group
New customizable vars.
(dired-details-hidden-string)
(dired-details-hide-link-targets)
(dired-details-initially-hide)
New buffer local vars.
(dired-details-internal-overlay-cache)
(dired-details-state)
New functions.
(dired-details-activate)
(dired-details-delete-overlays)
(dired-details-toggle)
(dired-details-hide)
(dired-details-show)
(dired-details-make-current-line-overlay)
(dired-details-hide-overlay)
(dired-details-show-overlay)
(dired-details-frob-overlays)
* dired-x.el (dired-virtual): run `dired-after-readin-hook' after
restoring a saved dired buffer
--- old/lisp/dired-x.el Sun Jul 15 21:25:37 2007
+++ new/lisp/dired-x.el Sun Jul 15 22:00:23 2007
@@ -755,7 +755,8 @@
(set (make-local-variable 'dired-subdir-alist) nil)
(dired-build-subdir-alist)
(goto-char (point-min))
- (dired-initial-position dirname))
+ (dired-initial-position dirname)
+ (run-hooks 'dired-after-readin-hook))
(defun dired-virtual-guess-dir ()
"Guess and return appropriate working directory of this buffer.
--- old/lisp/dired.el Sun Jul 15 15:42:33 2007
+++ new/lisp/dired.el Sun Jul 15 21:19:44 2007
@@ -1042,6 +1042,7 @@
(goto-char (point-min))
(setq mark-alist;; only after dired-remember-hidden since this unhides:
(dired-remember-marks (point-min) (point-max)))
+ (dired-details-delete-overlays) ;;ditch the entire overlay cache
;; treat top level dir extra (it may contain wildcards)
(dired-uncache
(if (consp dired-directory) (car dired-directory) dired-directory))
@@ -1242,6 +1243,9 @@
(define-key map "\C-n" 'dired-next-line)
(define-key map "\C-p" 'dired-previous-line)
(define-key map [down] 'dired-next-line)
+ (define-key map "(" 'dired-details-hide)
+ (define-key map ")" 'dired-details-show)
+ (define-key map ";" 'dired-details-toggle)
(define-key map [up] 'dired-previous-line)
;; hiding
(define-key map "$" 'dired-hide-subdir)
@@ -3334,6 +3338,171 @@
'(dired-mode . dired-restore-desktop-buffer))
+;;; optionally hide file details and link targets
+
+(defgroup dired-details nil
+ "Settings for to hide file details and symbolic link targets."
+ :group 'dired
+ :prefix "dired-details-")
+
+(defcustom dired-details-hidden-string "[...]"
+ "*This string will be shown in place of file details and symbolic links."
+ :group 'dired-details
+ :type 'string)
+
+(defcustom dired-details-hide-link-targets t
+ "*Hide symbolic link target paths."
+ :group 'dired-details
+ :type 'boolean)
+
+(defcustom dired-details-initially-hide nil
+ "*Hide dired details on entry to dired buffers."
+ :group 'dired-details
+ :type 'boolean)
+
+(defvar dired-details-internal-overlay-cache nil)
+(make-variable-buffer-local 'dired-details-internal-overlay-cache)
+
+(defvar dired-details-state nil
+ "Three possible values: nil (has not been set), 'hidden (details are
+hidden), 'shown (details are visible).")
+(make-variable-buffer-local 'dired-details-state)
+
+(defun dired-details-activate()
+ "Set up dired-details in the current dired buffer. Called by
+dired-after-readin-hook on initial display and when a dired
+buffer is modified. If the state of detail display has been set
+in this buffer then use that state, otherwise use the value of
+`dired-details-initially-hide'."
+ (if (eq 'hidden dired-details-state)
+ (dired-details-hide)
+ (when dired-details-initially-hide
+ (dired-details-hide))))
+(add-hook 'dired-after-readin-hook 'dired-details-activate)
+
+(defun dired-details-delete-overlays()
+ (dolist (dir-and-overlays dired-details-internal-overlay-cache)
+ (dolist (overlay (cdr dir-and-overlays))
+ (delete-overlay overlay)))
+ (setq dired-details-internal-overlay-cache nil))
+
+(defun dired-details-toggle (&optional arg default-too)
+ "Toggle visibility of dired details.
+With positive prefix argument ARG hide the details, with negative
+show them."
+ (interactive "P")
+ (let ((hide (if (null arg)
+ (not (eq 'hidden dired-details-state))
+ (> (prefix-numeric-value arg) 0))))
+ (if default-too
+ (setq dired-details-initially-hide hide))
+ (if hide (dired-details-hide)
+ (dired-details-show))))
+
+(defun dired-details-hide()
+ "Make an invisible, evaporable overlay for each visible file
+details in this dired buffer. This is called from
+dired-after-readin-hook in different contexts: (1) narrowed to a
+single file (after copy, move, symlink etc.) (2) narrowed to a
+single subdir (e.g. after dired-insert-subdir) (3) with multiple
+visible subdirs and not narrowed (e.g. after dired-revert)"
+ (interactive)
+ (unless (memq major-mode '(dired-mode vc-dired-mode))
+ (error "dired-details-hide can only be called in dired mode"))
+
+ (save-excursion
+ (goto-char (point-min))
+ (if (not (looking-at dired-subdir-regexp))
+ ;;a single file or files -- just make an overlay for each
+ (let* ((parent (dired-current-directory))
+ (cached-parent-overlays
+ (assoc parent dired-details-internal-overlay-cache)))
+ (unless cached-parent-overlays
+ (error "dired-details overlays not found for directory %s" parent))
+ (dired-goto-next-file)
+ (while (< (point) (point-max))
+ (dired-details-make-current-line-overlay cached-parent-overlays)
+ (dired-next-line 1)))
+
+ ;;hide each visible subdirectory (either of cases (2) or (3)
+ ;;mentioned above)
+ (dolist (dir-and-pos dired-subdir-alist)
+ (let* ((dir (car dir-and-pos))
+ (pos (cdr dir-and-pos))
+ (cached-overlays
+ (assoc dir dired-details-internal-overlay-cache)))
+ ;;skip this directory if it's outside of a narrowed region
+ (when (and (>= pos (point-min)) (<= pos (point-max)))
+ (if cached-overlays
+ (dired-details-frob-overlays t) ;;reuse existing
+ (let ((cache (list dir)) ;;make new overlays
+ (subdir-start (let ((rest pos))
+ ;;xemacs compat: in xemacs, this is a
list
+ (if (atom rest) rest (car rest))))
+ (subdir-end (1- (dired-get-subdir-max dir-and-pos))))
+ (goto-char subdir-start)
+ (dired-goto-next-file)
+ (while (< (point) subdir-end)
+ ;;nb: uses setcdr to update cache
+ (dired-details-make-current-line-overlay cache)
+ (dired-next-line 1))
+ (setq dired-details-internal-overlay-cache
+ (cons cache
dired-details-internal-overlay-cache)))))))
+ (setq dired-details-state 'hidden))))
+
+(defun dired-details-show()
+ "Show whatever details a call to `dired-details-hide' may have
+hidden in this buffer."
+ (interactive)
+ (dired-details-frob-overlays nil)
+ (setq dired-details-state 'shown))
+
+(defun dired-details-make-current-line-overlay (cache)
+ (let ((detail-overlay ;hide the flags, size, owner, date, etc.
+ (make-overlay
+ (+ 2 (progn (beginning-of-line) (point)))
+ (progn (dired-move-to-filename)(point))))
+
+ (ln-target ;hide the destination of a symbolic when
+ (when dired-details-hide-link-targets
+ (if (progn (beginning-of-line)
+ (search-forward-regexp
+ "-> \\(.*\\)"
+ (save-excursion (end-of-line)(point)) t))
+ (make-overlay (match-beginning 1) (match-end 1))))))
+
+ ;;delete the overlay when the dired line goes away
+ (overlay-put detail-overlay 'evaporate t)
+ (dired-details-hide-overlay detail-overlay)
+
+ (when ln-target
+ (overlay-put ln-target 'evaporate t)
+ (dired-details-hide-overlay ln-target))
+
+ (setcdr cache (append (if ln-target
+ (list ln-target detail-overlay)
+ (list detail-overlay))
+ (cdr cache)))
+ detail-overlay))
+
+(defun dired-details-hide-overlay (o)
+ (overlay-put o 'invisible t)
+ (overlay-put o 'before-string dired-details-hidden-string))
+
+(defun dired-details-show-overlay (o)
+ (overlay-put o 'invisible nil)
+ (overlay-put o 'before-string ""))
+
+(defun dired-details-frob-overlays (hide)
+ (when dired-details-internal-overlay-cache
+ (let ((frobber (if hide 'dired-details-hide-overlay
+ 'dired-details-show-overlay)))
+ (dolist (dir-and-overlays dired-details-internal-overlay-cache)
+ (dolist (overlay (cdr dir-and-overlays))
+ (funcall frobber overlay))))))
+
+
+
(if (eq system-type 'vax-vms)
(load "dired-vms"))
--- old/doc/emacs/dired.texi Sun Jul 15 18:00:22 2007
+++ new/doc/emacs/dired.texi Sun Jul 15 18:00:10 2007
@@ -41,6 +41,7 @@
@end ifnottex
* Subdirectory Motion:: Moving across subdirectories, and up and
down.
* Hiding Subdirectories:: Making subdirectories visible or invisible.
+ * Hiding File Details:: Making file attributes visible or invisible.
* Updating: Dired Updating. Discarding lines for files of no interest.
* Find: Dired and Find. Using `find' to choose the files for
Dired.
* Wdired:: Operating on files by editing the Dired buffer.
@@ -1011,6 +1012,45 @@
without having to remove the Dired marks on files in those
subdirectories.
address@hidden Hiding File Details
address@hidden Hiding File Details
+
address@hidden hiding in Dired (Dired)
+ @dfn{Hiding} file details means making file attributes and symbolic
+link targets invisible using overlays (@pxref{Overlays,,, elisp, the
+Emacs Lisp Reference Manual}). This converts the dired display to a
+terse list of filenames while continuing to support all normal dired
+commands.
+
address@hidden @kbd
address@hidden @kbd{;}
address@hidden dired-details-toggle
address@hidden @kbd{;} @r{(Dired)}
+Hide or reveal file details in the current Dired buffer.
+
address@hidden @kbd{(}
address@hidden dired-details-hide
address@hidden @kbd{(} @r{(Dired)}
+Hide file details in the current Dired buffer.
+
address@hidden @kbd{)}
address@hidden dired-details-hide
address@hidden @kbd{)} @r{(Dired)}
+Show file details in the current Dired buffer.
address@hidden table
+
+ You can customize @code{dired-details-hidden-string} to display any
+string in place of hidden details and link targets (the default is
+"[...]").
+
+ The option @code{dired-details-hide-link-targets} can be set to
address@hidden to show link targets when details are hidden. The default is to
+hide link targets.
+
+ Currently, the dired-sort-* family of functions do not call
address@hidden and thus will not hide details until
+the next call to @code{dired-revert} (@kbd{g}).
+
@node Dired Updating
@section Updating the Dired Buffer
@cindex updating Dired buffer
- Re: dired-details[+].el,
Stefan Monnier <=