Start Emacs in shell when started form shell Start Emacs in shell when started form shell shell shell

Start Emacs in shell when started form shell


So there's the alias solution, but a pb I encounter is that I sometimes make emacs sleep with Ctrl-z and then I forget I have an emacs session launched so I use my alias once again and I end up with two emacs in the terminal, which annoys me. So I use a function which checks if an emacs is already running:

cemacs () {if (ps|grep emacs); then   echo  "Hey, emacs is already running";          fg %emacselse     emacs -nw $@fi}

Shortcut

I defined a handy shortcut to revive a sleeping emacs:

bind -x '"\C-x\C-e":fg %emacs' 

Emacs-server

So that's what I used for quite long, and it isn't perfect. I can not launch a normal emacs and then my function, unless if I use emacs server: http://wikemacs.org/index.php/Emacs_server

Just create an alias to emacsclient -t.

and shell-mode

But now, I much prefer to use a terminal inside emacs (it is so handy to move around the shell's buffer, to copy-paste without the mouse, to look for a string, to go to the beginning of the output, to manipulate files with dired,…).


Good Idea !

I've just updated my .bashrc :

edit_file_in_emacs_console() {    emacsclient -t $@ || emacs -q -nw $@}if [ "$PS1" ]; then    alias emacs=edit_file_in_emacs_consolefi

So I use current emacs server if available, or a simple emacs console (-q) for faster startup.