comparison lisp/net/browse-url.el @ 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 3eb0fffdd08f
children 7c4da622f181
comparison
equal deleted inserted replaced
109812:063e94b66261 109813:17256ad564e9
890 890
891 The order attempted is gnome-moz-remote, Mozilla, Firefox, 891 The order attempted is gnome-moz-remote, Mozilla, Firefox,
892 Galeon, Konqueror, Netscape, Mosaic, Lynx in an xterm, and then W3." 892 Galeon, Konqueror, Netscape, Mosaic, Lynx in an xterm, and then W3."
893 (apply 893 (apply
894 (cond 894 (cond
895 ((browse-url-can-use-xdg-open) 'browse-url-xdg-open)
895 ((executable-find browse-url-gnome-moz-program) 'browse-url-gnome-moz) 896 ((executable-find browse-url-gnome-moz-program) 'browse-url-gnome-moz)
896 ((executable-find browse-url-mozilla-program) 'browse-url-mozilla) 897 ((executable-find browse-url-mozilla-program) 'browse-url-mozilla)
897 ((executable-find browse-url-firefox-program) 'browse-url-firefox) 898 ((executable-find browse-url-firefox-program) 'browse-url-firefox)
898 ((executable-find browse-url-galeon-program) 'browse-url-galeon) 899 ((executable-find browse-url-galeon-program) 'browse-url-galeon)
899 ((executable-find browse-url-kde-program) 'browse-url-kde) 900 ((executable-find browse-url-kde-program) 'browse-url-kde)
902 ((executable-find browse-url-xterm-program) 'browse-url-text-xterm) 903 ((executable-find browse-url-xterm-program) 'browse-url-text-xterm)
903 ((locate-library "w3") 'browse-url-w3) 904 ((locate-library "w3") 'browse-url-w3)
904 (t 905 (t
905 (lambda (&rest ignore) (error "No usable browser found")))) 906 (lambda (&rest ignore) (error "No usable browser found"))))
906 url args)) 907 url args))
908
909 (defun browse-url-can-use-xdg-open ()
910 "Check if xdg-open can be used, i.e. we are on Gnome, KDE or xfce4."
911 (and (getenv "DISPLAY")
912 (executable-find "xdg-open")
913 ;; xdg-open may call gnome-open and that does not wait for its child
914 ;; to finish. This child may then be killed when the parent dies.
915 ;; Use nohup to work around.
916 (executable-find "nohup")
917 (or (getenv "GNOME_DESKTOP_SESSION_ID")
918 ;; GNOME_DESKTOP_SESSION_ID is deprecated, check on Dbus also.
919 (condition-case nil
920 (eq 0 (call-process
921 "dbus-send" nil nil nil
922 "--dest=org.gnome.SessionManager"
923 "--print-reply"
924 "/org/gnome/SessionManager"
925 "org.gnome.SessionManager.CanShutdown"))
926 (error nil))
927 (equal (getenv "KDE_FULL_SESSION") "true")
928 (condition-case nil
929 (eq 0 (call-process
930 "/bin/sh" nil nil nil
931 "-c"
932 "xprop -root _DT_SAVE_MODE|grep xfce4"))
933 (error nil)))))
934
935
936 ;;;###autoload
937 (defun browse-url-xdg-open (url &optional new-window)
938 (interactive (browse-url-interactive-arg "URL: "))
939 (call-process "/bin/sh" nil nil nil
940 "-c"
941 (concat "nohup xdg-open " url
942 ">/dev/null 2>&1 </dev/null")))
907 943
908 ;;;###autoload 944 ;;;###autoload
909 (defun browse-url-netscape (url &optional new-window) 945 (defun browse-url-netscape (url &optional new-window)
910 "Ask the Netscape WWW browser to load URL. 946 "Ask the Netscape WWW browser to load URL.
911 Default to the URL around or before point. The strings in variable 947 Default to the URL around or before point. The strings in variable