all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* resolve rename-buffer conflicts
@ 2013-06-14  1:54 Hongxu Chen
  2013-06-16 18:29 ` Michael Heerdegen
  0 siblings, 1 reply; 3+ messages in thread
From: Hongxu Chen @ 2013-06-14  1:54 UTC (permalink / raw)
  To: help-gnu-emacs


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



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-06-17  0:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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

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.