Re: [Emacs.app dev]: An issue related to emacsclient

2008-07-22 Thread Carsten Bormann
On Jul 22 2008, at 03:56, Adrian Robert wrote:

 Curious though, how slow really is the exec osascript approach?  The
 patch is a lot of code to replace the 3-line lisp that Carsten
 posted.  (Though I think it's nicer to have it internal.)

In my typical use (getting text strings out of apps) my hack is rather  
slow (perceived delay 1 sec or so).
I mainly wrote it so I don't have to unlearn muscle memory I built up  
with Carbon Emacs.
The actual delay depends a lot on how efficient the copy-on-write  
forking is (and it appears Darwin does not win a medal here).

Also my code is a real hack when it comes to returning the value  
yielded by the script.

 Please use #ifdef NS_IMPL_COCOA (as it's possible to run GNUstep on OS
 X) around the C function, but leave the lisp function defined and
 return an error and/or a message on non NS_IMPL_COCOA.

Hmm. Please only define (fbind) the symbol when it's actually  
implemented; otherwise the fboundp style hacks don't work any more.

Gruesse, Carsten


-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/
___
Emacs-app-dev- mailing list
Emacs-app-dev-@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emacs-app-dev-


Re: [Emacs.app dev]: An issue related to emacsclient

2008-07-21 Thread David Reitter

Adrian,

On 21 Jul 2008, at 16:44, Gilbert Harman wrote:


A followup.  Carbon Emacs has a command do-applescript that I was
using to get the focus back to the email program alpine.




the patch below works for me.
Any comments? Otherwise I'll check this in.

- David




*** nsfns.m 19 Jul 2008 15:03:37 -0400  1.7
--- nsfns.m 21 Jul 2008 18:11:27 -0400  
***
*** 2192,2197 
--- 2192,2282 
  
= 
= 
= 
= 
==  
*/



+
+ /* Compile and execute the AppleScript SCRIPT and return the error
+status as function value.  A zero is returned if compilation and
+execution is successful, in which case *RESULT is set to a Lisp
+string or a number containing the resulting script value.   
Otherwise,

+1 is returned. */
+
+ static int
+ do_applescript (script, result)
+  Lisp_Object script, *result;
+ {
+   NSAppleEventDescriptor *desc;
+   NSDictionary* errorDict;
+   NSAppleEventDescriptor* returnDescriptor = NULL;
+
+   NSAppleScript* scriptObject =
+ [[NSAppleScript alloc] initWithSource:
+[NSString stringWithUTF8String: SDATA (script)]];
+
+   returnDescriptor = [scriptObject executeAndReturnError: errorDict];
+   [scriptObject release];
+
+   *result = Qnil;
+
+   if (returnDescriptor != NULL)
+ {
+   // successful execution
+   if (kAENullEvent != [returnDescriptor descriptorType])
+ {
+ *result = Qt;
+ // script returned an AppleScript result
+ if ((typeUnicodeText == [returnDescriptor descriptorType]) ||
+ (typeUTF16ExternalRepresentation
+  == [returnDescriptor descriptorType]) ||
+ (typeUTF8Text == [returnDescriptor descriptorType]) ||
+ (typeCString == [returnDescriptor descriptorType]))
+   {
+ desc = [returnDescriptor coerceToDescriptorType: typeUTF8Text];
+ if (desc)
+   *result = build_string([[desc stringValue] UTF8String]);
+   }
+ else
+ {
+ /* use typeUTF16ExternalRepresentation? */
+ // coerce the result to the appropriate ObjC type
+ desc = [returnDescriptor coerceToDescriptorType: typeUTF8Text];
+ if (desc)
+   *result = make_number([desc int32Value]);
+ }
+ }
+ }
+   else
+ {
+   // no script result, return error
+   return 1;
+ }
+   return 0;
+ }
+
+ DEFUN (do-applescript, Fdo_applescript, Sdo_applescript, 1, 1, 0,
+doc: /* Execute AppleScript SCRIPT and return the result.  If
+ compilation and execution are successful, the resulting script value
+ is returned as a string, a number or, in the case of other constructs,
+ t.  In case the execution fails, an error is signaled. */)
+ (script)
+ Lisp_Object script;
+ {
+   Lisp_Object result;
+   long status;
+
+   CHECK_STRING (script);
+   check_ns ();
+
+   BLOCK_INPUT;
+   status = do_applescript (script, result);
+   UNBLOCK_INPUT;
+   if (status == 0)
+ return result;
+   else if (!STRINGP (result))
+ error (AppleScript error %d, status);
+   else
+ error (%s, SDATA (result));
+ }
+
+
  DEFUN (xw-color-defined-p, Fns_color_defined_p,  
Sns_color_defined_p, 1, 2, 0,
 Return t if the current NS display supports the color named  
COLOR.\n\

  The optional argument FRAME is currently ignored.)
***
*** 2550,2555 
--- 2635,2641 
defsubr (Sns_list_fonts);
defsubr (Sns_font_name);
defsubr (Sns_list_colors);
+   defsubr (Sdo_applescript);
defsubr (Sns_color_defined_p);
defsubr (Sns_color_values);
defsubr (Sns_server_max_request_size);



smime.p7s
Description: S/MIME cryptographic signature
-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/___
Emacs-app-dev- mailing list
Emacs-app-dev-@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emacs-app-dev-


Re: [Emacs.app dev]: An issue related to emacsclient

2008-07-21 Thread David Reitter

On 21 Jul 2008, at 18:14, David Reitter wrote:



the patch below works for me.
Any comments? Otherwise I'll check this in.


Incidentally, do we need #if MAC_OSX around this?
NSAppleScript is probably not a NextStep API, is it?

- D

smime.p7s
Description: S/MIME cryptographic signature
-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/___
Emacs-app-dev- mailing list
Emacs-app-dev-@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emacs-app-dev-


Re: [Emacs.app dev]: An issue related to emacsclient

2008-07-21 Thread Adrian Robert
 ...
 +   // script returned an AppleScript result
 +   if ((typeUnicodeText == [returnDescriptor descriptorType]) ||
 +   (typeUTF16ExternalRepresentation
 +== [returnDescriptor descriptorType]) ||
 +   (typeUTF8Text == [returnDescriptor descriptorType]) ||
 +   (typeCString == [returnDescriptor descriptorType]))
 + {
 +   desc = [returnDescriptor coerceToDescriptorType:  
 typeUTF8Text];
 +   if (desc)
 + *result = build_string([[desc stringValue] UTF8String]);
 + }
 +   else
 + {
 +   /* use typeUTF16ExternalRepresentation? */

I don't entirely understand this part.   
typeUTF16ExternalRepresentation is above.  What is else covering  
here?  Also, since we're always coercing to typeUTF8Text, why not do  
it before the if?


-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/
___
Emacs-app-dev- mailing list
Emacs-app-dev-@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emacs-app-dev-


Re: [Emacs.app dev]: An issue related to emacsclient

2008-07-21 Thread David Reitter

On 21 Jul 2008, at 21:56, Adrian Robert wrote:


Looks good -- Cocoa even!  ;)


OK, checked in with NS_IMPL_COCOA.

Curious though, how slow really is the exec osascript approach?  The  
patch is a lot of code to replace the 3-line lisp that Carsten  
posted.  (Though I think it's nicer to have it internal.)


One wouldn't want to run time-critical stuff via AppleScript anyways.
The trick via a temporary file is quite the hack...

smime.p7s
Description: S/MIME cryptographic signature
-
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK  win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100url=/___
Emacs-app-dev- mailing list
Emacs-app-dev-@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emacs-app-dev-