--- event-carbon.c~ 2005-10-29 09:11:47.000000000 -0600 +++ event-carbon.c 2006-02-01 23:53:51.000000000 -0700 @@ -204,6 +204,14 @@ return errAEEventNotHandled; } +static OSErr +quit_application_ae_handler (const AppleEvent * UNUSED (apple_event), AppleEvent * UNUSED (reply), SInt32 UNUSED (ref_con)) +{ + call0 (Qsave_buffers_kill_emacs); + + return noErr; +} + static void install_apple_event_handlers (void) { @@ -213,6 +221,13 @@ invalid_operation ("Cannot install open documents Apple event handler", Qnil); DisposeAEEventHandlerUPP (od_handler); + + AEEventHandlerUPP qa_handler = NewAEEventHandlerUPP (quit_application_ae_handler); + + if (AEInstallEventHandler (kCoreEventClass, kAEQuitApplication, qa_handler, 0L, false) != noErr) + invalid_operation ("Cannot install quit application Apple event handler", Qnil); + + DisposeAEEventHandlerUPP (qa_handler); } /* Used in frame-carbon.c. */