[Top][All Lists]

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

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

From: Luis Gerhorst
Subject: Re: Mac: Don't quit Emacs when window is closed
Date: Tue, 19 Jan 2016 19:35:21 +0100

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" 

> On 18.01.2016, at 08:15, Nick Helm <> wrote:
>> I have the problem that I always quit Emacs by mistake when I am done
>> with a task by clicking the button to close the Emacs window. I have a
>> few ideas / questions:
>> - Wouldn't it be a good idea to make Emacs act like most Mac
>> application and not quit the application when the window is closed? Is
>> there some reason why this is not possible?
>> - How can I disable the button to close the window or make it call
>> suspend-frame instead of save-buffers-kill-emacs?
> I wanted to do something similar on my mac-port emacs a while back and
> added this to my init.el:
>   (defun nick-mac-hide-last-frame (orig-fun &rest args)
>      "Check if last visible frame is being closed and hide it instead."
>      (if (and (featurep 'mac)
>               (display-graphic-p nil)
>               (= 1 (length (frame-list)))) (progn 
>         (when (eq (frame-parameter (selected-frame) 'fullscreen) 'fullscreen)
>            (set-frame-parameter (selected-frame) 'fullscreen nil) 
>            (sit-for 1.2))
>         (mac-do-applescript "tell application \"System Events\" \
>            to tell process \"Emacs\" to set visible to false")
>         (sit-for 1.5)
>         (modify-frame-parameters (selected-frame) default-frame-alist)
>         (delete-other-windows)
>         (switch-to-buffer "*scratch*"))
>        (apply orig-fun args)))
>   (defun nick-handle-delete-frame (event)
>      "Hide last visible frame when clicking frame close button."
>      (interactive "e")
>      (let ((frame (posn-window (event-start event))))
>         (delete-frame frame t)))
>   (defun nick-save-buffers-kill-terminal (&optional arg)
>      "Hide last visible frame instead of closing Emacs."
>      (interactive "P")
>      (delete-frame (selected-frame) t))
>   (advice-add 'delete-frame :around #'nick-mac-hide-last-frame)
>   (advice-add 'handle-delete-frame :override #'nick-handle-delete-frame)
>   (advice-add 'save-buffers-kill-terminal :override 
>      #'nick-save-buffers-kill-terminal)
> This uses applescript to hide the last frame instead of closing it. The
> OS takes care of the unhiding when you click on the dock icon, relaunch
> the app, double click a file, etc. Do Emacs > Quit Emacs or `kill-emacs'
> to exit.
> It doesn't leave the emacs menubar visible after a frame is closed, but
> I've not found that to be a problem in practice. 
> If you don't use the mac-port you can probably do the same thing by
> dropping in ns-do-applescript, although I haven't tried it. 
> Nick

reply via email to

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