[gnu.emacs] Dired mode and the unix -F switch

fpb@sunpitt.east.sun.com (Frank P. Bresz) (01/08/90)

Hi,
	Here is a patch to dired.el which will allow dired.el to correctly
handle the -F switch on unix systems.  

	The patch includes some changes by Mark D. Baushke
<mdb@kosciusko.ESD.3Com.COM> to allow nice copying and renaming of files
from dired into another directory under the same name. It works just like
you'd expect.  i.e. if you copy a file to somewhere that happens to be a
directory it places the file inside the directory (this is exactly what
unix does)

	It also contains code changes to dired-do-deletions which allows
deletions to be done without asking.  If you use this patch and instead of
just hitting 'x' to perform deletions in dired-mode use ^U-x and it will
delete all of the files marked without asking (it of course may not delete
them all if there are protection failures or the like).

	Any comments back to:

InterNet :	wpmstr!fbresz@sunpitt.east.sun.com
Voice :		(412)733-6749
Fax :		(412)733-6444
Snail :		Westinghouse Electric Corp
		ITTC Mail Stop 7
		1740 Golden Mile Highway
		Monroeille, PA 15146


emjoy.

					Frank P. Bresz }*{
Here is the patch ...

*** dired.el	Mon Jan  8 09:48:11 1990
--- dist-18.52/dired.el	Mon Aug  8 08:14:09 1988
***************
*** 21,36 ****
  ;; can know your rights and responsibilities.  It should be in a
  ;; file named COPYING.  Among other things, the copyright notice
  ;; and this notice must be preserved on all copies.
- ;;
- ;;-----------------------------------------------------------------------
- ;; Mon Jan 8, 1990 
- ;; Kludged (dired-get-filename) wpmstr!fbresz@sunpitt.east.sun.com
- ;; This is to allow 'F' as a valid switch in the 
- ;; dired-listing-switches variable 
- ;; Should probably change the doc string for dired-listing-switches variable 
- ;; but since it is inside loaddefs.el it will have to wait until a release from
- ;; FSF.
  
  ;In loaddefs.el
  ;(defvar dired-listing-switches "-al"
  ;  "Switches passed to ls for dired. MUST contain the 'l' option.
--- 21,28 ----
  ;; can know your rights and responsibilities.  It should be in a
  ;; file named COPYING.  Among other things, the copyright notice
  ;; and this notice must be preserved on all copies.
  
+ 
  ;In loaddefs.el
  ;(defvar dired-listing-switches "-al"
  ;  "Switches passed to ls for dired. MUST contain the 'l' option.
***************
*** 279,308 ****
  Value returned normally includes the directory name.
  A non-nil 1st argument means do not include it.  A non-nil 2nd argument
  says return nil if no filename on this line, otherwise an error occurs."
!   (let (eol fname)
!     (setq fname 
! 	  (save-excursion
! 	    (end-of-line)
! 	    (setq eol (point))
! 	    (beginning-of-line)
! 	    (if (re-search-forward
! 		 "\\(Jan\\|Feb\\|Mar\\|Apr\\|May\\|Jun\\|Jul\\|Aug\\|Sep\\|Oct\\|Nov\\|Dec\\)[ ]+[0-9]+"
! 		 eol t)
! 		(progn (skip-chars-forward " ")
! 		       (skip-chars-forward "^ " eol)
! 		       (skip-chars-forward " " eol)
! 		       (let ((beg (point)))
! 			 (skip-chars-forward "^ \n")
! 			 (if localp
! 			     (buffer-substring beg (point))
! 			   ;; >> uses default-directory, could lose on cd, multiple.
! 			   (concat default-directory (buffer-substring beg (point))))))
! 	      (if no-error-if-not-filep nil
! 		(error "No file on this line")))))
!     (if (file-exists-p fname)
! 	fname
!       (if (file-exists-p (substring fname 0 -1))
! 	  (substring fname 0 -1)))))
  
  (defun dired-move-to-filename ()
    "In dired, move to first char of filename on this line.
--- 271,295 ----
  Value returned normally includes the directory name.
  A non-nil 1st argument means do not include it.  A non-nil 2nd argument
  says return nil if no filename on this line, otherwise an error occurs."
!   (let (eol)
!     (save-excursion
!       (end-of-line)
!       (setq eol (point))
!       (beginning-of-line)
!       (if (re-search-forward
! 	   "\\(Jan\\|Feb\\|Mar\\|Apr\\|May\\|Jun\\|Jul\\|Aug\\|Sep\\|Oct\\|Nov\\|Dec\\)[ ]+[0-9]+"
! 	   eol t)
! 	  (progn (skip-chars-forward " ")
! 		 (skip-chars-forward "^ " eol)
! 		 (skip-chars-forward " " eol)
! 		 (let ((beg (point)))
! 		   (skip-chars-forward "^ \n")
! 		   (if localp
! 		       (buffer-substring beg (point))
! 		     ;; >> uses default-directory, could lose on cd, multiple.
! 		     (concat default-directory (buffer-substring beg (point))))))
! 	(if no-error-if-not-filep nil
! 	  (error "No file on this line"))))))
  
  (defun dired-move-to-filename ()
    "In dired, move to first char of filename on this line.
***************
*** 445,458 ****
  
  (defun dired-rename-file (to-file)
    "Rename this file to TO-FILE."
!   (interactive "FRename to: ")
    (setq to-file (expand-file-name to-file))
!   (and (file-directory-p to-file)
!        (setq to-file
! 	     (concat (file-name-as-directory to-file)
! 		     (file-name-nondirectory
! 		      (dired-get-filename)))))
!   (rename-file (dired-get-filename) to-file 0)
    (let ((buffer-read-only nil))
      (beginning-of-line)
      (delete-region (point) (progn (forward-line 1) (point)))
--- 432,443 ----
  
  (defun dired-rename-file (to-file)
    "Rename this file to TO-FILE."
!   (interactive
!    (list (read-file-name (format "Rename %s to: "
! 				 (file-name-nondirectory (dired-get-filename)))
! 			 nil (dired-get-filename))))
    (setq to-file (expand-file-name to-file))
!   (rename-file (dired-get-filename) to-file)
    (let ((buffer-read-only nil))
      (beginning-of-line)
      (delete-region (point) (progn (forward-line 1) (point)))
***************
*** 463,475 ****
  (defun dired-copy-file (to-file)
    "Copy this file to TO-FILE."
    (interactive "FCopy to: ")
    (setq to-file (expand-file-name to-file))
-   (and (file-directory-p to-file)
-        (setq to-file
- 	     (concat (file-name-as-directory to-file)
- 		     (file-name-nondirectory
- 		      (dired-get-filename)))))
-   (copy-file (dired-get-filename) to-file 0)
    (dired-add-entry (file-name-directory to-file)
  		   (file-name-nondirectory to-file)))
  
--- 448,455 ----
  (defun dired-copy-file (to-file)
    "Copy this file to TO-FILE."
    (interactive "FCopy to: ")
+   (copy-file (dired-get-filename) to-file)
    (setq to-file (expand-file-name to-file))
    (dired-add-entry (file-name-directory to-file)
  		   (file-name-nondirectory to-file)))
  
***************
*** 562,570 ****
  			    (file-name-nondirectory file)))
    (dired-move-to-filename))
  
! (defun dired-do-deletions (arg)
    "In dired, delete the files flagged for deletion."
!   (interactive "P")
    (let (delete-list answer)
      (save-excursion
       (goto-char 1)
--- 542,550 ----
  			    (file-name-nondirectory file)))
    (dired-move-to-filename))
  
! (defun dired-do-deletions ()
    "In dired, delete the files flagged for deletion."
!   (interactive)
    (let (delete-list answer)
      (save-excursion
       (goto-char 1)
***************
*** 588,594 ****
  	   (insert (car (car l)))
  	   (setq l (cdr l))))
         (goto-char (point-min))
!        (setq answer (or arg (yes-or-no-p "Delete these files? "))))
        (if answer
  	  (let ((l delete-list)
  		failures)
--- 568,574 ----
  	   (insert (car (car l)))
  	   (setq l (cdr l))))
         (goto-char (point-min))
!        (setq answer (yes-or-no-p "Delete these files? ")))
        (if answer
  	  (let ((l delete-list)
  		failures)

rongchen@nunki.usc.edu (Rong Chen) (01/23/90)

Hi, 
I am new here in this group and maybe this is a silly question:

How does one put a patch program into work once he got one? 

USC is running Sun 3/80s if this information is essensial for someone
out there who would be kind enough to answer my question.

My e-mail address is  rongchen@nunki.usc.edu.

Thanks a lot,

						Rong Chen
						rongchen@nunki.usc.edu

fpb@sunpitt.east.sun.com (Frank P. Bresz) (01/24/90)

Hi All,

	Here is a new patch for dired.el.  I found a bug in the old version
inside the function dired-get-filename (the one I changed of course).  If
anyone wants a patch from just the last version I sent out, send me email.

	Here is a patch to dired.el which will allow dired.el to correctly
handle the -F switch on unix systems.  

	The patch includes some changes by Mark D. Baushke
<mdb@kosciusko.ESD.3Com.COM> to allow nice copying and renaming of files
from dired into another directory under the same name. It works just like
you'd expect.  i.e. if you copy a file to somewhere that happens to be a
directory it places the file inside the directory (this is exactly what
unix does)

	It also contains code changes to dired-do-deletions which allows
deletions to be done without asking.  If you use this patch ^U-x instead of
just hitting 'x' to perform deletions in dired-mode use will delete all of
the files marked without asking (it of course may not delete them all if
there are protection failures or the like). 

	Any comments back to:

InterNet :	wpmstr!fbresz@sunpitt.east.sun.com
Voice :		(412)733-6749
Fax :		(412)733-6444
Snail :		Westinghouse Electric Corp
		ITTC Mail Stop 7
		1740 Golden Mile Highway
		Monroeille, PA 15146


enjoy.

					Frank P. Bresz }*{
Here is the patch ...


*** dired.el	Wed Jan 17 11:32:55 1990
--- dist-18.52/dired.el	Mon Aug  8 08:14:09 1988
***************
*** 21,36 ****
  ;; can know your rights and responsibilities.  It should be in a
  ;; file named COPYING.  Among other things, the copyright notice
  ;; and this notice must be preserved on all copies.
- ;;
- ;;-----------------------------------------------------------------------
- ;; Mon Jan 8, 1990 
- ;; Kludged (dired-get-filename) wpmstr!fbresz@sunpitt.east.sun.com
- ;; This is to allow 'F' as a valid switch in the 
- ;; dired-listing-switches variable 
- ;; Should probably change the doc string for dired-listing-switches variable 
- ;; but since it is inside loaddefs.el it will have to wait until a release from
- ;; FSF.
  
  ;In loaddefs.el
  ;(defvar dired-listing-switches "-al"
  ;  "Switches passed to ls for dired. MUST contain the 'l' option.
--- 21,28 ----
  ;; can know your rights and responsibilities.  It should be in a
  ;; file named COPYING.  Among other things, the copyright notice
  ;; and this notice must be preserved on all copies.
  
+ 
  ;In loaddefs.el
  ;(defvar dired-listing-switches "-al"
  ;  "Switches passed to ls for dired. MUST contain the 'l' option.
***************
*** 279,309 ****
  Value returned normally includes the directory name.
  A non-nil 1st argument means do not include it.  A non-nil 2nd argument
  says return nil if no filename on this line, otherwise an error occurs."
!   (let (eol fname)
!     (setq fname 
! 	  (save-excursion
! 	    (end-of-line)
! 	    (setq eol (point))
! 	    (beginning-of-line)
! 	    (if (re-search-forward
! 		 "\\(Jan\\|Feb\\|Mar\\|Apr\\|May\\|Jun\\|Jul\\|Aug\\|Sep\\|Oct\\|Nov\\|Dec\\)[ ]+[0-9]+"
! 		 eol t)
! 		(progn (skip-chars-forward " ")
! 		       (skip-chars-forward "^ " eol)
! 		       (skip-chars-forward " " eol)
! 		       (let ((beg (point)))
! 			 (skip-chars-forward "^ \n")
! 			 (if localp
! 			     (buffer-substring beg (point))
! 			   ;; >> uses default-directory, could lose on cd, multiple.
! 			   (concat default-directory (buffer-substring beg (point))))))
! 	      (if no-error-if-not-filep nil
! 		(error "No file on this line")))))
!     (if fname
! 	(if (file-exists-p fname)
! 	    fname
! 	  (if (file-exists-p (substring fname 0 -1))
! 	      (substring fname 0 -1))))))
  
  (defun dired-move-to-filename ()
    "In dired, move to first char of filename on this line.
--- 271,295 ----
  Value returned normally includes the directory name.
  A non-nil 1st argument means do not include it.  A non-nil 2nd argument
  says return nil if no filename on this line, otherwise an error occurs."
!   (let (eol)
!     (save-excursion
!       (end-of-line)
!       (setq eol (point))
!       (beginning-of-line)
!       (if (re-search-forward
! 	   "\\(Jan\\|Feb\\|Mar\\|Apr\\|May\\|Jun\\|Jul\\|Aug\\|Sep\\|Oct\\|Nov\\|Dec\\)[ ]+[0-9]+"
! 	   eol t)
! 	  (progn (skip-chars-forward " ")
! 		 (skip-chars-forward "^ " eol)
! 		 (skip-chars-forward " " eol)
! 		 (let ((beg (point)))
! 		   (skip-chars-forward "^ \n")
! 		   (if localp
! 		       (buffer-substring beg (point))
! 		     ;; >> uses default-directory, could lose on cd, multiple.
! 		     (concat default-directory (buffer-substring beg (point))))))
! 	(if no-error-if-not-filep nil
! 	  (error "No file on this line"))))))
  
  (defun dired-move-to-filename ()
    "In dired, move to first char of filename on this line.
***************
*** 446,459 ****
  
  (defun dired-rename-file (to-file)
    "Rename this file to TO-FILE."
!   (interactive "FRename to: ")
    (setq to-file (expand-file-name to-file))
!   (and (file-directory-p to-file)
!        (setq to-file
! 	     (concat (file-name-as-directory to-file)
! 		     (file-name-nondirectory
! 		      (dired-get-filename)))))
!   (rename-file (dired-get-filename) to-file 0)
    (let ((buffer-read-only nil))
      (beginning-of-line)
      (delete-region (point) (progn (forward-line 1) (point)))
--- 432,443 ----
  
  (defun dired-rename-file (to-file)
    "Rename this file to TO-FILE."
!   (interactive
!    (list (read-file-name (format "Rename %s to: "
! 				 (file-name-nondirectory (dired-get-filename)))
! 			 nil (dired-get-filename))))
    (setq to-file (expand-file-name to-file))
!   (rename-file (dired-get-filename) to-file)
    (let ((buffer-read-only nil))
      (beginning-of-line)
      (delete-region (point) (progn (forward-line 1) (point)))
***************
*** 464,476 ****
  (defun dired-copy-file (to-file)
    "Copy this file to TO-FILE."
    (interactive "FCopy to: ")
    (setq to-file (expand-file-name to-file))
-   (and (file-directory-p to-file)
-        (setq to-file
- 	     (concat (file-name-as-directory to-file)
- 		     (file-name-nondirectory
- 		      (dired-get-filename)))))
-   (copy-file (dired-get-filename) to-file 0)
    (dired-add-entry (file-name-directory to-file)
  		   (file-name-nondirectory to-file)))
  
--- 448,455 ----
  (defun dired-copy-file (to-file)
    "Copy this file to TO-FILE."
    (interactive "FCopy to: ")
+   (copy-file (dired-get-filename) to-file)
    (setq to-file (expand-file-name to-file))
    (dired-add-entry (file-name-directory to-file)
  		   (file-name-nondirectory to-file)))
  
***************
*** 563,571 ****
  			    (file-name-nondirectory file)))
    (dired-move-to-filename))
  
! (defun dired-do-deletions (arg)
    "In dired, delete the files flagged for deletion."
!   (interactive "P")
    (let (delete-list answer)
      (save-excursion
       (goto-char 1)
--- 542,550 ----
  			    (file-name-nondirectory file)))
    (dired-move-to-filename))
  
! (defun dired-do-deletions ()
    "In dired, delete the files flagged for deletion."
!   (interactive)
    (let (delete-list answer)
      (save-excursion
       (goto-char 1)
***************
*** 589,595 ****
  	   (insert (car (car l)))
  	   (setq l (cdr l))))
         (goto-char (point-min))
!        (setq answer (or arg (yes-or-no-p "Delete these files? "))))
        (if answer
  	  (let ((l delete-list)
  		failures)
--- 568,574 ----
  	   (insert (car (car l)))
  	   (setq l (cdr l))))
         (goto-char (point-min))
!        (setq answer (yes-or-no-p "Delete these files? ")))
        (if answer
  	  (let ((l delete-list)
  		failures)

fpb@sunpitt.east.sun.com (Frank P. Bresz) (01/25/90)

Hi All,

	Last patch was backwards.  Here is the real one.  Thanks to
tale@turing.cs.rpi.edu (David C Lawrence) for catching it.

	Any comments back to:

InterNet :	wpmstr!fbresz@sunpitt.east.sun.com
Voice :		(412)733-6749
Fax :		(412)733-6444
Snail :		Westinghouse Electric Corp
		ITTC Mail Stop 7
		1740 Golden Mile Highway
		Monroeille, PA 15146


enjoy.

					Frank P. Bresz }*{
Here is the patch ...



diff -c dist-18.52/dired.el dired.el
*** dist-18.52/dired.el	Mon Aug  8 08:14:09 1988
--- dired.el	Wed Jan 17 11:32:55 1990
***************
*** 21,28 ****
  ;; can know your rights and responsibilities.  It should be in a
  ;; file named COPYING.  Among other things, the copyright notice
  ;; and this notice must be preserved on all copies.
  
- 
  ;In loaddefs.el
  ;(defvar dired-listing-switches "-al"
  ;  "Switches passed to ls for dired. MUST contain the 'l' option.
--- 21,36 ----
  ;; can know your rights and responsibilities.  It should be in a
  ;; file named COPYING.  Among other things, the copyright notice
  ;; and this notice must be preserved on all copies.
+ ;;
+ ;;-----------------------------------------------------------------------
+ ;; Mon Jan 8, 1990 
+ ;; Kludged (dired-get-filename) wpmstr!fbresz@sunpitt.east.sun.com
+ ;; This is to allow 'F' as a valid switch in the 
+ ;; dired-listing-switches variable 
+ ;; Should probably change the doc string for dired-listing-switches variable 
+ ;; but since it is inside loaddefs.el it will have to wait until a release from
+ ;; FSF.
  
  ;In loaddefs.el
  ;(defvar dired-listing-switches "-al"
  ;  "Switches passed to ls for dired. MUST contain the 'l' option.
***************
*** 271,295 ****
  Value returned normally includes the directory name.
  A non-nil 1st argument means do not include it.  A non-nil 2nd argument
  says return nil if no filename on this line, otherwise an error occurs."
!   (let (eol)
!     (save-excursion
!       (end-of-line)
!       (setq eol (point))
!       (beginning-of-line)
!       (if (re-search-forward
! 	   "\\(Jan\\|Feb\\|Mar\\|Apr\\|May\\|Jun\\|Jul\\|Aug\\|Sep\\|Oct\\|Nov\\|Dec\\)[ ]+[0-9]+"
! 	   eol t)
! 	  (progn (skip-chars-forward " ")
! 		 (skip-chars-forward "^ " eol)
! 		 (skip-chars-forward " " eol)
! 		 (let ((beg (point)))
! 		   (skip-chars-forward "^ \n")
! 		   (if localp
! 		       (buffer-substring beg (point))
! 		     ;; >> uses default-directory, could lose on cd, multiple.
! 		     (concat default-directory (buffer-substring beg (point))))))
! 	(if no-error-if-not-filep nil
! 	  (error "No file on this line"))))))
  
  (defun dired-move-to-filename ()
    "In dired, move to first char of filename on this line.
--- 279,309 ----
  Value returned normally includes the directory name.
  A non-nil 1st argument means do not include it.  A non-nil 2nd argument
  says return nil if no filename on this line, otherwise an error occurs."
!   (let (eol fname)
!     (setq fname 
! 	  (save-excursion
! 	    (end-of-line)
! 	    (setq eol (point))
! 	    (beginning-of-line)
! 	    (if (re-search-forward
! 		 "\\(Jan\\|Feb\\|Mar\\|Apr\\|May\\|Jun\\|Jul\\|Aug\\|Sep\\|Oct\\|Nov\\|Dec\\)[ ]+[0-9]+"
! 		 eol t)
! 		(progn (skip-chars-forward " ")
! 		       (skip-chars-forward "^ " eol)
! 		       (skip-chars-forward " " eol)
! 		       (let ((beg (point)))
! 			 (skip-chars-forward "^ \n")
! 			 (if localp
! 			     (buffer-substring beg (point))
! 			   ;; >> uses default-directory, could lose on cd, multiple.
! 			   (concat default-directory (buffer-substring beg (point))))))
! 	      (if no-error-if-not-filep nil
! 		(error "No file on this line")))))
!     (if fname
! 	(if (file-exists-p fname)
! 	    fname
! 	  (if (file-exists-p (substring fname 0 -1))
! 	      (substring fname 0 -1))))))
  
  (defun dired-move-to-filename ()
    "In dired, move to first char of filename on this line.
***************
*** 432,443 ****
  
  (defun dired-rename-file (to-file)
    "Rename this file to TO-FILE."
!   (interactive
!    (list (read-file-name (format "Rename %s to: "
! 				 (file-name-nondirectory (dired-get-filename)))
! 			 nil (dired-get-filename))))
    (setq to-file (expand-file-name to-file))
!   (rename-file (dired-get-filename) to-file)
    (let ((buffer-read-only nil))
      (beginning-of-line)
      (delete-region (point) (progn (forward-line 1) (point)))
--- 446,459 ----
  
  (defun dired-rename-file (to-file)
    "Rename this file to TO-FILE."
!   (interactive "FRename to: ")
    (setq to-file (expand-file-name to-file))
!   (and (file-directory-p to-file)
!        (setq to-file
! 	     (concat (file-name-as-directory to-file)
! 		     (file-name-nondirectory
! 		      (dired-get-filename)))))
!   (rename-file (dired-get-filename) to-file 0)
    (let ((buffer-read-only nil))
      (beginning-of-line)
      (delete-region (point) (progn (forward-line 1) (point)))
***************
*** 448,455 ****
  (defun dired-copy-file (to-file)
    "Copy this file to TO-FILE."
    (interactive "FCopy to: ")
-   (copy-file (dired-get-filename) to-file)
    (setq to-file (expand-file-name to-file))
    (dired-add-entry (file-name-directory to-file)
  		   (file-name-nondirectory to-file)))
  
--- 464,476 ----
  (defun dired-copy-file (to-file)
    "Copy this file to TO-FILE."
    (interactive "FCopy to: ")
    (setq to-file (expand-file-name to-file))
+   (and (file-directory-p to-file)
+        (setq to-file
+ 	     (concat (file-name-as-directory to-file)
+ 		     (file-name-nondirectory
+ 		      (dired-get-filename)))))
+   (copy-file (dired-get-filename) to-file 0)
    (dired-add-entry (file-name-directory to-file)
  		   (file-name-nondirectory to-file)))
  
***************
*** 542,550 ****
  			    (file-name-nondirectory file)))
    (dired-move-to-filename))
  
! (defun dired-do-deletions ()
    "In dired, delete the files flagged for deletion."
!   (interactive)
    (let (delete-list answer)
      (save-excursion
       (goto-char 1)
--- 563,571 ----
  			    (file-name-nondirectory file)))
    (dired-move-to-filename))
  
! (defun dired-do-deletions (arg)
    "In dired, delete the files flagged for deletion."
!   (interactive "P")
    (let (delete-list answer)
      (save-excursion
       (goto-char 1)
***************
*** 568,574 ****
  	   (insert (car (car l)))
  	   (setq l (cdr l))))
         (goto-char (point-min))
!        (setq answer (yes-or-no-p "Delete these files? ")))
        (if answer
  	  (let ((l delete-list)
  		failures)
--- 589,595 ----
  	   (insert (car (car l)))
  	   (setq l (cdr l))))
         (goto-char (point-min))
!        (setq answer (or arg (yes-or-no-p "Delete these files? "))))
        (if answer
  	  (let ((l delete-list)
  		failures)