From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Luis Gerhorst Newsgroups: gmane.emacs.help Subject: Re: Mac: Don't quit Emacs when window is closed Date: Tue, 19 Jan 2016 19:35:21 +0100 Message-ID: <5870E7A7-DF82-484A-95BB-985DF8F419AF@luisgerhorst.de> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 (Mac OS X Mail 9.2 \(3112\)) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1453228555 25517 80.91.229.3 (19 Jan 2016 18:35:55 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 19 Jan 2016 18:35:55 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Nick Helm Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Jan 19 19:35:45 2016 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aLb7z-0005Yt-5s for geh-help-gnu-emacs@m.gmane.org; Tue, 19 Jan 2016 19:35:39 +0100 Original-Received: from localhost ([::1]:38776 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLb7y-0003lN-JY for geh-help-gnu-emacs@m.gmane.org; Tue, 19 Jan 2016 13:35:38 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59394) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLb7n-0003jL-4W for help-gnu-emacs@gnu.org; Tue, 19 Jan 2016 13:35:28 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aLb7j-0007eN-Ux for help-gnu-emacs@gnu.org; Tue, 19 Jan 2016 13:35:27 -0500 Original-Received: from out1-smtp.messagingengine.com ([66.111.4.25]:39759) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLb7j-0007eH-RO for help-gnu-emacs@gnu.org; Tue, 19 Jan 2016 13:35:23 -0500 Original-Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id B097A20840 for ; Tue, 19 Jan 2016 13:35:23 -0500 (EST) Original-Received: from frontend1 ([10.202.2.160]) by compute5.internal (MEProxy); Tue, 19 Jan 2016 13:35:23 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=luisgerhorst.de; h=cc:content-transfer-encoding:content-type:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-sasl-enc:x-sasl-enc; s=mesmtp; bh=NBrhGur07gc+qKmnjKfYsGj5ZR8 =; b=sfxu/VGH+BJo3+DfXdfOkKIrxEZh44lMwc60E0ZM5NZTjRStNl4qSkONgWS B4Re3ucvC5Fa0SvgSCYoBu16/RDQcQSysYf5FhUCUJapq+PF+vlam50NgADcIJg1 ELYRL8fSPDpmeX0AVgYHn3q9Dm2oh2aXpRR/9q7Ezr1Wla3g= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=NBrhGur07gc+qKm njKfYsGj5ZR8=; b=oKZ3EKjN5OrBM7ep0Z3cTqY97V2wrw5eFGDFO0SxGjKLOsq LBRr6lchCOARUHfiR9nSi5bqINNC7uCM5F3CdFpcHdwc/l0DTz66uDmXXeb4I9wh 1AgOI2JxQJjAADGF4j/VqGv7ilal1KyFLhYMUpI3YIfBEFbUFNpgUv8s3Oqg= X-Sasl-enc: xkpDpNbbhmtzhlOHH8HXPFjpDxHh7NnsPxuHoVSTJ9fc 1453228523 Original-Received: from [192.168.178.44] (hsi-kbw-046-005-177-168.hsi8.kabel-badenwuerttemberg.de [46.5.177.168]) by mail.messagingengine.com (Postfix) with ESMTPA id 29903C01712; Tue, 19 Jan 2016 13:35:23 -0500 (EST) In-Reply-To: X-Mailer: Apple Mail (2.3112) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.25 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:108790 Archived-At: 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 18.01.2016, at 08:15, Nick Helm wrote: >=20 >=20 >> 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: >>=20 >> - 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? >=20 > I wanted to do something similar on my mac-port emacs a while back and > added this to my init.el: >=20 > (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) > (=3D 1 (length (frame-list)))) (progn=20 > (when (eq (frame-parameter (selected-frame) 'fullscreen) = 'fullscreen) > (set-frame-parameter (selected-frame) 'fullscreen nil)=20 > (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))) >=20 > (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))) >=20 > (defun nick-save-buffers-kill-terminal (&optional arg) > "Hide last visible frame instead of closing Emacs." > (interactive "P") > (delete-frame (selected-frame) t)) >=20 > (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=20 > #'nick-save-buffers-kill-terminal) >=20 > 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. >=20 > 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.=20 >=20 > 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.=20 >=20 > Nick >=20