emacsclient window focus
Asked Answered
T

3

14

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

Tonnie answered 3/9, 2010 at 14:25 Comment(3)
This may not help you, but focus seems to shift to the existing emacs window when using 23.2.2 and Ubuntu.Anthropography
I suspect it is being complicated by the use of your X-server on windows. Have you considered using emacs for windows? 23.2 is available precompiled: ftp.gnu.org/gnu/emacs/windowsSateen
I actually have emacsw32 installed. However, it's agonizingly slow working through CIFS shares :(Tonnie
T
-3

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!

Tonnie answered 12/10, 2010 at 16:3 Comment(0)
H
10

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.

Harriette answered 11/10, 2010 at 8:13 Comment(1)
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.Tonnie
M
-1

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).

Mathura answered 7/10, 2010 at 15:42 Comment(1)
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.Tonnie
T
-3

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!

Tonnie answered 12/10, 2010 at 16:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.