This one's been bugging me for a while. On macOS, Emacs automatically focuses (raises) other frames when one is closed.

This has the unfortunate side-effect that I could be moved from one macOS desktop/space to another when closing an Emacs frame.

Finally managed do something about it. Since I install Emacs on macOS via homebrew, a small patch on emacs-plus recipe small patch on emacs-plus recipe did the job.

UPDATE: Pull request merged in d12frosted/emacs-plus.

The patch patch has been merged into d12frosted/homebrew-emacs-plus. To use:

brew tap d12frosted/emacs-plus brew install emacs-plus --without-spacemacs-icon --with-no-frame-refocus

Balance restored.