emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* How to make firefox to open html automatically ?
@ 2009-08-12  3:41 waterloo
  2009-08-12  6:08 ` Nick Dokos
  0 siblings, 1 reply; 2+ messages in thread
From: waterloo @ 2009-08-12  3:41 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 123 bytes --]

When I run C-c C-e b , the html file is open in emacs .

How to make firefox to open html exported automatically ?

Thanks

[-- Attachment #1.2: Type: text/html, Size: 139 bytes --]

[-- Attachment #2: Type: text/plain, Size: 204 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Remember: use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

* Re: How to make firefox to open html automatically ?
  2009-08-12  3:41 How to make firefox to open html automatically ? waterloo
@ 2009-08-12  6:08 ` Nick Dokos
  0 siblings, 0 replies; 2+ messages in thread
From: Nick Dokos @ 2009-08-12  6:08 UTC (permalink / raw)
  To: waterloo; +Cc: emacs-orgmode

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.

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

end of thread, other threads:[~2009-08-12  6:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-12  3:41 How to make firefox to open html automatically ? waterloo
2009-08-12  6:08 ` Nick Dokos

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