I'm used to run emacs from my shell and my mind is not able to switch from the command emacs to emacs-client when I have an opened windows. This is why I wrote this simple shell script that:

  • run emacs (and force server-start) in detached screen with a particular id (emax) if this screen doesn't already exist
  • run emacs-client (with the -n option : don't wait for the server to return) else
[shell]
#!/bin/bash

screen -list |grep emax > /dev/null
if [ $? -eq 1 ]; then
	echo "screening -- emacs $@"
	screen -S emax -d -m emacs -f 'server-start' $@
else
	echo "connect to emacs server and detach -- emacs $@"
	emacsclient -n $@
fi

I prefer to get a separate emacs instance when I'm writing mail because I can focus on it. You may want to have special cases for this, use this script instead :

[shell]
#!/bin/bash

# special case for mutt mail edition
if [[ "$1" =~ "/tmp/mutt"  ]]; then
    echo "attached"
    detach=0
else
     echo "detached"
    detach=1
fi

screen -list |grep emax > /dev/null
if [ $? -eq 1 ]; then
    if [ $detach -eq 1 ]; then
	echo "screening -- emacs $@"
	screen -S emax -d -m emacs -f 'server-start' $@
    else
	echo "normal mode -- emacs $@"
	emacs -f 'mail-mode' $@
    fi
else
    if [ $detach -eq 1 ]; then
	echo "connect to emacs server and detach -- emacs $@"
	emacsclient -n $@
    else
	echo "connect to emacs server -- emacs $@"
	emacsclient $@
    fi
fi

Note: I also set a zsh alias to emacs on this script