On Wed, Aug 26, 2009 at 3:21 PM, Stefan Monnier<address@hidden> wrote:
Why isn't the buffer, which is visiting a file, renamed
when I rename the underlying file with rename-file?
Because rename-file is a low-level function. Maybe we should introduce
a new command rename-file-buffer which automatically applies to the
current buffer's file.
OK to commit?
(defun rename-buffer-file (new-name)
"Rename the current buffer and the file it is visiting to NEW-NAME."
(interactive "FRename current file and buffer to: ")
(let ((filename (or buffer-file-name
(error "This buffer is not visiting a file")))
(oldbuf (find-buffer-visiting new-name)))
(when (or (null oldbuf)
(y-or-n-p "Buffer %s is already visiting %s, proceed? "
oldbuf new-name))
(rename-file filename new-name 1)
(set-visited-file-name new-name nil t))))