When I start emacsclient from command line as below:

emacsclient -a '' -c "$@"

It always starts in the background (terminal window on top of emacsclient window), so I have to use mouse to click the window to switch to emacsclient.

It's really frustrating, can I get emacsclient to focus the frame that pops up when invoked from command line?

enter image description here

  • This is probably more a function of the window manager/desktop environment, than of emacs/emacsclient. In my case, the new frame pops up on top of the terminal window, e.g. (Gnome 3.20 on Fedora 24). – NickD Aug 7 '17 at 21:52

You might be able to use the server-switch-hook and raise the frame. Something like:

(add-hook 'server-switch-hook #'raise-frame)

If that leaves you without focus on the new frame you might try something like this instead:

(add-hook 'server-switch-hook (lambda () (select-frame-set-input-focus (selected-frame))))

If you are looking to have a shell command to bring up an Emacs frame (without specifying one or more files to edit), you can also do this from the command line:

emacsclient -e "(raise-frame)"
  • It doesn't work. but it sounds like if add a filename at the command line, emacs will popup to foreground but without file to open, it will stay at background. – lucky1928 Aug 8 '17 at 19:43
  • If you don't need to pass file name arguments you can also call a function from the command line, e.g.: emacsclient -e '(raise-frame)' – glucas Aug 8 '17 at 19:45
  • 1
    Your (select-frame-set-input-focus (selected-frame)) advice worked for me. – Tim Stewart May 25 '18 at 16:23

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.