all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Daniel Colascione <danc@merrillpress.com>
To: Emacs-Devel devel <emacs-devel@gnu.org>
Subject: Re: rename-file
Date: Thu, 27 Aug 2009 09:49:00 -0400	[thread overview]
Message-ID: <40360924-EE9E-4E34-92F5-46BB40338EF7@merrillpress.com> (raw)
In-Reply-To: <4A955D32.8030202@gnu.org>

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




      parent reply	other threads:[~2009-08-27 13:49 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-26 16:05 rename-file Sam Steingold
2009-08-26 18:58 ` rename-file Stephen Berman
2009-08-27  3:16   ` rename-file Stefan Monnier
2009-08-27  8:38     ` rename-file Stephen Berman
2009-08-27  9:09       ` rename-file Andreas Schwab
2009-08-27 10:01         ` rename-file Stephen Berman
2009-08-27 10:21           ` rename-file Andreas Schwab
2009-08-27 11:28             ` rename-file Stephen Berman
2009-08-27 11:50               ` rename-file Miles Bader
2009-08-27 14:59                 ` rename-file Stephen Berman
2009-08-27 12:18               ` rename-file Andreas Schwab
2009-08-27 17:08       ` rename-file Stefan Monnier
2009-08-26 19:21 ` rename-file Stefan Monnier
2009-08-26 20:20   ` rename-file Lennart Borgman
2009-08-26 20:35   ` rename-file Sam Steingold
2009-08-27  3:15     ` rename-file Eli Zaretskii
2009-08-27  3:25     ` rename-file Richard Stallman
2009-08-27  3:41       ` rename-file Sam Steingold
2009-08-27 17:11         ` rename-file Stefan Monnier
2009-08-29  0:46         ` rename-file Richard Stallman
2009-08-31 22:09           ` rename-file Sam Steingold
2009-08-27 14:47     ` rename-file Sam Steingold
2009-08-26 20:42 ` rename-file martin rudalics
2009-08-27 13:49 ` Daniel Colascione [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=40360924-EE9E-4E34-92F5-46BB40338EF7@merrillpress.com \
    --to=danc@merrillpress.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.