opening emacsclient windows on the current desktop

Using emacsclient deserves its own entry, but let's assume you've already set that up. Basically, you'll put (server-start) in your .emacs, and emacs will run in server mode, which means you can open files in an existing emacs by using the 'emacsclient' command.

One small annoyance with this is that when using virtual desktop / workspaces, running emacsclient will open the file on a different virtual desktop. As with just about anything, there are some tricks to move your existing emacs to the current desktop; add the following to your .emacs:

;; move to current desktop 
(add-hook 'server-switch-hook
(lambda ()
(call-process
"wmctrl" nil nil nil "-i" "-R"
(frame-parameter (or frame (selected-frame)) 'outer-window-id))))

This works when using X (GNOME, KDE,...), and requires the wmctrl program. An alternative solution is to use a new window ('frame', remember emacs terminology) with the new buffer. I am not using that, because I prefer to use one single window. However, if you prefer to use seperate windows for each buffer opened with emacsclient, you can use this trick (courtesy of EmacsWiki) instead:
;; open a new frame
(add-hook 'server-switch-hook
(lambda nil
(let ((server-buf (current-buffer)))
(bury-buffer)
(switch-to-buffer-other-frame server-buf))))

Overall, emacsclient is a nice tool; as with many things about emacs, it does take a bit of work to make it work they way you want.

No comments:

Post a Comment

Followers

Popular Posts