From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Reitter Newsgroups: gmane.emacs.devel Subject: Re: Bug in Carbon port: browse-url-default-macosx-browser Date: Fri, 25 Nov 2005 21:29:49 +0000 Message-ID: References: <502E6611-3B38-4C39-9469-4E4902EE0586@gmail.com> <87u0e29d0v.fsf-monnier+emacs@gnu.org> <87d5kpahk2.fsf-monnier+emacs@gnu.org> <64A46339-4AAF-4394-9ED9-E9E25E8CE17E@gmail.com> <86mzjthd96.fsf@blue.stonehenge.com> <06C1531F-8BD1-4CAE-960F-BD0D63736668@gmail.com> <43865069.8090701@student.lu.se> <7A053713-A6E0-48C8-AF45-8AEC8C844049@gmail.com> <4386C94A.3080502@student.lu.se> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 (Apple Message framework v746.2) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1132954313 13285 80.91.229.2 (25 Nov 2005 21:31:53 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 25 Nov 2005 21:31:53 +0000 (UTC) Cc: Steven Tamm , Stefan Monnier , YAMAMOTO Mitsuharu , Emacs-Devel ' Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Nov 25 22:31:49 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1Efl9L-0006MF-J7 for ged-emacs-devel@m.gmane.org; Fri, 25 Nov 2005 22:30:33 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Efl9K-0007nJ-6L for ged-emacs-devel@m.gmane.org; Fri, 25 Nov 2005 16:30:30 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Efl8x-0007mx-Sy for emacs-devel@gnu.org; Fri, 25 Nov 2005 16:30:08 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Efl8k-0007el-LS for emacs-devel@gnu.org; Fri, 25 Nov 2005 16:30:07 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Efl8k-0007eW-8o for emacs-devel@gnu.org; Fri, 25 Nov 2005 16:29:54 -0500 Original-Received: from [64.233.162.200] (helo=zproxy.gmail.com) by monty-python.gnu.org with esmtp (Exim 4.34) id 1Efl8j-0001ha-Dy for emacs-devel@gnu.org; Fri, 25 Nov 2005 16:29:54 -0500 Original-Received: by zproxy.gmail.com with SMTP id 4so68939nzn for ; Fri, 25 Nov 2005 13:29:51 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:in-reply-to:references:mime-version:content-type:message-id:cc:content-transfer-encoding:from:subject:date:to:x-mailer; b=f61gwpgVMC+c9nsLRxwqzEPlHzPjtJfG/71yyv4cqAM71KPbShA/l0rR0+XHqIO+kVP5Q2WRXTXK+E+Q/0FNp/XoTwgjtyHyh7/o3ihong03On8SKFq4Dv5XBZwIbRZP2vrMkMPBBPRJdvIPjsEgd9+iWd2gOzaIJywLupyAwPQ= Original-Received: by 10.65.250.10 with SMTP id c10mr8963672qbs; Fri, 25 Nov 2005 13:29:51 -0800 (PST) Original-Received: from ?129.215.174.81? ( [129.215.174.81]) by mx.gmail.com with ESMTP id e16sm854267qba.2005.11.25.13.29.50; Fri, 25 Nov 2005 13:29:51 -0800 (PST) In-Reply-To: <4386C94A.3080502@student.lu.se> Original-To: Lennart Borgman X-Mailer: Apple Mail (2.746.2) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:46582 Archived-At: 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);