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: resolve rename-buffer conflicts Date: Fri, 14 Jun 2013 09:54:04 +0800 Message-ID: <87hah131ab.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1371174868 11867 80.91.229.3 (14 Jun 2013 01:54:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 14 Jun 2013 01:54:28 +0000 (UTC) To: help-gnu-emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jun 14 03:54:27 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 1UnJDe-0007oc-Vq for geh-help-gnu-emacs@m.gmane.org; Fri, 14 Jun 2013 03:54:27 +0200 Original-Received: from localhost ([::1]:39963 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UnJDe-00059y-Fe for geh-help-gnu-emacs@m.gmane.org; Thu, 13 Jun 2013 21:54:26 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38560) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UnJDS-00059e-9g for help-gnu-emacs@gnu.org; Thu, 13 Jun 2013 21:54:16 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UnJDP-00031e-Oy for help-gnu-emacs@gnu.org; Thu, 13 Jun 2013 21:54:14 -0400 Original-Received: from mail-pd0-f176.google.com ([209.85.192.176]:59442) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UnJDP-00031T-IP for help-gnu-emacs@gnu.org; Thu, 13 Jun 2013 21:54:11 -0400 Original-Received: by mail-pd0-f176.google.com with SMTP id t12so49092pdi.21 for ; Thu, 13 Jun 2013 18:54:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:user-agent:mime-version :content-type; bh=dLJASTu8wB6RJE9adEhd5wUXzsgG9mv7QXz8efASi5U=; b=rBgGP7mna/W/y7SrlKdx3oGQlTJADoTHFLjypludhEu/DtT6Xfe/T/v/s/CWkW3fMR zUsbROmOddpaVMPaSn2HtTUeKKnpnZoosMGBBeg/ZhragR0uL7sMgPdx0gX8MIsx1Ol/ ndqoa8daY5GjC3F3VwOcgQ2HROFiH0SKkL5eHdGR062vgSuPZBwDTaN31x+w/Tap7NEt AlTFGFn0nMedG6em4gO47dU+MIelaksMF52/yoEibUnxyuftShFLyKTMlnOB6oNwau6H yT31LTt5Qj0r9O6+MkWrHDGXWsHi0fNXVlx34mOp8OdJRSCZRMEyC3TspBt9OUxBOOJc omyw== X-Received: by 10.66.145.2 with SMTP id sq2mr215458pab.2.1371174849793; Thu, 13 Jun 2013 18:54:09 -0700 (PDT) Original-Received: from hongxuchen-VM.STAP ([167.220.232.198]) by mx.google.com with ESMTPSA id l4sm192210pbo.6.2013.06.13.18.54.07 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 13 Jun 2013 18:54:08 -0700 (PDT) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.192.176 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:91535 Archived-At: Hi, I have followed some tips to rename file(and the corresponding buffer name) like this below: ,----------[ 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))))) `---------- Since there might be a buffer name conflict I am using `(rename-buffer new-name t)' inside this function instead(according to the docstrings, if the last argument is non-nil it is supposed to generate a new buffer name when there is a conflict). However it DOESN'T work at all. It reports like below: A buffer named 'test.cpp' already exists! But it works fine when invoking `rename-buffer' interactively like `C-u M-x rename-buffer'. So Why it fails for the snippet above? (I also use uniquify.el but I don't believe it is a problem since it defines an advice `rename-buffer-uniquify') -- Regards, Hongxu Chen