From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Daniel Colascione Newsgroups: gmane.emacs.devel Subject: Re: rename-file Date: Thu, 27 Aug 2009 09:49:00 -0400 Message-ID: <40360924-EE9E-4E34-92F5-46BB40338EF7@merrillpress.com> References: <4A955D32.8030202@gnu.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 (Apple Message framework v936) Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1251380987 23426 80.91.229.12 (27 Aug 2009 13:49:47 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 27 Aug 2009 13:49:47 +0000 (UTC) To: Emacs-Devel devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Aug 27 15:49:40 2009 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MgfM6-0007ks-Vk for ged-emacs-devel@m.gmane.org; Thu, 27 Aug 2009 15:49:35 +0200 Original-Received: from localhost ([127.0.0.1]:46363 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MgfM6-0000Wh-EK for ged-emacs-devel@m.gmane.org; Thu, 27 Aug 2009 09:49:34 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MgfLz-0000Uo-GX for emacs-devel@gnu.org; Thu, 27 Aug 2009 09:49:27 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MgfLu-0000PM-V7 for emacs-devel@gnu.org; Thu, 27 Aug 2009 09:49:27 -0400 Original-Received: from [199.232.76.173] (port=41106 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MgfLu-0000PD-Qg for emacs-devel@gnu.org; Thu, 27 Aug 2009 09:49:22 -0400 Original-Received: from vpn.merrillpress.com ([64.61.107.78]:42524) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MgfLu-0000Jv-Ft for emacs-devel@gnu.org; Thu, 27 Aug 2009 09:49:22 -0400 Original-Received: from cpe-67-246-181-235.buffalo.res.rr.com ([67.246.181.235] helo=[192.168.1.104]) by mars.merrillpress.net with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.63) (envelope-from ) id 1MgfLs-00061V-Fp for emacs-devel@gnu.org; Thu, 27 Aug 2009 09:49:20 -0400 In-Reply-To: <4A955D32.8030202@gnu.org> X-Pgp-Agent: GPGMail 1.2.0 (v56) X-Mailer: Apple Mail (2.936) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:114688 Archived-At: -----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 =3D4l7w -----END PGP SIGNATURE-----