all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* dired.el
@ 2004-06-06 19:26 Luc Teirlinck
  2004-06-06 19:40 ` dired.el Luc Teirlinck
  2004-06-07  7:10 ` dired.el Richard Stallman
  0 siblings, 2 replies; 10+ messages in thread
From: Luc Teirlinck @ 2004-06-06 19:26 UTC (permalink / raw)


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
    itself.
    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."
    (interactive)
    (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."
    (interactive)
    (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.
============================================================

^ permalink raw reply	[flat|nested] 10+ messages in thread
* dired.el
@ 2004-06-03  3:43 Luc Teirlinck
  2004-06-03  5:09 ` dired.el Luc Teirlinck
  0 siblings, 1 reply; 10+ messages in thread
From: Luc Teirlinck @ 2004-06-03  3:43 UTC (permalink / raw)


My previous patch to dired-aux.el turned out to still require several
changes, for instance to be able to handle the `-R' switch to `ls'.

My patches now require some changes to dired.el as well.  If they look
OK, I will install all four patches.

The variable `dired-subdir-switches' allows to get rid of two ugly
alternative functions and bindings for `dired-maybe-insert-subdir' in
locate.el and find-dired.el.  It allows to specify different default
switches for the main directory and for inserted subdirectories.  It
could potentially be used for user customization as well.  But I am
hesitating whether that is true to a sufficient degree to use
defcustom instead of defvar.  The patch below uses defvar, but, of
course, it would be trivial to change that.

`dired-switches-alist' already occurred in my previous dired-aux.el
patch.  I just had to move it to dired.el.

The change to `dired-insert-old-subdirs' corrects a bug when reverting
buffers containing a subdirectory inserted using the "-R" switch.
The previous version first correctly inserted all subdirectories using
`ls -R' and then went through a lot of work getting things (sometimes)
wrong, by systematically erasing every single subdirectory and
re-inserting it.  Subdirectories several levels down could get
inserted, deleted and re-inserted countless times.  My patch corrects
this.

In as far as the final change is concerned, it would make
`dired-build-subdir-alist' only print the "Buffer includes %d directories"
message when called interactively.  This is yet another auto-revert
noise control issue.  I believe the user is only interested in the
info if the function was called interactively.  If it was called for
internal reasons by some other command, then I believe that the message
is likely to confuse the user, regardless of the auto-revert issue.
It certainly is confusing when `dired-build-subdir-alist' is indirectly
called by auto-revert.

===File ~/dired-diff========================================
*** dired.el	30 May 2004 15:58:40 -0500	1.286
--- dired.el	02 Jun 2004 16:01:52 -0500	
***************
*** 60,65 ****
--- 60,69 ----
    :type 'string
    :group 'dired)
  
+ (defvar dired-subdir-switches nil
+   "If non-nil, switches passed to `ls' for inserting subdirectories.
+ If nil, `dired-listing-switches' is used.")
+ 
  ; Don't use absolute file names as /bin should be in any PATH and people
  ; may prefer /usr/local/gnu/bin or whatever.  However, chown is
  ; usually not in PATH.
***************
*** 274,286 ****
  (defvar dired-re-perms "[-bcdlps][-r][-w].[-r][-w].[-r][-w].")
  (defvar dired-re-dot "^.* \\.\\.?/?$")
  
! ;; The subdirectory names in this list are expanded.
  (defvar dired-subdir-alist nil
    "Association list of subdirectories and their buffer positions.
  Each subdirectory has an element: (DIRNAME . STARTMARKER).
  The order of elements is the reverse of the order in the buffer.
  In simple cases, this list contains one element.")
  
  (defvar dired-subdir-regexp "^. \\([^\n\r]+\\)\\(:\\)[\n\r]"
    "Regexp matching a maybe hidden subdirectory line in `ls -lR' output.
  Subexpression 1 is the subdirectory proper, no trailing colon.
--- 278,294 ----
  (defvar dired-re-perms "[-bcdlps][-r][-w].[-r][-w].[-r][-w].")
  (defvar dired-re-dot "^.* \\.\\.?/?$")
  
! ;; The subdirectory names in the next two lists are expanded.
  (defvar dired-subdir-alist nil
    "Association list of subdirectories and their buffer positions.
  Each subdirectory has an element: (DIRNAME . STARTMARKER).
  The order of elements is the reverse of the order in the buffer.
  In simple cases, this list contains one element.")
  
+ (defvar dired-switches-alist nil
+   "Keeps track of which switches to use for inserted subdirectories.
+ This is an alist of the form (SUBDIR . SWITCHES).")
+ 
  (defvar dired-subdir-regexp "^. \\([^\n\r]+\\)\\(:\\)[\n\r]"
    "Regexp matching a maybe hidden subdirectory line in `ls -lR' output.
  Subexpression 1 is the subdirectory proper, no trailing colon.
***************
*** 961,967 ****
  	  (condition-case ()
  	      (progn
  		(dired-uncache dir)
! 		(dired-insert-subdir dir))
  	    (error nil))))))
  
  (defun dired-uncache (dir)
--- 969,982 ----
  	  (condition-case ()
  	      (progn
  		(dired-uncache dir)
! 		(dired-insert-subdir dir)
! 		(let ((switches (cdr (assoc-string dir dired-switches-alist))))
! 		  (and switches
! 		       (string-match "R" switches)
! 		       (dolist (cur-ass (copy-sequence old-subdir-alist))
! 			 (when (string-match (concat "\\`" dir) (car cur-ass))
! 			   (setq old-subdir-alist
! 				 (delete cur-ass old-subdir-alist)))))))
  	    (error nil))))))
  
  (defun dired-uncache (dir)
***************
*** 1406,1411 ****
--- 1421,1427 ----
         '(dired-font-lock-keywords t nil nil beginning-of-line))
    (set (make-local-variable 'desktop-save-buffer)
         'dired-desktop-buffer-misc-data)
+   (set (make-local-variable 'dired-switches-alist) nil)
    (dired-sort-other dired-actual-switches t)
    (run-mode-hooks 'dired-mode-hook)
    (when (featurep 'x-dnd)
***************
*** 2073,2079 ****
  			     (goto-char (match-beginning 0))
  			     (beginning-of-line)
  			     (point-marker))))
!       (if (> count 1)
  	  (message "Buffer includes %d directories" count))
        ;; We don't need to sort it because it is in buffer order per
        ;; constructionem.  Return new alist:
--- 2089,2095 ----
  			     (goto-char (match-beginning 0))
  			     (beginning-of-line)
  			     (point-marker))))
!       (if (and (> count 1) (interactive-p))
  	  (message "Buffer includes %d directories" count))
        ;; We don't need to sort it because it is in buffer order per
        ;; constructionem.  Return new alist:
============================================================

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

end of thread, other threads:[~2004-06-09 14:27 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-06-06 19:26 dired.el Luc Teirlinck
2004-06-06 19:40 ` dired.el Luc Teirlinck
2004-06-06 20:19   ` dired.el David Kastrup
2004-06-07  9:04   ` dired.el Stefan Monnier
2004-06-07 16:34     ` dired.el Luc Teirlinck
2004-06-09  9:59       ` dired.el Stefan Monnier
2004-06-09 14:27         ` dired.el Luc Teirlinck
2004-06-07  7:10 ` dired.el Richard Stallman
  -- strict thread matches above, loose matches on Subject: below --
2004-06-03  3:43 dired.el Luc Teirlinck
2004-06-03  5:09 ` dired.el Luc Teirlinck

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.