I relise that I have to add something like:
shell
: to m开发者_StackOverflow社区y .emacs file. But then how can I get it to do shell commands like:
cd /mydirectory
: and other shell actions
This is a function which does what you want. You can add it (customizing the actions), or just add the body:
(defun shell-and-stuff ()
"run a shell, then do some extra stuff"
(interactive)
(let ((shell-buf (get-buffer-create "*shell*")))
(shell shell-buf)
(comint-send-string
(get-buffer-process shell-buf)
"cd some-directory
ls
touch frog
")))
(shell-and-stuff)
The cd
part is easy, just let
bind the variable default-directory
. See this question for some possible solutions.
Trey Jackson's idea looks good. Also note that the manual (info "(emacs) Interactive Shell")
says
Emacs sends the new shell the contents of the file
~/.emacs_SHELLNAME
as input, if it exists, where SHELLNAME is the name of the file that the shell was loaded from. For example, if you use bash, the file sent to it is~/.emacs_bash
. If this file is not found, Emacs tries to fallback on~/.emacs.d/init_SHELLNAME.sh
.
So you could put your commands in that file.
精彩评论