From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nick Dokos Subject: Re: How to make firefox to open html automatically ? Date: Wed, 12 Aug 2009 02:08:30 -0400 Message-ID: <10426.1250057310@gamaville.dokosmarshall.org> References: <907065090908112041q30aa396awe838320595229f12@mail.gmail.com> Reply-To: nicholas.dokos@hp.com Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mb72C-0007qc-Lf for emacs-orgmode@gnu.org; Wed, 12 Aug 2009 02:10:04 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mb728-0007iX-Rc for emacs-orgmode@gnu.org; Wed, 12 Aug 2009 02:10:04 -0400 Received: from [199.232.76.173] (port=57061 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mb728-0007iF-MK for emacs-orgmode@gnu.org; Wed, 12 Aug 2009 02:10:00 -0400 Received: from vms173013pub.verizon.net ([206.46.173.13]:43252) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mb727-0002HM-UU for emacs-orgmode@gnu.org; Wed, 12 Aug 2009 02:10:00 -0400 Received: from gamaville.dokosmarshall.org ([98.110.172.159]) by vms173013.mailsrvcs.net (Sun Java(tm) System Messaging Server 6.3-7.04 (built Sep 26 2008; 32bit)) with ESMTPA id <0KO9003TX2E4DDR4@vms173013.mailsrvcs.net> for emacs-orgmode@gnu.org; Wed, 12 Aug 2009 01:08:29 -0500 (CDT) In-reply-to: Message from waterloo of "Wed, 12 Aug 2009 11:41:22 +0800." <907065090908112041q30aa396awe838320595229f12@mail.gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: waterloo Cc: emacs-orgmode@gnu.org waterloo 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()" 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.