From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Simon Josefsson Newsgroups: gmane.emacs.devel Subject: browse-url.el support for firefox Date: Wed, 09 Mar 2005 12:39:31 +0100 Message-ID: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1110371263 29378 80.91.229.2 (9 Mar 2005 12:27:43 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 9 Mar 2005 12:27:43 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Mar 09 13:27:42 2005 Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1D90Hm-0005Mk-Rt for ged-emacs-devel@m.gmane.org; Wed, 09 Mar 2005 13:27:35 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1D90WP-0004gq-SG for ged-emacs-devel@m.gmane.org; Wed, 09 Mar 2005 07:42:43 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1D8zst-0003MD-G5 for emacs-devel@gnu.org; Wed, 09 Mar 2005 07:01:52 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1D8zsn-0003Ko-7o for emacs-devel@gnu.org; Wed, 09 Mar 2005 07:01:48 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1D8zsm-0003J5-NF for emacs-devel@gnu.org; Wed, 09 Mar 2005 07:01:44 -0500 Original-Received: from [217.13.230.178] (helo=yxa.extundo.com) by monty-python.gnu.org with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.34) id 1D8zXh-0007S0-5F for emacs-devel@gnu.org; Wed, 09 Mar 2005 06:39:58 -0500 Original-Received: from latte.josefsson.org (c494102a.s-bi.bostream.se [217.215.27.65]) (authenticated bits=0) by yxa.extundo.com (8.13.3/8.13.3/Debian-6) with ESMTP id j29BdmXP017363 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 9 Mar 2005 12:39:50 +0100 Original-To: emacs-devel@gnu.org OpenPGP: id=B565716F; url=http://josefsson.org/key.txt X-Hashcash: 1:21:050309:emacs-devel@gnu.org::ESmK0Me1KwEf7lz5:3V9A User-Agent: Gnus/5.110003 (No Gnus v0.3) Emacs/22.0.50 (gnu/linux) X-Virus-Scanned: ClamAV version 0.81, clamav-milter version 0.81b on yxa.extundo.com X-Virus-Status: Clean X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org X-MailScanner-To: ged-emacs-devel@m.gmane.org Xref: news.gmane.org gmane.emacs.devel:34370 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:34370 Ok to install? Conditioned on copyright assignments, of course. (I've asked assign@gnu.org, although Steve have papers for Emacs on file before.) Not sure if the patch is really copyrightable though, it is mostly cut'n'paste'n'search'n'replace. While I'm at it, I find browse-url.el slightly inelegant for at least two reasons: * Are all the browse-url-*-new-window-is-tab variables useful? Wouldn't it be better to collapse them into just one variable, browse-url-new-window-is-tab? I could propose a patch if people agree (read: don't disagree). * The Mozilla based browsers are very similar, but have their own functions anyway. A lot of cut'n'paste. This applies to at least Mozilla, Galeon and (with this) Firefox, and possibly also Netscape. Could be useful to parametrize the functions. I don't have time to do this, but if anyone wants to take up on this, that would be excellent... 2005-03-09 Steve Youngs * net/browse-url.el (browse-url-browser-function): Add firefox. (browse-url-firefox-program): New. (browse-url-firefox-arguments): New. (browse-url-firefox-startup-arguments): New. (browse-url-firefox-new-window-is-tab): New. (browse-url-default-browser): Add firefox. (browse-url-firefox): New. (browse-url-firefox-sentinel): New. --- browse-url.el 09 Mar 2005 12:26:30 +0100 1.43 +++ browse-url.el 09 Mar 2005 12:28:16 +0100 @@ -38,6 +38,7 @@ ;; Function Browser Earliest version ;; browse-url-mozilla Mozilla Don't know +;; browse-url-firefox Firefox Don't know (tried with 1.0.1) ;; browse-url-galeon Galeon Don't know ;; browse-url-epiphany Epiphany Don't know ;; browse-url-netscape Netscape 1.1b1 @@ -248,6 +249,7 @@ (function-item :tag "W3 in another Emacs via `gnudoit'" :value browse-url-w3-gnudoit) (function-item :tag "Mozilla" :value browse-url-mozilla) + (function-item :tag "Firefox" :value browse-url-firefox) (function-item :tag "Galeon" :value browse-url-galeon) (function-item :tag "Epiphany" :value browse-url-epiphany) (function-item :tag "Netscape" :value browse-url-netscape) @@ -323,6 +325,25 @@ :type '(repeat (string :tag "Argument")) :group 'browse-url) +;;;###autoload +(defcustom browse-url-firefox-program "firefox" + "*The name by which to invoke Firefox." + :type 'string + :group 'browse-url) + +(defcustom browse-url-firefox-arguments nil + "*A list of strings to pass to Firefox as arguments." + :type '(repeat (string :tag "Argument")) + :group 'browse-url) + +(defcustom browse-url-firefox-startup-arguments browse-url-firefox-arguments + "*A list of strings to pass to Firefox when it starts up. +Defaults to the value of `browse-url-firefox-arguments' at the time +`browse-url' is loaded." + :type '(repeat (string :tag "Argument")) + :group 'browse-url) + +;;;###autoload (defcustom browse-url-galeon-program "galeon" "*The name by which to invoke Galeon." :type 'string @@ -373,6 +394,13 @@ :type 'boolean :group 'browse-url) +(defcustom browse-url-firefox-new-window-is-tab nil + "*Whether to open up new windows in a tab or a new window. +If non-nil, then open the URL in a new tab rather than a new window if +`browse-url-firefox' is asked to open it in a new window." + :type 'boolean + :group 'browse-url) + (defcustom browse-url-galeon-new-window-is-tab nil "*Whether to open up new windows in a tab or a new window. If non-nil, then open the URL in a new tab rather than a new window if @@ -815,13 +843,14 @@ When called non-interactively, optional second argument NEW-WINDOW is used instead of `browse-url-new-window-flag'. -The order attempted is gnome-moz-remote, Mozilla, Galeon, -Konqueror, Netscape, Mosaic, IXI Mosaic, Lynx in an xterm, MMM, -and then W3." +The order attempted is gnome-moz-remote, Mozilla, Firefox, +Galeon, Konqueror, Netscape, Mosaic, IXI Mosaic, Lynx in an +xterm, MMM, and then W3." (apply (cond ((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) ((executable-find browse-url-galeon-program) 'browse-url-galeon) ((executable-find browse-url-kde-program) 'browse-url-kde) ((executable-find browse-url-netscape-program) 'browse-url-netscape) @@ -960,6 +989,72 @@ (append browse-url-mozilla-startup-arguments (list url)))))) ;;;###autoload +(defun browse-url-firefox (url &optional new-window) + "Ask the Firefox WWW browser to load URL. +Default to the URL around or before point. The strings in +variable `browse-url-firefox-arguments' are also passed to +Firefox. + +When called interactively, if variable +`browse-url-new-window-flag' is non-nil, load the document in a +new Firefox window, otherwise use a random existing one. A +non-nil interactive prefix argument reverses the effect of +`browse-url-new-window-flag'. + +If `browse-url-firefox-new-window-is-tab' is non-nil, then +whenever a document would otherwise be loaded in a new window, it +is loaded in a new tab in an existing window instead. + +When called non-interactively, optional second argument +NEW-WINDOW is used instead of `browse-url-new-window-flag'. + +On MS-Windows systems the optional `new-window' parameter is +ignored. Firefox for Windows does not support the \"-remote\" +command line parameter. Therefore the +`browse-url-new-window-flag', `browse-url-new-window-flag' and +`browse-url-firefox-new-window-is-tab' are ignored as +well. Firefox on Windows will always open the requested URL in a +new window." + (interactive (browse-url-interactive-arg "URL: ")) + ;; URL encode any `confusing' characters in the URL. This needs to + ;; include at least commas; presumably also close parens. + (while (string-match "[,)]" url) + (setq url (replace-match + (format "%%%x" (string-to-char (match-string 0 url))) t t url))) + (let* ((process-environment (browse-url-process-environment)) + (process + (apply 'start-process + (concat "firefox " url) nil + browse-url-firefox-program + (append + browse-url-firefox-arguments + (if (or (featurep 'dos-w32) + (string-match "win32" system-configuration)) + (list url) + (list "-remote" + (concat "openURL(" + url + (if (browse-url-maybe-new-window + new-window) + (if browse-url-firefox-new-window-is-tab + ",new-tab" + ",new-window")) + ")"))))))) + (set-process-sentinel process + `(lambda (process change) + (browse-url-firefox-sentinel process ,url))))) + +(defun browse-url-firefox-sentinel (process url) + "Handle a change to the process communicating with Firefox." + (or (eq (process-exit-status process) 0) + (let* ((process-environment (browse-url-process-environment))) + ;; Firefox is not running - start it + (message "Starting Firefox...") + (apply 'start-process (concat "firefox " url) nil + browse-url-firefox-program + (append browse-url-firefox-startup-arguments (list url)))))) + +;;;###autoload (defun browse-url-galeon (url &optional new-window) "Ask the Galeon WWW browser to load URL. Default to the URL around or before point. The strings in variable