Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

emacsclient window focus

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 :(

like image 798
vlee Avatar asked Sep 03 '10 14:09

vlee


1 Answers

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.

like image 119
VitoshKa Avatar answered Sep 23 '22 23:09

VitoshKa