emacs-devel
[Top][All Lists]
Advanced

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

Re: rename-file


From: Daniel Colascione
Subject: Re: rename-file
Date: Thu, 27 Aug 2009 09:49:00 -0400

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Aug 26, 2009, at 12:05 PM, Sam Steingold wrote:
Why isn't the buffer, which is visiting a file, renamed
when I rename the underlying file with rename-file?

Here's what I use. It's DTRT for years. (I have it bound to C-x m.)
Something like this, IMHO, should be the user-level rename-file.


(defun qtmstr-rename-file (new)
 "Rename file OLD to NEW, renaming the buffer as well.

If the file is under version control, act like vc-rename-file."

 (interactive "FRename to: ")

 (let ((oldbuf (current-buffer))
       (oldbufname (buffer-name))
       (old (buffer-file-name))
       vc)

   (if (and oldbuf (buffer-modified-p oldbuf))
        (error "Please save files before moving them"))
   (if (get-file-buffer new)
        (error "Already editing new file name"))
   (if (file-exists-p new)
        (error "New file already exists"))

   (let ((state (vc-state old)))
     (cond ((memq state '(up-to-date edited))
            (setq vc t)
            (vc-call rename-file old new)
            (vc-file-clearprops old))

           (state
            (error "Please %s files before moving them"
                   (if (stringp state) "check in" "update")))))

   (if (file-exists-p old) (rename-file old new))

   (with-current-buffer oldbuf
     (let ((buffer-read-only buffer-read-only))
       (set-visited-file-name new))
     (when vc
       (vc-backend new)
       (vc-mode-line new))
     (set-buffer-modified-p nil))
   (message "Renamed %s to %s%s"
            oldbufname new (if vc " [with VC]" ""))))
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Darwin)

iEYEARECAAYFAkqWjswACgkQ17c2LVA10VtOywCgxhjjfavlB0qDDKMKgR1D1llN
o3IAoIICnOzZbDqP+RBpT3m2tPyXg935
=4l7w
-----END PGP SIGNATURE-----




reply via email to

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