Article View: gnu.emacs.bug
Article #99211Re: Dired: mv, mkdir
From: Mike Williams
Date: Fri, 19 Oct 1990 16:25
Date: Fri, 19 Oct 1990 16:25
99 lines
4455 bytes
4455 bytes
+-- In article <9010151328.AA02444@.diderot.gr.osf.org.>
macrakis@DIDEROT.GR.OSF.ORG (Stavros Macrakis) writes:
|
| I suggest that Dired allow renaming/moving (r) and copying (c) a file
| to a directory as well as to a file.
|
| It would also be nice to be able to create directories within Dired.
The code included below should do what you want. I've also included a
rewrite of dired-add-entry, as the old version seemed to do strange
things with symlinks.
--- cut here ---
;; Copyright Mike Williams 1990 etc etc
;; No warranty, you can copy it, blah blah
(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))
(if (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)
(let ((buffer-read-only nil))
(beginning-of-line)
(delete-region (point) (progn (forward-line 1) (point)))
(setq to-file (expand-file-name to-file))
(dired-add-entry (file-name-directory to-file)
(file-name-nondirectory to-file))))
(defun dired-copy-file (to-file)
"Copy this file to TO-FILE."
(interactive "FCopy to: ")
(setq to-file (expand-file-name to-file))
(if (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)
(setq to-file (expand-file-name to-file))
(dired-add-entry (file-name-directory to-file)
(file-name-nondirectory to-file)))
(defun dired-mkdir (dir)
"Create a new sub-directory."
(interactive "FNew directory name: ")
(call-process "mkdir" nil nil nil (expand-file-name dir))
(message "Directory %s created." dir)
(dired-add-entry default-directory
(file-name-nondirectory dir)))
(defun dired-symlink (to link)
"Make a symbolic link to another file."
(interactive "fSymbolic link to: \nFLink name: ")
(setq link (expand-file-name link))
(call-process "ln" nil nil nil "-s"
(expand-file-name to) link)
(message "Symbolic link created.")
(dired-add-entry (file-name-directory link)
(file-name-nondirectory link)))
;;=== dired-add-entry ===
;; The old version did funny things with symlinks. In any case, I can't
;; see why it has to delete the filename then re-insert it !!
(defun dired-add-entry (directory filename)
;; If tree dired is implemented, this function will have to do
;; something smarter with the directory. Currently, just check
;; default directory, if same, add the new entry at point. With tree
;; dired, should call 'dired-current-directory' or similar. Note
;; that this adds the entry 'out of order' if files sorted by time,
;; etc.
(if (string-equal directory default-directory)
(let ((buffer-read-only nil))
(beginning-of-line)
(call-process "ls" nil t nil "-d" dired-listing-switches
filename)
;; (concat directory filename)
(forward-line -1)
(insert " ")
;; (dired-move-to-filename)
;; (let* ((beg (point))
;; (end (progn (end-of-line) (point))))
;; (setq filename (buffer-substring beg end))
;; (delete-region beg end)
;; (insert (file-name-nondirectory filename)))
(beginning-of-line))))
--- end of code ---
--
/-------------------- byrd@comp.vuw.ac.nz --------------------\
| Mike Williams, Victoria University of Wellington, Aotearoa. |
\-------- Yesterday, I ... no, wait, that wasn't me. ---------/
Technical Details
Message-ID:
<BYRD.90Oct19122535@downstage.comp.vuw.ac.nz>Path:
arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!tut.cis.ohio-state.edu!COMP.VUW.AC.NZ!Mike.WilliamsShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fb2f1,eed0f6032d00ff3b X-Google-Attributes: gidfb2f1,public X-Google-ArrivalTime: 1990-10-19 09:25:35 PST Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!tut.cis.ohio-state.edu!COMP.VUW.AC.NZ!Mike.Williams From: Mike.Williams@COMP.VUW.AC.NZ (Mike Williams) Newsgroups: gnu.emacs.bug Subject: Re: Dired: mv, mkdir Message-ID: <BYRD.90Oct19122535@downstage.comp.vuw.ac.nz> Date: 19 Oct 90 16:25:35 GMT Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: Dept. of Computer Science, Victoria Uni. of Wellington, NZ. Lines: 99 Approved: bug-gnu-emacs@prep.ai.mit.edu Posted: Fri Oct 19 17:25:35 1990