[Top][All Lists]

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

Re: [Orgmode] How to make firefox to open html automatically ?

From: Nick Dokos
Subject: Re: [Orgmode] How to make firefox to open html automatically ?
Date: Wed, 12 Aug 2009 02:08:30 -0400

waterloo <address@hidden> wrote:

> When I run C-c C-e b , the html file is open in emacs .
> How to make firefox to open html exported automatically ?

There are probably many ways to do it, depending on where you want to
put the customization. I chose (perhaps unwisely - see below) to put it
into the lowest layer. Note that there is no warranty, express or
implied, of any kind: you do the following of your own free will, and if
your computer explodes or kittens die as a result, you cannot hold me

Org uses the function org-open-file(), which by default uses the mailcap
method to open the file. The command that is executed is the result of
this function call:

   (mailcap-mime-info "text/html")

In my case, this returns "/usr/bin/w3m -T text/html '%s'" where the %s
is replaced by the pathname of the file.

It turns out that mailcap-mime-info obtains this by looking into a
double association list, mailcap-mime-data (in mailcap.el): the first
level a-list is indexed by the major mime type ("text" above); the value
is a second-level a-list indexed by the minor mime type ("html" above,
but it could also be other kinds of text , e.g. "plain"). There can be
multiple elements with the same minor mime type: mailcap-mime-info returns
the first element of that list. The value in the second level a-list is
yet another, third-level a-list, as shown below.

So the trick is to add a new element to the appropriate place in the
double a-list, so that mailcap-mime-info will return it. First the
command for firefox to open a URL remotely is

        /usr/bin/firefox --remote "openURL(<URL>)"

THe element that we need to add to the list is (note that the command
has been specialized for a file://-type URL):

           (viewer . "/usr/bin/firefox --remote \"openURL(file://'%s')\"")
           (type . "text/html")
           ("nametemplate" . "%s.html")
           ("description" . "HTML Text")
           ("needsterminal" . nil))

I define a variable whose value is the list above, to simplify the notation:

(setq ff '("html" 
           (viewer . "/usr/bin/firefox --remote \"openURL(file://'%s')\"")
           (type . "text/html")
           ("nametemplate" . "%s.html")
           ("description" . "HTML Text")
           ("needsterminal" . nil)))

Then I do surgery on the double a-list, replacing the second-level a-list that 
indexed by "text", by a modified one that has the new element ff from above at 

(rplacd (assoc "text" mailcap-mime-data) (cons ff (cdr (assoc "text" 

And that's all! After this, (mailcap-mime-info "text/html") returns
"/usr/bin/firefox --remote \"openURL(file://'%s')\"" - just what the doctor 
And doing C-c C-e b on an org file sends the URL to firefox for display.

Horrible, no? If anybody comes up with an easier way, do tell!


PS BTW, I was evaluating these things in the *scratch* buffer. That way,
if something goes wrong, I kill emacs, restart and all is
forgotten. After assuring yourself that this works, then you have to put
it in some initialization file. Make sure to (require 'mailcap) before
mucking aroung with mailcap-mime-data.

reply via email to

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