From: Hongxu Chen <leftcopy.chx@gmail.com>
To: help-gnu-emacs <help-gnu-emacs@gnu.org>
Subject: Re: resolve rename-buffer conflicts
Date: Mon, 17 Jun 2013 08:07:28 +0800 [thread overview]
Message-ID: <87k3lt38hr.fsf@gmail.com> (raw)
In-Reply-To: <87fvwhykn4.fsf@web.de> (Michael Heerdegen's message of "Sun, 16 Jun 2013 20:29:19 +0200")
Michael Heerdegen <michael_heerdegen@web.de> 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
prev parent reply other threads:[~2013-06-17 0:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-14 1:54 resolve rename-buffer conflicts Hongxu Chen
2013-06-16 18:29 ` Michael Heerdegen
2013-06-17 0:07 ` Hongxu Chen [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=87k3lt38hr.fsf@gmail.com \
--to=leftcopy.chx@gmail.com \
--cc=help-gnu-emacs@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.