Suppose you just want to call a shell in your code. In Lisp, the entire prefix notation is surrounded by parentheses. Therefore, we inject this into the buffer (say, the zero buffer):
(shell)
Move the cursor to the end of the line after closing and type <Cx Ce> to execute the Lisp code. You should see that the shell function is being called.
Now let's make it a function, so we can add other things to it. The command is to create the defun function, and it takes the name of the function, a list of arguments (in parentheses), and then the body of the function:
(defun automate-connection () (shell))
Move the cursor to the end of the code, press <Cx Ce> , and the function will be defined. You can call it from Lisp by doing
(automate-connection)
Ok, now we just need to put some text in the shell buffer.
(defun automate-connection () (shell) (insert "TERM=xterm"))
Now that we run this, we get "TERM = xterm" placed in the shell buffer. But actually it does not send a command. Let's try to put a new line.
(defun automate-connection () (shell) (insert "TERM=xterm\n"))
This puts a new line, but does not actually run the command. Why not? Let's see what the input key does. Go to the *shell* buffer and type <Ch c> , then press the return key. ( <Ch c> starts describe-key-briefly , which prints the name of the function describe-key-briefly by pressing this key). This suggests that when you press RET, it does not put a new line, but actually calls comint-send-input . So do this:
(defun automate-connection () (shell) (insert "TERM=xterm") (comint-send-input))
Now, when you start `(automatic connection) from any Lisp code, you should send this thing. I leave this as a reading exercise to add your other commands.
But wait! We really didnβt, right? I assume that you do not want to move to the Lisp buffer, type (automate-connection) , and then evaluate this code. You probably just want to enter and name it day. You cannot do this by default with the function you just created. Fortunately, just allowing it: just add the (interactive) call to your function:
(defun automate-connection () (interactive) (shell) (insert "TERM=xterm") (comint-send-input))
Now you can call it the way you want, and it will open the *shell* buffer, put it in the text and tell Emacs to tell the shell to run that text.