changeset 109813:17256ad564e9

Add ability to use xdg-open, i.e. your desktop default browser. * net/browse-url.el (browse-url-default-browser): Add cond for browse-url-xdg-open (browse-url-can-use-xdg-open, browse-url-xdg-open): New functions
author Jan D. <jan.h.d@swipnet.se>
date Tue, 17 Aug 2010 10:01:10 +0200
parents 063e94b66261
children ea341a06439f
files lisp/ChangeLog lisp/net/browse-url.el
diffstat 2 files changed, 42 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Tue Aug 17 00:29:26 2010 -0700
+++ b/lisp/ChangeLog	Tue Aug 17 10:01:10 2010 +0200
@@ -1,3 +1,9 @@
+2010-08-17  Jan Djärv  <jan.h.d@swipnet.se>
+
+	* net/browse-url.el (browse-url-default-browser): Add cond
+	for browse-url-xdg-open
+	(browse-url-can-use-xdg-open, browse-url-xdg-open): New functions
+
 2010-08-17  Glenn Morris  <rgm@gnu.org>
 
 	* progmodes/cc-engine.el (c-new-BEG, c-new-END)
--- a/lisp/net/browse-url.el	Tue Aug 17 00:29:26 2010 -0700
+++ b/lisp/net/browse-url.el	Tue Aug 17 10:01:10 2010 +0200
@@ -892,6 +892,7 @@
 Galeon, Konqueror, Netscape, Mosaic, Lynx in an xterm, and then W3."
   (apply
    (cond
+    ((browse-url-can-use-xdg-open) 'browse-url-xdg-open)
     ((executable-find browse-url-gnome-moz-program) 'browse-url-gnome-moz)
     ((executable-find browse-url-mozilla-program) 'browse-url-mozilla)
     ((executable-find browse-url-firefox-program) 'browse-url-firefox)
@@ -905,6 +906,41 @@
      (lambda (&rest ignore) (error "No usable browser found"))))
    url args))
 
+(defun browse-url-can-use-xdg-open ()
+  "Check if xdg-open can be used, i.e. we are on Gnome, KDE or xfce4."
+  (and (getenv "DISPLAY")
+       (executable-find "xdg-open")
+       ;; xdg-open may call gnome-open and that does not wait for its child
+       ;; to finish.  This child may then be killed when the parent dies.
+       ;; Use nohup to work around.
+       (executable-find "nohup")
+       (or (getenv "GNOME_DESKTOP_SESSION_ID")
+	   ;; GNOME_DESKTOP_SESSION_ID is deprecated, check on Dbus also.
+	   (condition-case nil
+	       (eq 0 (call-process
+		      "dbus-send" nil nil nil
+				  "--dest=org.gnome.SessionManager"
+				  "--print-reply"
+				  "/org/gnome/SessionManager"
+				  "org.gnome.SessionManager.CanShutdown"))
+	     (error nil))
+	   (equal (getenv "KDE_FULL_SESSION") "true")
+	   (condition-case nil
+	       (eq 0 (call-process
+		      "/bin/sh" nil nil nil
+		      "-c"
+		      "xprop -root _DT_SAVE_MODE|grep xfce4"))
+	     (error nil)))))
+
+
+;;;###autoload
+(defun browse-url-xdg-open (url &optional new-window)
+  (interactive (browse-url-interactive-arg "URL: "))
+  (call-process "/bin/sh" nil nil nil
+		"-c"
+		(concat "nohup xdg-open " url
+			">/dev/null 2>&1 </dev/null")))
+
 ;;;###autoload
 (defun browse-url-netscape (url &optional new-window)
   "Ask the Netscape WWW browser to load URL.