help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Make rename-file() also rename visiting buffers


From: Nikolaj Schumacher
Subject: Re: Make rename-file() also rename visiting buffers
Date: Thu, 14 Jun 2007 12:43:14 +0200
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (darwin)

Nordlöw <per.nordlow@gmail.com> wrote:

> Why does not rename-file() correspondingly rename all buffers visiting
> that file?

Because buffers are associated with file names and not files.  Changing
the buffer name would break backup for instance, which (by default)
renames the file and then writes it again.

I don't think there can be multiple buffers visiting the same file, thuogh.

> How can I make this happen?

Something like this:

(defun rename-this-file (new-name)
  "Rename this buffer's file to NEW-NAME."
  (interactive
   (let ((file (or buffer-file-name (error "Not a file"))))
     (list (read-file-name
            "New name: " (file-name-directory file) nil nil
            (file-name-nondirectory file)))))
  (if (vc-backend buffer-file-name)
      (vc-rename-file buffer-file-name new-name))
    (rename-file buffer-file-name new-name)
    (set-visited-file-name new-name t t))


regards,
Nikolaj Schumacher




reply via email to

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