1

I typically start GUI Emacs on macOS, https://bitbucket.org/mituharu/emacs-mac/overview, installed via Nix package manager, as part of a larger startup script on the terminal (iterm). While Emacs is loading I am entering passwords to decrypt various encfs volumes. Annoyingly, Emacs steals focus after a while, sometimes in the middle of entering a password on the terminal. I am aware of about when in the startup sequence this happens so I can simply wait for it to complete then switch focus back to terminal, but naturally I prefer to avoid this.

I've searched for all occurrances of raise-frame, select-frame-set-input-focus, x-focus-frame, select-frame and while there are many instances of these they are not at top-level. To some of these few containing functions that I wondered may be getting called during init, I added message printf style statements, restarted Emacs and read the *Messages* buffer, none of these were printed out. I might have missed something though as I didn't try them all this way, just the most likely looking ones.

It may be a feature of the Emacs I use and I may have to patch to overcome, but I don't want to have to do that.

Any clues what I should look for to change this behavior?

  • 1
    You are on the right track. select-frame-set-input-focus and other functions that may exist along those lines are what causes Emacs to acquire focus on OSX 10.6.8. I have no experience with higher versions of OSX or MacOS, but assume they may be the same. At all locations in the Lisp functions that I use daily, I have changed select-frame-set-input-foucs to select-frame and raise-frame. The most common annoyance for me was sending and receiving email with Wanderlust -- I generally like to use other applications at that time. I have not traced the startup without any user-config... – lawlist Dec 5 '19 at 18:32
  • @lawlist, thanks. Your comment about tracing startup without config was good as I had forgotten to try that. I did so and it confirmed that it is hardwired into the Emacs I use unfortunately. – Joe Dec 5 '19 at 18:49
  • 1
    startup.el is baked into the Emacs executable during the build process. I use a custom version of startup.el, primarily because the stock version messed too much with how windows / buffers are displayed when Emacs starts. If you build your own Emacs from source and are sufficiently motivated, then you may wish to have a look at the existing startup.el and see if certain custom modifications have the desired effect. .... The offending code may be elsewhere (i.e., I use the vanilla Emacs for OSX/MacOS, not Mituharu's port), but startup.el may be a good place to start looking. – lawlist Dec 5 '19 at 18:59
  • @lawlist, good tip, thanks – Joe Dec 5 '19 at 19:08

Your Answer

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

Browse other questions tagged or ask your own question.