Reputation: 10102
This happens frequently to me: I am using several M-x shell
shells at the same time. To open the next shell, I have to rename the first one with rename-buffer
. However, emacs simply then prompts the new buffer name without permitting me to reusing the existing buffer name to construct a related one like *shell* dist
in place of *shell*
. So how can I write the new name without retyping everything?
Upvotes: 6
Views: 1772
Reputation: 73274
Note also C-hf rename-uniquely
So one option is:
rename-uniquely
RETshell
RETHowever for this specific use-case, you can circumvent a renaming step entirely by using a prefix argument when you invoke the command: C-uM-x shell
Obviously this all depends on whether you're happy with the automated name, or if you wanted to name it something more meaningful. If the latter, than the answer by false is clearly going to be the most useful (probably in conjunction with the prefix argument approach).
Upvotes: 7
Reputation: 4521
How about this.
(defun rename-buffer ()
(interactive)
(rename-buffer (read-string "Rename buffer (to new name): " (buffer-name))))
Current buffer name will appear first. Then you can rename it.
Upvotes: 1
Reputation: 30699
Both @phils and @false provide good answers, and perhaps there will be more good answers to come. As @phils pointed out, it somewhat depends on what behavior you want.
Here's my contribution ---
In addition to using M-n
to retrieve the current buffer name (so you can edit it), it can also be handy to use lax completion against the existing buffer names.
Lax completion means you can, if you want, totally ignore the completion candidates and enter any new name you want. But it also means that you can complete to one of the existing names and then edit it to come up with a similar but different name, where the new name means something to you. IOW, just the behavior that M-n
gives you, but for all buffer names and with matching instead of cycling (repeating M-n
).
Library misc-cmds.el
advises the definition of rename-buffer
to give you such completing behavior. If you don't want other things in that library, you can just grab its definition of rename-buffer
.
It is quick to give buffers names that are related to other buffers but are more meaningful than what automatic uniquifying schemes provide. (I bind rename-buffer
to a key.)
Upvotes: 1
Reputation: 10102
When rename-buffer
prompts for the new name, simply do cursor down. With cursor up you get all the other names.
After so many years of emacsing, I only discovered this right now...
Upvotes: 6