| Paste number 81834: | my-rename-file |
| Pasted by: | quidnunc |
| When: | 7 months, 3 weeks ago |
| Share: | Tweet this! | http://paste.lisp.org/+1R56 |
| Channel: | None |
| Paste contents: |
;; Courtesy of offby1
(defun my-rename-file (bufname newname)
"Rename the file visited by buffer BUFNAME to NEWNAME. BUFNAME
defaults to the current buffer.
This is a bit like \\[dired-do-rename], except that you don't have to
run \\[dired] to get at it!"
(interactive "bBuffer: \nFNew name: ")
(let ((oldname (buffer-file-name)))
(or oldname (error "%s isn't visiting a file" bufname))
(if (file-directory-p newname)
(setq newname (concat newname (file-name-nondirectory oldname))))
(rename-file oldname newname)
;; TODO -- ensure that, if set-visited-file-name fails, the file
;; rename gets undone.
(with-current-buffer bufname
(set-visited-file-name newname nil t))
(message "Renamed %s to %s" bufname newname)))
This paste has no annotations.