Subject: bug#23483: 24.5; cygwin emacs w32 doesn not ask to save files when windows shuts down

From: Ken Brown <[email-masked]>
Date: Tue, 10 May 2016 11:16:44 -0400

On 5/8/2016 2:40 PM, Eli Zaretskii wrote:
>> From: "Strozzi, David J." <[email-masked]>
>> Date: Sun, 8 May 2016 13:33:11 +0000
>>
>> I am running the Windows 32 native emacs build that is part of cygwin.
>> Running on Windows 7. When I shut down windows (from the Start Menu),
>> emacs does not ask to save edited files. That means I lose work unless
>> I remember to separately quit emancs manually before shutting down.
>> Not a big deal, but can it be fixed?
> 
> If someone submits patches that listen to system shutdown messages,
> and auto-save files when they arrive, this can be fixed.  Patches
> welcome.

I asked about this on the Cygwin list (https://www.cygwin.com/ml/cygwin/2016-05/msg00085.html).  Based on the response I got, I tried the following, which seems to work:

diff --git a/src/w32fns.c b/src/w32fns.c
index ede8f6b..705b978 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -4795,6 +4795,9 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
       my_post_msg (&wmsg, hwnd, msg, wParam, lParam);
       return 0;

+    case WM_ENDSESSION:
+      terminate_due_to_signal (SIGTERM, 0);
+
     case WM_WINDOWPOSCHANGING:
       /* Don't restrict the sizing of any kind of frames.  If the window
         manager doesn't, there's no reason to do it ourselves.  */

Ken