unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Bug in Carbon port: browse-url-default-macosx-browser
@ 2005-11-23 21:22 David Reitter
  2005-11-24 17:23 ` Stefan Monnier
  0 siblings, 1 reply; 14+ messages in thread
From: David Reitter @ 2005-11-23 21:22 UTC (permalink / raw)


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.

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2005-11-28  9:36 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-11-23 21:22 Bug in Carbon port: browse-url-default-macosx-browser David Reitter
2005-11-24 17:23 ` Stefan Monnier
2005-11-24 17:40   ` David Reitter
2005-11-24 21:03     ` Stefan Monnier
2005-11-24 22:32       ` David Reitter
2005-11-24 22:50         ` Randal L. Schwartz
2005-11-24 23:23           ` David Reitter
2005-11-24 23:44             ` Lennart Borgman
2005-11-25  6:59               ` David Reitter
2005-11-25  8:20                 ` Lennart Borgman
2005-11-25 21:29                   ` David Reitter
2005-11-28  2:32                     ` YAMAMOTO Mitsuharu
2005-11-28  9:12                       ` David Reitter
2005-11-28  9:36                         ` YAMAMOTO Mitsuharu

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).