unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* dired-kill-tree
@ 2004-06-06 21:19 Luc Teirlinck
  2004-06-06 21:27 ` dired-kill-tree Miles Bader
  2004-06-07  7:11 ` dired-kill-tree Richard Stallman
  0 siblings, 2 replies; 7+ messages in thread
From: Luc Teirlinck @ 2004-06-06 21:19 UTC (permalink / raw)


The docstring of `dired-kill-tree' says:

"Kill all proper subdirs of DIRNAME, excluding DIRNAME itself.

But you have to understand that this assumes that DIRNAME is a
directory name and not a directory file name.  Otherwise, DIRNAME _is_
killed.  Anybody having taken any look at the Dired Elisp code will
probably have no trouble guessing this implicit assumption.

But `dired-kill-tree' can be used interactively and the implicit
assumption may not be obvious to most interactive users.  Actually, I
myself find it more often useful _in interactive usage_ to
_deliberately_ pass a directory file name to kill the entire tree
including DIRNAME.  This saves me a step, because I nearly invariably
_want_ to kill DIRNAME itself.

So what about turning this bug officially into a feature, with the
following change in the docstring:

===File ~/dired-aux-diff====================================
*** dired-aux.el	05 Jun 2004 21:07:07 -0500	1.119
--- dired-aux.el	06 Jun 2004 15:52:23 -0500	
***************
*** 1834,1839 ****
--- 1834,1844 ----
  
  (defun dired-kill-tree (dirname &optional remember-marks)
    "Kill all proper subdirs of DIRNAME, excluding DIRNAME itself.
+ Note that DIRNAME itself is _only_ excluded if it is a directory name,
+ which on most systems means that it ends with a slash.  If DIRNAME is
+ a directory file name, which on most systems means that it does not end
+ with a slash, then DIRNAME is killed too.  The latter is sometimes useful
+ in interactive usage, when DIRNAME is itself a subdirectory.
  With optional arg REMEMBER-MARKS, return an alist of marked files."
    (interactive "DKill tree below directory: ")
    (setq dirname (expand-file-name dirname))
============================================================

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: dired-kill-tree
  2004-06-06 21:19 dired-kill-tree Luc Teirlinck
@ 2004-06-06 21:27 ` Miles Bader
  2004-06-06 21:42   ` dired-kill-tree Luc Teirlinck
  2004-06-07  1:08   ` dired-kill-tree Luc Teirlinck
  2004-06-07  7:11 ` dired-kill-tree Richard Stallman
  1 sibling, 2 replies; 7+ messages in thread
From: Miles Bader @ 2004-06-06 21:27 UTC (permalink / raw)
  Cc: emacs-devel

On Sun, Jun 06, 2004 at 04:19:03PM -0500, Luc Teirlinck wrote:
> But you have to understand that this assumes that DIRNAME is a
> directory name and not a directory file name.  Otherwise, DIRNAME _is_
> killed.  Anybody having taken any look at the Dired Elisp code will
> probably have no trouble guessing this implicit assumption.

Is there a (reasonable) reason for this rather odd behavior?

-miles
-- 
`...the Soviet Union was sliding in to an economic collapse so comprehensive
 that in the end its factories produced not goods but bads: finished products
 less valuable than the raw materials they were made from.'  [The Economist]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: dired-kill-tree
  2004-06-06 21:27 ` dired-kill-tree Miles Bader
@ 2004-06-06 21:42   ` Luc Teirlinck
  2004-06-07  1:08   ` dired-kill-tree Luc Teirlinck
  1 sibling, 0 replies; 7+ messages in thread
From: Luc Teirlinck @ 2004-06-06 21:42 UTC (permalink / raw)
  Cc: emacs-devel

Miles Bader wrote:

   On Sun, Jun 06, 2004 at 04:19:03PM -0500, Luc Teirlinck wrote:
   > But you have to understand that this assumes that DIRNAME is a
   > directory name and not a directory file name.  Otherwise, DIRNAME _is_
   > killed.  Anybody having taken any look at the Dired Elisp code will
   > probably have no trouble guessing this implicit assumption.

   Is there a (reasonable) reason for this rather odd behavior?

Tecnically because:

  (setq dirname (expand-file-name dirname))

and later:

      (if (and (not (string-equal dir dirname))

(then we do _not_ delete DIR).

DIR is a directory name.  If DIRNAME is not, then DIR and DIRNAME are
not string-equal.

This bug can trivially be fixed by changing:

  (setq dirname (expand-file-name dirname))

into:

  (setq dirname (file-name-as-directory (expand-file-name dirname)))

That would be an obvious alternative patch.  (Leaving the docstring
unchanged.)  Somehow, the buggy behavior turns out (at least in my
usage) to be useful interactively.

Sincerely,

Luc.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: dired-kill-tree
  2004-06-06 21:27 ` dired-kill-tree Miles Bader
  2004-06-06 21:42   ` dired-kill-tree Luc Teirlinck
@ 2004-06-07  1:08   ` Luc Teirlinck
  1 sibling, 0 replies; 7+ messages in thread
From: Luc Teirlinck @ 2004-06-07  1:08 UTC (permalink / raw)
  Cc: emacs-devel

Actually, there is a third (much more general) way to view the anomaly.

The first way to deal with the problem was to quite simply make the
behavior into a feature by documenting it into the docstring.

The second is to change:

  (setq dirname (expand-file-name dirname))

into:

  (setq dirname (file-name-as-directory (expand-file-name dirname)))

thereby getting rid of the feature.

The third way is that maybe the behavior of the "D" interactive code,
usd by `dired-kill-tree' is anomalous:

>From (elisp)Interactive Codes:

`D'
     A directory name.  The default is the current default directory
     of
     the current buffer, `default-directory' (*note File Name
     Expansion::).  Existing, Completion, Default, Prompt.

If I have a directory ~/subdir, and no other subdirectory of ~/
starting with ~/subd, then if I enter ~/subd RET, then depending on my
customizations, Emacs will, in various ways, tell me that the only
possible completion is ~/subdir/.  But if I type ~/subdir, it will
accept that as is.  That is, contrary to its documentation, the `D'
interactive code does not only accept existing directory names, but
also existing directory file names.  The two are _only_ equivalent if
the function using `D' makes them equivalent.  The completions listed
after say, ~/subd RET, do not interact very well with the first way to
deal with the problem, because they only include ~/subdir/, not
~/subdir.

Sincerely,

Luc.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: dired-kill-tree
  2004-06-06 21:19 dired-kill-tree Luc Teirlinck
  2004-06-06 21:27 ` dired-kill-tree Miles Bader
@ 2004-06-07  7:11 ` Richard Stallman
  2004-06-08  2:39   ` dired-kill-tree Luc Teirlinck
  1 sibling, 1 reply; 7+ messages in thread
From: Richard Stallman @ 2004-06-07  7:11 UTC (permalink / raw)
  Cc: emacs-devel

      (defun dired-kill-tree (dirname &optional remember-marks)
	"Kill all proper subdirs of DIRNAME, excluding DIRNAME itself.
    + Note that DIRNAME itself is _only_ excluded if it is a directory name,
    + which on most systems means that it ends with a slash.  If DIRNAME is
    + a directory file name, which on most systems means that it does not end
    + with a slash, then DIRNAME is killed too.  The latter is sometimes useful
    + in interactive usage, when DIRNAME is itself a subdirectory.
      With optional arg REMEMBER-MARKS, return an alist of marked files."

I think this behavior is rather error-prone and counterintuitive.
I would rather consider it a bug, and change it to exclude
DIRNAME even if it is specified in the syntactic form of a file name.

If this makes it hard to kill a subdir, we could add a new interface
for doing that, or we could make this command ask whether
to kill directory DIRNAME as well.  That would provide an accident-proof
way to ask for either behavior.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: dired-kill-tree
  2004-06-07  7:11 ` dired-kill-tree Richard Stallman
@ 2004-06-08  2:39   ` Luc Teirlinck
  2004-06-08 23:31     ` dired-kill-tree Richard Stallman
  0 siblings, 1 reply; 7+ messages in thread
From: Luc Teirlinck @ 2004-06-08  2:39 UTC (permalink / raw)
  Cc: emacs-devel

Richard Stallman wrote:

   I think this behavior is rather error-prone and counterintuitive.
   I would rather consider it a bug, and change it to exclude
   DIRNAME even if it is specified in the syntactic form of a file name.

   If this makes it hard to kill a subdir, we could add a new interface
   for doing that, or we could make this command ask whether
   to kill directory DIRNAME as well.  That would provide an accident-proof
   way to ask for either behavior.

What about the following patch, which kills DIRNAME as well if a
prefix argument is given?

===File ~/dired-aux-diff====================================
*** dired-aux.el	07 Jun 2004 15:59:16 -0500	1.120
--- dired-aux.el	07 Jun 2004 21:04:22 -0500	
***************
*** 1852,1870 ****
  			  (> (dired-get-subdir-min elt1)
  			     (dired-get-subdir-min elt2)))))))
  
