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: Bug in Carbon port: browse-url-default-macosx-browser Date: Wed, 23 Nov 2005 21:22:11 +0000 Message-ID: <502E6611-3B38-4C39-9469-4E4902EE0586@gmail.com> 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 1132781790 8388 80.91.229.2 (23 Nov 2005 21:36:30 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 23 Nov 2005 21:36:30 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Nov 23 22:36:28 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1Ef2EP-0006mV-8v for ged-emacs-devel@m.gmane.org; Wed, 23 Nov 2005 22:32:45 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ef2EO-0004W1-M3 for ged-emacs-devel@m.gmane.org; Wed, 23 Nov 2005 16:32:44 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Ef24J-0003JN-86 for emacs-devel@gnu.org; Wed, 23 Nov 2005 16:22:19 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Ef24H-0003HY-KR for emacs-devel@gnu.org; Wed, 23 Nov 2005 16:22:18 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ef24G-0003GP-Qt for emacs-devel@gnu.org; Wed, 23 Nov 2005 16:22:17 -0500 Original-Received: from [64.233.184.200] (helo=wproxy.gmail.com) by monty-python.gnu.org with esmtp (Exim 4.34) id 1Ef24G-0004kU-HA for emacs-devel@gnu.org; Wed, 23 Nov 2005 16:22:16 -0500 Original-Received: by wproxy.gmail.com with SMTP id i5so1391943wra for ; Wed, 23 Nov 2005 13:22:15 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:mime-version:content-transfer-encoding:message-id:content-type:to:from:subject:date:x-mailer; b=DrIupR63rZBn33B3ESwRfo1Ag/Ya+BoynYge7RHuwrSlOY/YEbu+u61wF95EiK7jf02z6uobNkqIUC45XpzTlnR15orYLVjlbxystfZUqKfzfwa5s59IZS8CWJDEEprqkBbqsyrwnK3nsQSLW2vWB6bFz7AVkOIb/hIOvoc4NDM= Original-Received: by 10.65.103.12 with SMTP id f12mr6610097qbm; Wed, 23 Nov 2005 13:22:15 -0800 (PST) Original-Received: from ?129.215.174.81? ( [129.215.174.81]) by mx.gmail.com with ESMTP id q13sm714828qbq.2005.11.23.13.22.14; Wed, 23 Nov 2005 13:22:15 -0800 (PST) Original-To: Emacs-Devel ' 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:46489 Archived-At: The browse-url functions have a bug on OS X: When a local file is browsed (such as during "Preview Buffer" in HTML(-Helper) mode), the system will open the file in the application that is the default handler for .html files. Chances are that this default handler is NOT the default browser, but an editor such as Emacs itself. This is actually what happens when you run Emacs on a virgin OS X machine: HTML files are not associated with the browser. (Happened to me when I installed it on a friend's brand-new iBook). Here's what the relevant function does: (defun browse-url-default-macosx-browser (url &optional new-window) (interactive (browse-url-interactive-arg "URL: ")) (start-process (concat "open " url) nil "open" url)) as originally proposed here: http://groups.google.com/group/gnu.emacs.bug/browse_thread/thread/ fdf8b2f1523f9c94/9903ef920ab11af6 Now, the problem is that while "open" is specified to open http:// URLs in the default browser, it will open "file://" URLs in the system's default handler for the particular file, which is usually what's associated with the file type of the file, or its extension. I have spent half the evening researching the correct solution (without using Cocoa) and the best I could come up with was this: (defun browse-url-default-macosx-browser (url &optional new-window) (interactive (browse-url-interactive-arg "URL: ")) (if (not (string-match "file:/*\\(/.*\\)" url)) (start-process (concat "open " url) nil "open" url) (let* ((file (match-string 1 url)) (newfile (concat file ".emacs-url"))) (copy-file file newfile 'overwrite 'keeptime nil 'preserve) (mac-set-file-type newfile "HTML") (start-process (concat "open " newfile) nil "open" url)))) Not very elegant, and needs to write to the directory where the .html file is. (Needs to do that in order to eliminate the use of any .html standard handler. Can't be in /tmp because the browser will interpret all embedded URLs (e.g. graphics) as relative to path. Could get around by writing a temporary redirection file to /tmp. This is even clunkier.) Note that something like this won't work: (do-applescript (format "tell \"browser\" open location \"%s\"" "file:///Users/dr/Temp/test.html end tell ")) doesn't work either - it does the same as "open". Any solutions involving "tell application Finder" aren't acceptable either because the Finder is not defined to be present. Maybe some of the Mac people here have an idea.