2

I try to solve the problem like this in test.el:

(shell)
(rename-buffer "name1")
(shell)
(rename-buffer "name2")
(shell)
(rename-buffer "name3")

However, when I use (eval-buffer) to execute, it seems that the program stops at the 4th line and returns that

Buffer name 'name1' is in use

I am not a pro of elisp, can't figure out what is happening here. Can any one help?

2
  • Not an answer to your question per se, but shell has an optional argument for a buffer/buffer-name and will create it if not already in existence: (shell "foo1") and (shell "foo2"). To read more about how this works, type M-x describe-function RET shell RET or C-h f RET shell RET.
    – lawlist
    Commented Dec 28, 2018 at 3:44
  • Thanks a lot. This actually solved my problem. Commented Dec 28, 2018 at 3:52

1 Answer 1

1

The function shell has an optional argument whereby a user may specify a buffer/buffer-name. To learn more about the the optional argument and a few extra things about the shell, type M-x describe-function RET shell RET or the shortcut C-h f RET shell RET.

For example:

(shell "name1")

(shell "name2")

(shell "name2")
5
  • By the way, can you tell me how can I execute some command in the shell that I opened? Actually it is a cd command, but if I can execute arbitrary command then it is much better. I tried shell-cd but this only works for eval-buffer but cannot be executed in a script file I want emacs load. Commented Dec 28, 2018 at 6:51
  • After digging in the shell-cd definition in shell.el I found the simple function cd which can be invoked and it works. Commented Dec 28, 2018 at 6:55
  • I will not be offended or saddened if you care to edit the question and/or the title to help future forum participants and Google searchers, and/or if you write-up your own answer. The forum rules permit an original poster to accept (check-mark) an answer by the O.P. to his/or her own question within a period of something like 36 to 48 hours.
    – lawlist
    Commented Dec 28, 2018 at 7:41
  • Are you advising me to modify the problem and/or the title? Or you are just telling me a fact? Commented Dec 28, 2018 at 7:57
  • In general, a question/answer have two components: (1) help the original poster; and, (2) help future Google searchers and forum searchers / participants. If the question and title of the question are perfect, then all you need to do is post an alternative answer and accept it if you feel that it is the best. Keep in mind that other forum participants may also provide alternative answers in the near future. If there is anything lacking in the title of the question or the question itself, then editing the question and/or title to be more helpful to others in the future would be appropriate.
    – lawlist
    Commented Dec 28, 2018 at 8:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.