The Frame Patch

As I mentioned yesterday in my post about the just announced Emacs 27.1-RC2, Álvaro Ramírez left a comment to my post A Shortcut Manager for My Emacs-centric Workstation. In that post, I said that I was using yequake to pop up an Org-mode capture buffer from anywhere in the system. Jack Baty commented that yequake didn’t return to the previous application after yequake was terminated. I’d noticed that too and after a bit of research discovered that this is a macOS problem but that it could be (sort of) fixed by inhibiting Emacs from returning that the last frame when a new frame is deleted.

You can follow the discussion in the comments to the post but the TL;DR is that the fix involves a patch to frame.c. Since Emacs 27.1-RC2 had just been released, I decided to compile it with the patch and try things out. If you’d like to do the same thing, here’s the patch (against the RC2 release).

--- frame.c.orig	2020-08-07 13:54:20.000000000 -0400
+++ frame.c	2020-08-07 13:56:35.000000000 -0400
@@ -2056,15 +2056,6 @@
 		}
 	    }
 	}
-#ifdef NS_IMPL_COCOA
-      else
-	/* Under NS, there is no system mechanism for choosing a new
-	   window to get focus -- it is left to application code.
-	   So the portion of THIS application interfacing with NS
-	   needs to know about it.  We call Fraise_frame, but the
-	   purpose is really to transfer focus.  */
-	Fraise_frame (frame1);
-#endif
 
       do_switch_frame (frame1, 0, 1, Qnil);
       sf = SELECTED_FRAME ();

I said “(sort of) fixed” above because there are still two problems. First, I run Emacs and Safari in full screen mode. When I call yequake from one of them, it comes up in a different desktop. Safari doesn’t return to the Safari desktop. Oddly, with Emacs things work perfectly. The second problem is that even when yequake does return to the proper desktop, the previous application does not receive focus. Again, these problems are because of the way macOS works but the patch does help a lot.

It’s easy to try it out if you compile your own Emacs. If you get your Emacs from Homebrew, you can load the patched version with

brew install emacs-plus@27 --with-no-frame-refocus ...

Ramírez says that it should work with Emacs 26 too. Of course, if you’re not on macOS, you don’t have the problem at all.

This entry was posted in General and tagged . Bookmark the permalink.