[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bug in Carbon port: browse-url-default-macosx-browser
From: |
David Reitter |
Subject: |
Re: Bug in Carbon port: browse-url-default-macosx-browser |
Date: |
Fri, 25 Nov 2005 21:29:49 +0000 |
On 25 Nov 2005, at 08:20, Lennart Borgman wrote:
David Reitter wrote:
On 24 Nov 2005, at 23:44, Lennart Borgman wrote:
I think the implementation in Emacs for w32 is of the same type.
I actually think it is quite practical most of the time. This
way Emacs behaves as I expect it to on w32. Firefox installed
itself so that it took care of this. It would not have been
possible if Emacs explicitly specified the web browser. But
maybe things works differently on Mac?
Maybe the doc string should be changed? Perhaps something like:
Asked OS to give url to associated application (normally a
web browser)
I think the defined functionality is just the right thing. On OS
X, there is a system-wide browser default, which may or may not
coincide with the association for .html files. The browser
default is what should be respected.
Thanks, I see. I do not think you can divide between those two
things on w32 (but I am not absolutely sure about that). Your
explanation makes it much more easy for me to understand what you
want.
Is there then a way for Emacs to use the system-wide browser default?
After some research I put together the following patch. It finds the
appropriate default browser and runs it. Does the job for me.
*** lisp/net/browse-url.el 25 Oct 2005 13:18:52 -0000 1.51
--- lisp/net/browse-url.el 25 Nov 2005 21:07:14 -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,820 ----
(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: "))
! (mac-launch-URL-with-default-browser url))
;; --- Netscape ---
*** src/mac.c Fri Nov 25 20:45:05 2005
--- src/mac.c Fri Nov 25 21:06:10 2005
***************
*** 4247,4252 ****
--- 4247,4332 ----
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 system's default browser.
+ 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
+
+ FSRef appRef; // will be discarded
+ LSLaunchURLSpec spec;
+ OSStatus status;
+
+ /* 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.*/
+
+ 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, kLSRolesEditor, &appRef,
+ &spec.appURL);
+ CFRelease(inURLRef);
+ CFRelease(inURLCfs);
+
+ if (status == noErr)
+ {
+ /* Open the file / http with the http handler */
+ CFStringRef targetUrlCfs =
+ CFStringCreateWithCString(NULL, SDATA(URLstring),
+ kCFStringEncodingASCII);
+ CFURLRef targetUrlRef = CFURLCreateWithString(NULL,
targetUrlCfs, NULL);
+
+ 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);
+ UNBLOCK_INPUT;
+
+ if (status != noErr)
+ {
+ error("Failed to launch default browser.");
+ return Qnil;
+ }
+ }
+ else
+ {
+ UNBLOCK_INPUT;
+ error("Could not determine default browser.");
+ return Qnil;
+ }
+
+
+ return Qt;
+ }
+
+
#ifdef MAC_OSX
#undef select
***************
*** 4692,4698 ****
defsubr (&Smac_code_convert_string);
#endif
defsubr (&Smac_clear_font_name_table);
!
defsubr (&Smac_set_file_creator);
defsubr (&Smac_set_file_type);
defsubr (&Smac_get_file_creator);
--- 4772,4779 ----
defsubr (&Smac_code_convert_string);
#endif
defsubr (&Smac_clear_font_name_table);
!
! defsubr (&Smac_launch_url_with_default_browser);
defsubr (&Smac_set_file_creator);
defsubr (&Smac_set_file_type);
defsubr (&Smac_get_file_creator);
- Bug in Carbon port: browse-url-default-macosx-browser, David Reitter, 2005/11/23
- Re: Bug in Carbon port: browse-url-default-macosx-browser, Stefan Monnier, 2005/11/24
- Re: Bug in Carbon port: browse-url-default-macosx-browser, David Reitter, 2005/11/24
- Re: Bug in Carbon port: browse-url-default-macosx-browser, Stefan Monnier, 2005/11/24
- Re: Bug in Carbon port: browse-url-default-macosx-browser, David Reitter, 2005/11/24
- Re: Bug in Carbon port: browse-url-default-macosx-browser, Randal L. Schwartz, 2005/11/24
- Re: Bug in Carbon port: browse-url-default-macosx-browser, David Reitter, 2005/11/24
- Re: Bug in Carbon port: browse-url-default-macosx-browser, Lennart Borgman, 2005/11/24
- Re: Bug in Carbon port: browse-url-default-macosx-browser, David Reitter, 2005/11/25
- Re: Bug in Carbon port: browse-url-default-macosx-browser, Lennart Borgman, 2005/11/25
- Re: Bug in Carbon port: browse-url-default-macosx-browser,
David Reitter <=
- Re: Bug in Carbon port: browse-url-default-macosx-browser, YAMAMOTO Mitsuharu, 2005/11/27
- Re: Bug in Carbon port: browse-url-default-macosx-browser, David Reitter, 2005/11/28
- Re: Bug in Carbon port: browse-url-default-macosx-browser, YAMAMOTO Mitsuharu, 2005/11/28