Commit 08e3161a authored by Jan Djärv's avatar Jan Djärv
Browse files

Fix that executing applescript may hang emacs uninterruptedly.

* nsfns.m (as_script, as_result, as_status): New static variables.
(ns_run_ascript): New function.
(Fns_do_applescript): Set variables as_*. Make an NSApplicationDefined
event with data2 set to NSAPP_DATA2_RUNASSCRIPT, post it and then start
the event loop.  Get status from as_status.

* nsterm.h (ns_run_ascript): Declare.
(NSAPP_DATA2_RUNASSCRIPT): Define.

* nsterm.m (sendEvent): If event is NSApplicationDefined and
data2 is NSAPP_DATA2_RUNASSCRIPT, call ns_run_ascript and then exit
the event loop (Bug#7276).
parent 7417b37c
2011-08-14 Jan Djärv <jan.h.d@swipnet.se>
* nsterm.h (ns_run_ascript): Declare.
(NSAPP_DATA2_RUNASSCRIPT): Define.
* nsfns.m (as_script, as_result, as_status): New static variables.
(ns_run_ascript): New function.
(Fns_do_applescript): Set variables as_*. Make an NSApplicationDefined
event with data2 set to NSAPP_DATA2_RUNASSCRIPT, post it and then start
the event loop. Get status from as_status (Bug#7276).
* nsterm.m (sendEvent): If event is NSApplicationDefined and
data2 is NSAPP_DATA2_RUNASSCRIPT, call ns_run_ascript and then exit
the event loop (Bug#7276).
2011-08-14 Andreas Schwab <schwab@linux-m68k.org>
* gnutls.c (QCgnutls_bootprop_priority)
......
......@@ -97,6 +97,9 @@ Updated by Christian Limpach (chris@nice.ch)
extern BOOL ns_in_resize;
/* Static variables to handle applescript execution. */
static Lisp_Object as_script, *as_result;
static int as_status;
/* ==========================================================================
......@@ -2052,6 +2055,15 @@ and GNUstep implementations ("distributor-specific release
return 0;
}
/* Helper function called from sendEvent to run applescript
from within the main event loop. */
void
ns_run_ascript (void)
{
as_status = ns_do_applescript (as_script, as_result);
}
DEFUN ("ns-do-applescript", Fns_do_applescript, Sns_do_applescript, 1, 1, 0,
doc: /* Execute AppleScript SCRIPT and return the result.
If compilation and execution are successful, the resulting script value
......@@ -2061,12 +2073,37 @@ and GNUstep implementations ("distributor-specific release
{
Lisp_Object result;
int status;
NSEvent *nxev;
CHECK_STRING (script);
check_ns ();
BLOCK_INPUT;
status = ns_do_applescript (script, &result);
as_script = script;
as_result = &result;
/* executing apple script requires the event loop to run, otherwise
errors aren't returned and executeAndReturnError hangs forever.
Post an event that runs applescript and then start the event loop.
The event loop is exited when the script is done. */
nxev = [NSEvent otherEventWithType: NSApplicationDefined
location: NSMakePoint (0, 0)
modifierFlags: 0
timestamp: 0
windowNumber: [[NSApp mainWindow] windowNumber]
context: [NSApp context]
subtype: 0
data1: 0
data2: NSAPP_DATA2_RUNASSCRIPT];
[NSApp postEvent: nxev atStart: NO];
[NSApp run];
status = as_status;
as_status = 0;
as_script = Qnil;
as_result = 0;
UNBLOCK_INPUT;
if (status == 0)
return result;
......@@ -2670,4 +2707,7 @@ - (NSString *)panel: (id)sender userEnteredFilename: (NSString *)filename
/* used only in fontset.c */
check_window_system_func = check_ns;
as_status = 0;
as_script = Qnil;
as_result = 0;
}
......@@ -795,6 +795,9 @@ extern void x_set_tool_bar_lines (struct frame *f,
extern void x_activate_menubar (struct frame *);
extern void free_frame_menubar (struct frame *);
#define NSAPP_DATA2_RUNASSCRIPT 10
extern void ns_run_ascript (void);
extern void ns_init_paths (void);
extern void syms_of_nsterm (void);
extern void syms_of_nsfns (void);
......
......@@ -4257,6 +4257,16 @@ - (void)sendEvent: (NSEvent *)theEvent
/* NSTRACE (sendEvent); */
/*fprintf (stderr, "received event of type %d\t%d\n", type);*/
#ifdef NS_IMPL_COCOA
if (type == NSApplicationDefined
&& [theEvent data2] == NSAPP_DATA2_RUNASSCRIPT)
{
ns_run_ascript ();
[self stop: self];
return;
}
#endif
if (type == NSCursorUpdate && window == nil)
{
fprintf (stderr, "Dropping external cursor update event.\n");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment