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 (/~)
;;set default browser for browse-url-of (setq browse-url-browser-function 'browse-url-generic) (setq browse-url-generic-program "google-chrome-open-url")
2. We create a new python executable with the following code
#!/usr/bin/env python # Name this file “google-chrome-open-url” from subprocess import call import sys call(['/usr/bin/open', '-a', "/Applications/Google Chrome.app", sys.argv])
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.