help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Mac: Don't quit Emacs when window is closed


From: Nick Helm
Subject: Re: Mac: Don't quit Emacs when window is closed
Date: Wed, 20 Jan 2016 11:04:30 +1300
User-agent: mu4e 0.9.15; emacs 24.5.1

> Thanks! I tried it but it gives me some error in GNU Emacs. For the
> beginning I instead added this code wich make C-z no longer painful on
> OS X:
>
> (when (eq system-type 'darwin)
>   (global-set-key [remap suspend-frame] 'ns-do-hide-emacs))
>
> Without it the Emacs window minimizes slowly into the dock on my iMac
> 27" Retina.

On OSX emacs, `suspend-frame' is the equivalent of clicking the yellow
minimise button on the window decoration. This is normally on C-z. You
could try using s-h (super-h) instead, which is pre-mapped to
`ns-do-hide-emacs' and should give you a quick hide key if that's what
you need.

Sorry about the error on GNU/Emacs. Try replacing the first function
with this instead:

   (defun nh-mac-hide-last-frame (orig-fun &rest args)
      "Check if last visible frame is being closed and hide it instead."
      (if (and (featurep 'ns)
               (display-graphic-p nil)
               (= 1 (length (frame-list)))) (progn 
         (when (eq (frame-parameter (selected-frame) 'fullscreen) 'fullboth)
            (set-frame-parameter (selected-frame) 'fullscreen nil) 
            (sit-for 1.2))
         (ns-hide-emacs t)
         (sit-for 1.5)
         (modify-frame-parameters (selected-frame) default-frame-alist)
         (delete-other-windows)
         (switch-to-buffer "*scratch*"))
        (apply orig-fun args)))

This just replaces the mac-* functions with ns-* equivalents. Having
access to `ns-hide-emacs' and `ns-do-hide-emacs' is much nicer than
messing about with applescript imho.

One more thing, if you'd like the frame reset to work (so the unhidden
frame has the same position and size properties as a new frame), make
sure you have default-frame-alist defined in your init.el. Even better is
to set the frame parameters in ~/Library/Preferences/org.gnu.emacs.plist
to avoid that annoying flicker as the frame resizes during startup. 

Nick



reply via email to

[Prev in Thread] Current Thread [Next in Thread]