Each time I open a new terminal in Emacs "M-x term" I get the currently open one, to get around this I need to rename the buffer where the terminal is running upon and then start a new one through M-x term.
I would like to write a function which holds a global counter and uses it to start a new terminal using it to generate the buffer name; once done I could map this function to a key binding of my preference.
I am having issues in running the terminal in a new created buffer, I am not an experienced ELisp programmer and this code might look quite naive to some, nonetheless this where I am at the moment :
(defvar counter 0)
(defun mine/open-terminal ()
"Open a new terminal and rename the buffer"
(setq counter (+ counter 1))
(setq title (concat "Terminal-" (number-to-string counter)))
(setq terminal (get-buffer-create title))
That function creates a new buffer with the correct name - although it does not show up it immediately as I would like it to do, the rub is that if I add at the end of the function the line:
(term "/bin/bash")
A new buffer called terminal is created, I have the feeling I am missing a bit here, is there a way to start a new terminal giving to it a buffer name ?
Thanks a lot.
termis just a few lines long -- so go ahead and find the function, open it up, copy it to your.emacs, and create a new function with a different name incorporating a concept similar to the link in the first comment:M-x find-function RET term RET. When you programmatically loop through or search for existing buffers with a particular name, that obviates the need to store buffer object/name information in a global variable. The latter is possible, but appears to be necessary unless the variable will later be used for other things not specified in the question.(require 'term)in the.emacsorM-x eval-expression RET (require 'term) RET.