[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: rename-file

From: Sam Steingold
Subject: Re: rename-file
Date: Wed, 26 Aug 2009 16:35:31 -0400

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))))

Sam Steingold <http://sds.podval.org>

reply via email to

[Prev in Thread] Current Thread [Next in Thread]