Reputation:
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)
Upvotes: 0
Views: 1308
Reputation: 2360
As Ryan Thompson mentioned above, you can use xdg-open in Emacs.
Change:
(browse-url "http://news.ycombinator.com")
(browse-url "http://stackoverflow.com")
To:
(browse-url-xdg-open "http://news.ycombinator.com")
(browse-url-xdg-open "http://stackoverflow.com"))
Upvotes: 1
Reputation: 42010
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
.
Upvotes: 0
Reputation:
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)
Upvotes: 0
Reputation: 6022
A neat function I discovered yesterday is M-x webjump which has recently been added to emacs.
Upvotes: 2