Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

(I'm actually asking this even though I intend to supply the answer, so this is more by way of providing a tip.)

If you create an emacsclient launcher by copying a .desktop file (e.g. the Emacs one), it does not behave in the standard Unity launcher manner. It always launches a new window; it doesn't recognize that existing Emacsclient windows exist to jump to them. How can I make it behave?

As background, this is a very useful usage mode for Emacs, where you run it as a daemon: emacs --daemon, and then you summon an emacs window with emacsclient. A good way to do this for habitual emacs users is to put emacs --daemon into your Startup Applications.

share|improve this question
add comment

3 Answers 3

Solution by james.ferguson works well. What I wanted was to link emacsclient to so some file types as the "preferred application". For this, I found james's script with a new "Exec" line

Exec=/usr/bin/emacsclient --alternate-editor emacs24 --no-wait %F

works better for me: it runs a new emacs if none is running, does not open a new window and does not make emacs complain about clients still waiting for stuff to happen.

Now I can click on files and they are opened in a running emacs, if one exists, otherwise emacs starts.

share|improve this answer
add comment

Another way is to use a script:

if [ "$(pidof emacs)" ] ; then
    emacsclient "$@" &
else
    emacs -mm "$@" &
fi

So you always invoke the same command.

share|improve this answer
add comment

The solution is to create an emacsclient.desktop file including a directive to it the class of the window using the StartupWMClass settings. Without it, Unity can't tell that that window came from Emacsclient. This will create one based on the contents of the Emacs one (/usr/share/applications/emacs23.desktop):

mkdir -p ~/.local/share/applications
cat > !$/emacsclient.desktop <<EOF
[Desktop Entry]
Version=1.0
Name=Emacsclient
GenericName=Text Editor
Comment=View and edit files
MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;
Exec=/usr/bin/emacsclient -c %F
Icon=/usr/share/icons/hicolor/scalable/apps/emacs23.svg
Type=Application
Terminal=false
Categories=Utility;Development;TextEditor;
StartupWMClass=Emacs
EOF

Place the emacsclient in the launcher (e.g. tap Super, type "emacsclient", drag it on), and log out/in.

share|improve this answer
    
In my .bashrc, I define TMPDIR=${HOME}/tmp so temporary files are under my encrypted $HOME. emacs, invoked from the launcher, doesn't see this definition, but emacsclient, invoked from a shell does. emacs (after server-start) opens a socket in /tmp, emacsclient tries to communicate with emacs over a socket in ${HOME}/tmp, and does very poorly. Can I use emacsclient.desktop to pass the right value for TMPDIR? –  waltinator Sep 28 '11 at 19:40
    
I moved my question to a thread of its own, and got answered. See askubuntu.com/questions/64005/launcher-doesnt-respect-tmpdir/… –  waltinator Nov 6 '11 at 23:20
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.