Skip to content

Commit

Permalink
Fix up logic for emacsclient support.
Browse files Browse the repository at this point in the history
Deciding between client and server on startup is gnarly, plus bash function calls in emacsclient --tty  seems to break.
emacsclient will fall back to emacs if things break anyway. Also fall back to emacs -nw if we don't
have multi-tty as it would get confusing (maybe I'll change later if I can flash screen).
  • Loading branch information
stsquad authored and Alex Bennee committed Nov 3, 2008
1 parent d7905c3 commit ecb4e99
Showing 1 changed file with 30 additions and 21 deletions.
51 changes: 30 additions & 21 deletions dotbashrc
Expand Up @@ -204,30 +204,39 @@ alias mkcdimg="mkisofs -v -R -o ~/tmp/temp.iso "
######################

# There is only one editor (although I can get to it in different ways)
# roughly based on the emacs.bash with emacs

alias ec="emacsclient"

export ALTERNATE_EDITOR=emacs
export EDITOR=ec
export VISUAL=ec

# Start an emacsclient or start emacs if no server if running
start_emacs() {

if [[ "$@" == "" || "$1" == "-nw" ]]; then
$ALTERNATE_EDITOR "$@"
#
# Anything that uses EDITOR/VISUAL probably wants to call emacsclient if it can.
# The only other wrinkle being that in none X mode I'll be wanting to use multi-tty
# support if it exists. Let's see if we can make sense of all that.

# Only do this if the server is running
if [ -e "${HOME}/.emacs_server" -o -e "/tmp/emacs${UID}/server" ]; then
if [[ "$DISPLAY" == "" ]]; then
# Can we use muti-tty?
emacsclient --help | grep "\-\-tty" > /dev/null
if [[ "$?" == "0" ]]; then
# Thats a yes
EMACS_CMD="emacsclient --tty "
else
# Hmmm, opening in another pane would be a pain?
EMACS_CMD="emacs -nw "
fi
else
if [ -e "${HOME}/.emacs_server" -o -e "/tmp/emacs${UID}/server" ]; then
$EDITOR "$@"
return $?
else
echo "start_emacs: starting emacs in background..." 1>&2
$ALTERNATE_EDITOR "$@" &
fi
# For X the focusing of the new frame is problem for emacs, I should see it
EMACS_CMD="emacsclient "
fi
}
else
# If we have no server running lets just call emacs
EMACS_CMD="emacs "
fi

export EDITOR=${EMACS_CMD}
export VISUAL=${EMACS_CMD}
# alternate is always straight emacs incase the server died
export ALTERNATE_EDITOR=emacs

# shortcut
alias ec="${EMACS_CMD}"

# set CFLAGS for debugging - autoconf usually picks it up.
export CFLAGS=-g3
Expand Down

0 comments on commit ecb4e99

Please sign in to comment.