[Top][All Lists]

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


From: Luc Teirlinck
Subject: dired.el
Date: Sun, 6 Jun 2004 14:26:48 -0500 (CDT)

While fixing bugs in Dired, locate and find-dired, I noticed the
following two problems, which were both present before my changes.
The small patch below corrects both.  I will install if it seems OK. 

Make a directory. say ~/subdir, say using + in Dired and then
make files ~/testfile and ~/subdir/testfile.  (It is very common to
have files with the same name in different directories.)

Visit ~/ using Dired.  Then insert ~/subdir using `i'.  "Accidentally"
kill it using C-u k on the subdirectory header line.  Reinsert it using
`C-_'.  First (minor) problem: occasionally the mode line marks the
Dired buffer as writable for some period before correcting it.  The
Dired buffer is not really writable during that period, the modeline
was just updated at the wrong time.  Now the real problem.  Delete
the "testfile" entry in the inserted subdir.  Now ~/testfile and not
~/subdir/testfile is deleted.  All kind of other serious damage can
occur in the given situation, the above is just an example.

It can be argued that this is not a bug.  It is mentioned in the
docstring of `dired-undo':

    Undo in a dired buffer.
    This doesn't recover lost files, it just undoes changes in the buffer
    You can use it to recover marks, killed lines or subdirs.
    In the latter case, you have to do M-x dired-build-subdir-alist to
    parse the buffer again.

But not everybody reads the docstring of every single command before
using it.  `dired-undo' is documented in the Emacs manual and _there_
`dired-build-subdir-alist' does not seem to be mentioned at all.
Given the danger involved in failing to call
`dired-build-subdir-alist' in the given situation, why not simply make
`dired-undo' call `dired-build-subdir-alist'?  The patch below does this.

As an added bonus, it also corrects the modeline problem.  (To be
honest, I do not fully understand why, but it does.  The patch changes
the scope of the buffer-read-only binding.  Does message update modelines?)

===File ~/dired-diff========================================
*** dired.el    05 Jun 2004 19:54:59 -0500      1.287
--- dired.el    06 Jun 2004 12:20:04 -0500      
*** 1453,1461 ****
  parse the buffer again."
    (let (buffer-read-only)
!     (undo)
!     (message "Change in Dired buffer undone.
! Actual changes in files cannot be undone by Emacs.")))
  (defun dired-next-line (arg)
    "Move down lines then position at filename.
--- 1453,1462 ----
  parse the buffer again."
    (let (buffer-read-only)
!     (undo))
!   (dired-build-subdir-alist)
!   (message "Change in Dired buffer undone.
! Actual changes in files cannot be undone by Emacs."))
  (defun dired-next-line (arg)
    "Move down lines then position at filename.

reply via email to

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