views:

149

answers:

3

Hi,

How do I consistently control window focus after running emacsclient?

Currently, focus depends on if I already have an emacs server running. When emacsclient invokes an alternative editor, focus is shifted to the new emacs window. When emacsclient connects to an existing emacs server, focus is not shifted (ie. it stays on my putty client).

I would like to consistently focus on the emacs window, since I usually go to emacs after opening a file.

Any help would be greatly appreciated!

Notes

Version Info

emacs: 21.4.1
emacsclient: 21.4
client os: Windows XP Service Pack 3
x server: Exceed 11.0.0.0

Relevant section of my .bash_profile

# a wrapper is needed to sandwich multiple command line arguments in bash
# 2>/dev/null hides
#   "emacsclient: can't find socket; have you started the server?"
emacs_wrapper () {
  if [ 0 -eq $# ]
  then
    emacsclient -n -a emacs ~/notes.txt 2>/dev/null &
  else
    emacsclient -n -a emacs $* &
  fi
}
alias x="emacs_wrapper"

Also, at the end of my .emacs I have

(server-start)

My current workaround is a simple autohotkey script, which focuses on my first Exceed window

^+x::
If WinExist("ahk_class EXCEEDW:MWCLIENT0")
    WinActivate
return

As a side note, it seems my redirection to /dev/null confused the syntax-highlighter :(

A: 

Would the "--create-frame" option to emacsclient work for you? You'd get a new frame for each file you opened this way, but at least it would be focused (I think).

thermans
Thanks for the suggestion! However, the problem fixed itself (see my answer on 2010-10-12). As a side-note, I'd be creating a ton of frames if I used this approach.
vlee
A: 

How about:

emacsclient -e  "(select-frame-set-input-focus (selected-frame))"

works for me on emacs 23.1

To unfocus (lower-frame) might be useful.

VitoshKa
Thanks for the suggestion! I tried this fix, which seemed to exhibit the correct behavior. Unfortunately, I can't definitively attribute credit to this fix since the problem no longer exists without this fix.
vlee
A: 

For some unknown reason, the issue fixed itself. Opening files now consistently changes focus to the emacs frame with the corresponding file. I'm honestly unsure what changed the behavior, but I'm happy.

Thanks to everyone for their comments and suggestions!

vlee