emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bug in Carbon port: browse-url-default-macosx-browser


From: David Reitter
Subject: Bug in Carbon port: browse-url-default-macosx-browser
Date: Wed, 23 Nov 2005 21:22:11 +0000

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.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]