home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / misc / dired-fns.el < prev    next >
Encoding:
Text File  |  1990-07-22  |  2.7 KB  |  77 lines

  1. ;From: rbj@DSYS.NCSL.NIST.GOV (Root Boy Jim)
  2. ;Newsgroups: gnu.emacs.bug
  3. ;Subject: Renaming Files With DIRED
  4. ;Message-ID: <8908311954.AA23564@dsys.ncsl.nist.gov>
  5. ;Date: 31 Aug 89 19:54:32 GMT
  6. ;Distribution: gnu
  7. ;Organization: National Institute of Standards and Technology formerly National Bureau of Standards
  8. ;Lines: 67
  9. ;
  10. ;? From: wpmstr!omaha1!fpb%sunpitt.East@sun.com (Frank P. Bresz - Westinghouse ITTC)
  11. ;
  12. ;? In GNU Emacs 18.52.3 of Tue Apr 11 1989 on omaha1 (berkeley-unix)
  13. ;
  14. ;? Hi,
  15. ;?     I have just finished implementing a change to dired.el to allow you
  16. ;? to move a file from 1 directory to another easily.  It seems that I often
  17. ;? want to do this and the functionality did not exist, so I added it.  The
  18. ;? code I wrote may be a touch inelegant.  If anyone wants the code I can
  19. ;? mail it.  
  20. ;
  21. ;I have always wanted this too. Your note prompted me to code it up.
  22. ;I also added the ability to overwrite the file if desired.
  23.  
  24. (defun dired-rename-file (to-file)
  25.   "Rename this file to TO-FILE."
  26.   (interactive "FRename to: ")
  27. ;;;;  (interactive
  28. ;;;;   (list (read-file-name (format "Rename %s to: "
  29. ;;;;                 (file-name-nondirectory (dired-get-filename)))
  30. ;;;;             nil (dired-get-filename))))
  31.   (setq to-file (expand-file-name to-file))
  32.   (and (file-directory-p to-file)
  33.        (setq to-file
  34.          (concat (file-name-as-directory to-file)
  35.              (file-name-nondirectory
  36.               (dired-get-filename)))))
  37.   (rename-file (dired-get-filename) to-file 0)
  38.   (let ((buffer-read-only nil))
  39.     (beginning-of-line)
  40.     (delete-region (point) (progn (forward-line 1) (point)))
  41.     (setq to-file (expand-file-name to-file))
  42.     (dired-add-entry (file-name-directory to-file)
  43.              (file-name-nondirectory to-file))))
  44.  
  45. (defun dired-copy-file (to-file)
  46.   "Copy this file to TO-FILE."
  47.   (interactive "FCopy to: ")
  48.   (setq to-file (expand-file-name to-file))
  49.   (and (file-directory-p to-file)
  50.        (setq to-file
  51.          (concat (file-name-as-directory to-file)
  52.              (file-name-nondirectory
  53.               (dired-get-filename)))))
  54.   (copy-file (dired-get-filename) to-file 0)
  55. ;;;;  (setq to-file (expand-file-name to-file))
  56.   (dired-add-entry (file-name-directory to-file)
  57.            (file-name-nondirectory to-file)))
  58.  
  59. ;BTW, I changed the interactive spec on dired-rename-file to match
  60. ;the one on dired-copy-file. Does anyone know why they differ?
  61. ;I also moved the expand-file-name in copy up a bit to match the
  62. ;one in dired-rename-file. Anyone know why they differ, or even
  63. ;why it is present?
  64. ;
  65. ;?                     Frank P. Bresz }*{
  66. ;? sunpitt!wpmstr!omaha1!fpb@Sun.COM
  67. ;
  68. ;? !!! PLEASE USE THE ABOVE ADDRESS
  69. ;? !!! DO NOT REPLY TO THE ADDRESS GENERATED BY THE MAILER:
  70. ;? !!! wpmstr!omaha1!fbresz%sunpitt.East@sun.com 
  71. ;? !!! SUN.COM rejects it.
  72. ;
  73. ;'nother feechur from the dired wizard,
  74. ;
  75. ;    Root Boy Jim and
  76. ;    the GNU Bohemians
  77.