emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nick Dokos <nicholas.dokos@hp.com>
To: waterloo <waterloo2005@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: How to make firefox to open html automatically ?
Date: Wed, 12 Aug 2009 02:08:30 -0400	[thread overview]
Message-ID: <10426.1250057310@gamaville.dokosmarshall.org> (raw)
In-Reply-To: Message from waterloo <waterloo2005@gmail.com> of "Wed, 12 Aug 2009 11:41:22 +0800." <907065090908112041q30aa396awe838320595229f12@mail.gmail.com>

waterloo <waterloo2005@gmail.com> 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
responsible!

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):

("html" 
           (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 is
indexed by "text", by a modified one that has the new element ff from above at the
front:

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

And that's all! After this, (mailcap-mime-info "text/html") returns
"/usr/bin/firefox --remote \"openURL(file://'%s')\"" - just what the doctor ordered.
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!

Nick

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	other threads:[~2009-08-12  6:10 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-12  3:41 How to make firefox to open html automatically ? waterloo
2009-08-12  6:08 ` Nick Dokos [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=10426.1250057310@gamaville.dokosmarshall.org \
    --to=nicholas.dokos@hp.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=waterloo2005@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.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).