From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Hongxu Chen Newsgroups: gmane.emacs.help Subject: Re: resolve rename-buffer conflicts Date: Mon, 17 Jun 2013 08:07:28 +0800 Message-ID: <87k3lt38hr.fsf@gmail.com> References: <87hah131ab.fsf@gmail.com> <87fvwhykn4.fsf@web.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1371427669 31363 80.91.229.3 (17 Jun 2013 00:07:49 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 17 Jun 2013 00:07:49 +0000 (UTC) To: help-gnu-emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Jun 17 02:07:50 2013 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UoMz7-0006Np-Rh for geh-help-gnu-emacs@m.gmane.org; Mon, 17 Jun 2013 02:07:49 +0200 Original-Received: from localhost ([::1]:42400 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UoMz7-0005d9-An for geh-help-gnu-emacs@m.gmane.org; Sun, 16 Jun 2013 20:07:49 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51095) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UoMyv-0005d4-9Z for help-gnu-emacs@gnu.org; Sun, 16 Jun 2013 20:07:39 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UoMys-0001x9-V8 for help-gnu-emacs@gnu.org; Sun, 16 Jun 2013 20:07:37 -0400 Original-Received: from mail-pa0-x233.google.com ([2607:f8b0:400e:c03::233]:41531) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UoMys-0001x3-O8 for help-gnu-emacs@gnu.org; Sun, 16 Jun 2013 20:07:34 -0400 Original-Received: by mail-pa0-f51.google.com with SMTP id lf11so2277195pab.10 for ; Sun, 16 Jun 2013 17:07:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:references:date:in-reply-to:message-id:user-agent :mime-version:content-type; bh=Vx2CTCS4gsK7xyHeddgAdyNLoVEcGMCJ6qI+JLyACsk=; b=BrgBaV03d7ZugnP1GGgKU2E+q1zkG5Gg0IH1R2m8hy4JCWNplIKXaDnkE+APbG5FO4 ljkM5d/kEvEjQDRYeUcVFQnJQgPi7IjxX2AtZGB0BNbezJ7c3zCDswup1Qd1YJxjROKo b9SyPyqx+bUr6SNfT0t5O//yNP2xY7L1RKs1P/hLOn0rikbxkK4gLRcjQUf6X6lwN0V+ z2uJw64s7y2eIn3rZvNfqGYZu6E4etFUz2KL5KoCWEkjm9r5AWNhOL91KSOFNuP88CEl xB54hAuWgajndstMMuFfIBnApGwy5gVqS1pykGdDZevl63caSxLYEqyWPco2g+Nx1yW7 uk4A== X-Received: by 10.66.217.226 with SMTP id pb2mr10679785pac.109.1371427653271; Sun, 16 Jun 2013 17:07:33 -0700 (PDT) Original-Received: from hongxuchen-VM.STAP ([167.220.232.198]) by mx.google.com with ESMTPSA id jb2sm11460641pbc.8.2013.06.16.17.07.31 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 16 Jun 2013 17:07:32 -0700 (PDT) In-Reply-To: <87fvwhykn4.fsf@web.de> (Michael Heerdegen's message of "Sun, 16 Jun 2013 20:29:19 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400e:c03::233 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:91574 Archived-At: Michael Heerdegen writes: > Hi Hongxu, > >> ,----------[ rename-this-file ] >> | (defun rename-this-file (new-name) >> | "Renames both current buffer and file it's visiting to NEW-NAME." >> | (interactive "sNew name: ") >> | (let ((name (buffer-name)) >> | (filename (buffer-file-name))) >> | (unless filename >> | (error "Buffer '%s' is not visiting a file!" name)) >> | (if (get-buffer new-name) >> | (message "A buffer named '%s' already exists!" new-name) >> | (progn >> | (rename-file filename new-name t) >> | (rename-buffer new-name t) >> | (set-visited-file-name new-name) >> | (set-buffer-modified-p nil))))) >> `---------- > >> A buffer named 'test.cpp' already exists! >> >> So Why it fails for the snippet above? > > I tested your code in a recent build of trunk, and it works fine here. > > Can you reproduce your problem with emacs -Q? Which Emacs version are > you using? Maybe try to follow what's happening with the debugger. You > probably want to (debug-on-entry 'rename-this-file). Load file sources > to avoid debugging compiled code. Thanks for your advice, Michael. I now figure out that I made a silly mistake here, the `if' condition here should be stripped as well. I didn't even notice that! The fixed version is simpler: ,----------[ rename-this-file ] | (defun rename-this-file (new-name) | "Renames both current buffer and file it's visiting to NEW-NAME." | (interactive "sNew name: ") | (let ((name (buffer-name)) | (filename (buffer-file-name))) | (unless filename | (error "Buffer '%s' is not visiting a file!" name)) | (rename-file filename new-name t) | (rename-buffer new-name t) | (set-visited-file-name new-name) | (set-buffer-modified-p nil))) `---------- > > > Regards, > > Michael. -- Regards, Hongxu Chen