I use emacs’ html-mode fairly often. And on OS X, it’s always been a problem that I couldn’t use Chrome to preview HTML pages straight from emacs. I found some help on StackOveflow, but not much in the way that it solved my issue.
I went ahead and made a python script that gets called from emacs every time I save an html file in html-mode.
This is two step process:
1. We edit our .emacs file located within your home directory (/~)
The below code should be copy pasted or entered in your
.emacs located at
Line 3: calls the
browse-url-generic function which in runs a “generic program” called google-chrome-open-url - this is our
python script(see below).
2. We create a new python executable with the following code
The above is a straight forward python script. That uses the
call method from the
subprocess module to execute a
terminal based command to open the app. The thing to note here is that the script takes an argument from the command line. This argument is supplied by emacs lisp lines above while making a call to this python script (“google-chrome-open-url”). This is where we use
Make sure that this file is executable and the path to this is located in your
PATH var. Instead of keeping this file around in a seperate directory and then specifying the path, I just moved it to my
This was possible because you can use OS X’s CLI / Terminal.app to open/execute apps via the
Hope this helps someone out there.