I don't see a way to launch the default browser from the Cocoa port  
(executing "open ....html" is NOT the same, as it launches the  
application associated with .html files and not the default browser).

Can we have a function ns-launch-URL-with-default-browser please?

The Carbon patch below illustrates how it's done in Aquamacs.

Many thanks
- D


Index: src/mac.c
===================================================================
RCS file: /sources/emacs/emacs/src/mac.c,v
retrieving revision 1.60
diff -c -r1.60 mac.c
*** src/mac.c   7 May 2006 08:04:22 -0000       1.60
--- src/mac.c   8 May 2006 07:20:25 -0000
***************
*** 4789,4794 ****
--- 4789,4901 ----
       return Qnil;
   }

+ DEFUN ("mac-launch-URL-with-default-browser",  
Fmac_launch_url_with_default_browser,  
Smac_launch_url_with_default_browser, 1, 1, 0,
+        doc: /* Launch the URL with the appropriate handler  
application.
+ file:// URLs are always opened with the system's default browser, i.e.
+ the http:// handler. Return non-nil if the URL has been successfully
+ launched.*/)
+      (URLstring)
+      Lisp_Object URLstring;
+ {
+   check_mac();
+   CHECK_STRING (URLstring);
+   if (NILP (URLstring))
+     {
+       error ("URL is nil.");
+       return Qnil;
+     }
+
+   BLOCK_INPUT;
+   // get default browser
+       
+
+
+   LSLaunchURLSpec spec;
+   OSStatus status;
+
+   if (strncmp("file:/", SDATA(URLstring), 6) == 0)
+     {
+       /* Build URL to find out what the default handler for http is.
+        Without an explicit application reference, the launch function
+        (e.g. LSOpenFromURLSpec or ICLaunchURL) will determine the
+        default file handler for the file, which is not neccessarily the
+        default browser.*/
+       
+       FSRef appRef;  // will be discarded
+       char* urlStr = "http://www.gnu.org/";; // just a test URL
+       CFStringRef inURLCfs = CFStringCreateWithCString(NULL, urlStr,  
+                                                      kCFStringEncodingASCII);
+       CFURLRef inURLRef = CFURLCreateWithString(NULL, inURLCfs, NULL);
+       
+       /* Get application for opening html pages */
+       status = LSGetApplicationForURL(inURLRef, kLSRolesAll, &appRef,
+                                     &spec.appURL);
+       CFRelease(inURLRef);
+       CFRelease(inURLCfs);
+     } else
+     {
+       spec.appURL = NULL; /* use preferred application */
+       status = noErr;
+     }
+   if (status == noErr)
+     {
+       /* Open the file / http with the http handler */
+       CFStringRef targetUrlCfs =
+       CFStringCreateWithCString(NULL, SDATA(URLstring),
+                                 kCFStringEncodingASCII);
+
+       /* CFStringRef targetUrlCfsEscaped =
+       CFURLCreateStringByAddingPercentEscapes(NULL, targetUrlCfs,
+                                               NULL, NULL,
+                                               kCFStringEncodingUTF8);
+         the URL must already be encoded. */
+       CFURLRef targetUrlRef =
+       CFURLCreateWithString(NULL, targetUrlCfs, NULL);
+       
+       if (targetUrlRef)
+       {
+       
+         if ( (spec.itemURLs =
+               CFArrayCreate(NULL, (const void **)&targetUrlRef, 1,
+                             &kCFTypeArrayCallBacks)) == NULL)
+           {
+             return Qnil;
+           }
+         spec.passThruParams = NULL;
+         spec.launchFlags = kLSLaunchDefaults;
+         spec.asyncRefCon = NULL;
+         status = LSOpenFromURLSpec(&spec, NULL);
+               
+         CFRelease(spec.itemURLs);
+         CFRelease(targetUrlRef);
+       }
+       CFRelease(targetUrlCfs);
+       /* CFRelease(targetUrlCfsEscaped); */
+       UNBLOCK_INPUT;
+
+       if (! targetUrlRef)
+       {
+         error ("Could not produce valid URL from string.");
+         return Qnil;
+       }
+       if (status != noErr)
+       {
+         error ("Failed to launch default browser. Error %d", XINT(status));
+         return Qnil;
+       }
+     }
+   else
+     {
+       UNBLOCK_INPUT;
+       error ("Could not determine default browser. Error %d",  
XINT(status));
+       return Qnil;
+     }
+
+
+   return Qt;
+ }
+
+

   #ifdef MAC_OSX

***************
*** 5240,5245 ****
--- 5347,5353 ----
     defsubr (&Smac_code_convert_string);
   #endif

+   defsubr (&Smac_launch_url_with_default_browser);
     defsubr (&Smac_set_file_creator);
     defsubr (&Smac_set_file_type);
     defsubr (&Smac_get_file_creator);
Index: lisp/net/browse-url.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/net/browse-url.el,v
retrieving revision 1.52
diff -c -r1.52 browse-url.el
*** lisp/net/browse-url.el      19 Nov 2005 15:57:19 -0000      1.52
--- lisp/net/browse-url.el      9 Feb 2006 08:34:51 -0000
***************
*** 811,818 ****
       (w32-shell-execute "open" url)))

   (defun browse-url-default-macosx-browser (url &optional new-window)
     (interactive (browse-url-interactive-arg "URL: "))
!   (start-process (concat "open " url) nil "open" url))

   ;; --- Netscape ---

--- 811,825 ----
       (w32-shell-execute "open" url)))

   (defun browse-url-default-macosx-browser (url &optional new-window)
+ "Launch the default browser specified in Mac OS X.
+ NEW-WINDOW is ignored."
     (interactive (browse-url-interactive-arg "URL: "))
!   (condition-case nil
!       (mac-launch-URL-with-default-browser url)
!     (error
!      ;; fallback - sometimes http is not registered in the
!      ;; LaunchServices database
!      (start-process (concat "open " url) nil "open" url))))

   ;; --- Netscape ---



-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Emacs-app-dev- mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emacs-app-dev-

Reply via email to