3

In case it's relevant, I'm on a Mac, running OSX 10.12 and Carbon Emacs 24.3.1.

If I open a file using /Applications/Emacs.app/Contents/MacOS/bin/emacsclient -n filepath the Emacs window comes to the top and gets focus unless opening the file triggers a minibuffer prompt (such as Symbolic link to Hg-controlled source file; follow link? (yes or no).

Is there a way to configure Emacs to grab focus and raise its window in these cases as well?

3

Assuming that are you using the GUI frame, basically you just need pass -e '(x-focus-frame nil)' as argument of emacsclient.

In that case: emacsclient -n -e '(x-focus-frame nil)' filepath

EDIT by OP: (You may need to use: emacsclient -n -e "(progn (x-focus-frame nil) (find-file \"filepath\"))" —— See documentation for emacsclient's -e parameter.)

I wrote a similar script to accomplish that here and another stuff for personal reasons. Mainly to avoid pain about opening multiple frames running on daemon mode like:

  • handling daemon crashing (and restarting for my init system [OpenRC])
  • be sure that when a frame exists, opening the file on it instead creating a new one
  • if a current frame was used, ensure that raises that frame and focus it.

The script is in some way portable and you can try to use it in the last case.

| improve this answer | |
  • This got me there with a couple of changes: (raise-frame) did not work, but (x-focus-frame nil) did; and (empirically and from emacsclient --help) I can't use plain filepath to open a file if I also use -e. What worked for me: emacsclient -n -e "(progn (x-focus-frame nil) (find-file \"$1\"))" – Joshua Goldberg Nov 3 '17 at 14:36
  • Probably is different because you are running on Mac Os X? Works fine for me (raise-frame), I'm editing the answer. – Manoel Vilela Nov 3 '17 at 21:21
  • About the filepath stuff, try executing in the way that I edited the answer, works fine here: keep the filepath on the last argument. – Manoel Vilela Nov 3 '17 at 21:32
  • 1
    Wr.t. raise-frame -vs- focus-frame: they're both needed in general (the effect of either of them is dependent on the window system/manager in use). – Stefan Nov 8 '17 at 18:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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