! (defun dired-kill-tree (dirname &optional remember-marks)
    "Kill all proper subdirs of DIRNAME, excluding DIRNAME itself.
! With optional arg REMEMBER-MARKS, return an alist of marked files."
!   (interactive "DKill tree below directory: ")
!   (setq dirname (expand-file-name dirname))
    (let ((s-alist dired-subdir-alist) dir m-alist)
      (while s-alist
        (setq dir (car (car s-alist))
  	    s-alist (cdr s-alist))
!       (if (and (not (string-equal dir dirname))
! 	       (dired-in-this-tree dir dirname)
! 	       (dired-goto-subdir dir))
! 	  (setq m-alist (nconc (dired-kill-subdir remember-marks) m-alist))))
      m-alist))
  
  (defun dired-insert-subdir-newpos (new-dir)
--- 1852,1874 ----
  			  (> (dired-get-subdir-min elt1)
  			     (dired-get-subdir-min elt2)))))))
  
! (defun dired-kill-tree (dirname &optional remember-marks kill-root)
    "Kill all proper subdirs of DIRNAME, excluding DIRNAME itself.
! Interactively, you can kill DIRNAME as well by using a prefix argument.
! In interactive use, the command prompts for DIRNAME.
! 
! When called from Lisp, if REMEMBER-MARKS is non-nil, return an alist
! of marked files.  If KILL-ROOT is non-nil, kill DIRNAME as well."
!   (interactive "DKill tree below directory: \ni\nP")
!   (setq dirname (file-name-as-directory (expand-file-name dirname)))
    (let ((s-alist dired-subdir-alist) dir m-alist)
      (while s-alist
        (setq dir (car (car s-alist))
  	    s-alist (cdr s-alist))
!       (and (or kill-root (not (string-equal dir dirname)))
! 	   (dired-in-this-tree dir dirname)
! 	   (dired-goto-subdir dir)
! 	   (setq m-alist (nconc (dired-kill-subdir remember-marks) m-alist))))
      m-alist))
  
  (defun dired-insert-subdir-newpos (new-dir)
============================================================

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: dired-kill-tree
  2004-06-08  2:39   ` dired-kill-tree Luc Teirlinck
@ 2004-06-08 23:31     ` Richard Stallman
  0 siblings, 0 replies; 7+ messages in thread
From: Richard Stallman @ 2004-06-08 23:31 UTC (permalink / raw)
  Cc: emacs-devel

    What about the following patch, which kills DIRNAME as well if a
    prefix argument is given?

That might be a good interface.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2004-06-08 23:31 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-06-06 21:19 dired-kill-tree Luc Teirlinck
2004-06-06 21:27 ` dired-kill-tree Miles Bader
2004-06-06 21:42   ` dired-kill-tree Luc Teirlinck
2004-06-07  1:08   ` dired-kill-tree Luc Teirlinck
2004-06-07  7:11 ` dired-kill-tree Richard Stallman
2004-06-08  2:39   ` dired-kill-tree Luc Teirlinck
2004-06-08 23:31     ` dired-kill-tree Richard Stallman

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).