2

I am trying to run emacsclient with alternate-editor of emacs --eval "(setq server-name '\"server1\")". I am not having any luck.

This is what I have tried:

lispExp="(setq server-name '\"server1\")"
emacsclient -c  --alternate-editor="emacs --eval $lispExp"

So how do I define an alternate editor with arguments, for emacsclient.

Background: I am trying to make a bash command (edit) that when I use it to edit a file, it will connect to a local emacs server, or create a new one. With a different server for each virtual desktop. If I can get the above to work then I can substitute server1 for the appropriate server name.

My original alias (for one server) is defined here:

alias edit='emacsclient --alternate-editor="" --no-wait $*'
ctrl-alt-delor
  • 7,506
  • 5
  • 40
  • 52

1 Answers1

2

I did a work around:

emacsclient -s "${server}" $*
if test  "z$PIPESTATUS" != "z0"
then
    lispExp="(setq server-name '\"${server}\")"
    emacs --daemon --eval "$lispExp"
    emacsclient  -s "${server}" $*
fi

The full code to my problem of — run a different emacs server for each virtual desktop in KDE (and probably Gnome) — is here:

unalias edit #this line only needed if you have an alias, you could just remove the alias.
function edit {
    #this method gives a differant emacs server to each X11 virtual desktop
    desktop=$(xprop -id $WINDOWID | sed -rn -e  's/_NET_WM_DESKTOP\(CARDINAL\) = ([^)]+)/\1/pg')
    if test "z${desktop}" != "z"
    then
        server="desktop${desktop}"
    else
        server="server" #use this server if can't find virtual desktop
    fi

    emacsclient -s "${server}" $*
    if test  "z$PIPESTATUS" != "z0"
    then
        lispExp="(setq server-name '\"${server}\")"
        emacs --daemon --eval "$lispExp"
        emacsclient  -s "${server}" $*
    fi
}
ctrl-alt-delor
  • 7,506
  • 5
  • 40
  • 52