November 22, 2004 4:39 PM
Upon searching for a browse-url that works with firefox, I came across
the one at EmacsWiki that uses mozilla-xremote-client
. It had a
deficiency though. While using JDEE to test applets, you need a
file:///
before the filename for it to work in firefox. So, here's
the modified version:
(defun browse-url-firefox-new-tab (url &optional new-window) "Open URL in a new tab in Firefox." (interactive (browse-url-interactive-arg "URL: ")) (if (string= (substring url 0 1) "/") (setq url (concat "file://" url))) (let ((cmd (shell-command-to-string (concat "~/firefox/mozilla-xremote-client -a any 'openURL(" url ",new-tab)'")))) (unless (string= "" cmd) (message "Starting Firefox...") (start-process (concat "firefox " url) nil "~/firefox/firefox" url) (message "Starting Firefox...done")))) (setq browse-url-browser-function 'browse-url-firefox-new-tab)
If the path begins with /, it automatically adds file:///
before
calling mozilla-xremote-client
.
This is useful in emacs-wiki-mode to view a published wiki file using this snippet:
(defun load-html-firefox () "Load Wiki's published html file into a firefox tab." (interactive) (browse-url (expand-file-name (emacs-wiki-published-name (emacs-wiki-page-name)) emacs-wiki-publishing-directory))) (define-key emacs-wiki-mode-map [(control ?c) (control ?F)] 'load-html-firefox)
Shell script that loads a url in a new firefox tab:
#!/bin/bash url="$1"; case $1 in /*) url="file://$1" ;; esac if ~/firefox/mozilla-xremote-client -a any "openURL($url,new-tab)"; then echo "Loaded $url in new tab"; else echo "Launching Firefox..."; ~/firefox/firefox $url & fi