tags:

views:

99

answers:

3

I have the following emacs lisp snippet that will launch my browser from within emacs and open the specified pages. However when I run it as a script from a shell nothing happens. What more do I need to do? I tried dropping (interactive).


#!/usr/bin/emacs --script

(defun surf-news ()
  (interactive)
  (progn
    (browse-url "http://news.ycombinator.com")
    (browse-url "http://stackoverflow.com")
      ))

(surf-news)

+1  A: 

A neat function I discovered yesterday is M-x webjump which has recently been added to emacs.

stsquad
A: 

I found the answer on this site, at the bottom, where it describes a Mac OS pty bug. I had to add this line and a slight delay between urls.

 (setq process-connection-type nil)

Here's the complete solution.

#!/usr/bin/emacs --script

(setq process-connection-type nil);; pty's broken on the Mac

(defun surf ()
  (progn
    (browse-url "http://news.ycombinator.com")
    (sleep-for 0.5);  We need a delay
    (browse-url "http://stackoverflow.com")
    ))
;;
;; This is what's going on behind the scenes
;;(setq url "http://www.google.com")
;;(start-process (concat "open " url) nil "open" url)

(surf)
A: 

On linux, if you are in GNOME, KDE, or probably almost any graphical environment, there is probably a command called xdg-open. This command basically takes its argument and opens it with the desktop default application. It handles both files and URLs. So generally when I need to say "Open this in the default application," I use xdg-open.

I think Mac OS has a similar command just called open.

Ryan Thompson