]> code.delx.au - gnu-emacs/blobdiff - lisp/net/browse-url.el
* term/ns-win.el (ns-alternatives-map, ns-insert-working-text)
[gnu-emacs] / lisp / net / browse-url.el
index cfb3f2742e9e1edee8e0fb6700eb135efacf8cf1..992a081fefd528b034df4bec90fd4ac9c2397a01 100644 (file)
@@ -1,7 +1,7 @@
 ;;; browse-url.el --- pass a URL to a WWW browser
 
 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
-;;   2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+;;   2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
 
 ;; Author: Denis Howe <dbh@doc.ic.ac.uk>
 ;; Maintainer: FSF
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -21,9 +21,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
 ;; browse-url-cci                     XMosaic     2.5
 ;; browse-url-w3                      w3          0
 ;; browse-url-w3-gnudoit              w3 remotely
-;; browse-url-iximosaic               IXI Mosaic  ?
-;; browse-url-lynx-*                 Lynx           0
-;; browse-url-grail                   Grail       0.3b1
-;; browse-url-mmm                     MMM         ?
+;; browse-url-text-*                 Any text browser     0
 ;; browse-url-generic                 arbitrary
 ;; browse-url-default-windows-browser MS-Windows browser
 ;; browse-url-default-macosx-browser  Mac OS X browser
 ;; Emacs process is available from
 ;; <URL:ftp://ftp.splode.com/pub/users/friedman/packages/>.
 
-;; Grail is the freely available WWW browser implemented in Python, a
-;; cool object-oriented freely available interpreted language.  Grail
-;; 0.3b1 was the first version to have remote control as distributed.
-;; For more information on Grail see
-;; <URL:http://grail.cnri.reston.va.us/> and for more information on
-;; Python see <url:http://www.python.org/>.  Grail support in
-;; browse-url.el written by Barry Warsaw <bwarsaw@python.org>.
-
 ;; Lynx is now distributed by the FSF.  See also
 ;; <URL:http://lynx.browser.org/>.
 
@@ -257,13 +244,10 @@ regexp should probably be \".\" to specify a default browser."
          (function-item :tag "Netscape" :value  browse-url-netscape)
          (function-item :tag "Mosaic" :value  browse-url-mosaic)
          (function-item :tag "Mosaic using CCI" :value  browse-url-cci)
-         (function-item :tag "IXI Mosaic" :value  browse-url-iximosaic)
-         (function-item :tag "Lynx in an xterm window"
-                        :value browse-url-lynx-xterm)
-         (function-item :tag "Lynx in an Emacs window"
-                        :value browse-url-lynx-emacs)
-         (function-item :tag "Grail" :value  browse-url-grail)
-         (function-item :tag "MMM" :value  browse-url-mmm)
+         (function-item :tag "Text browser in an xterm window"
+                        :value browse-url-text-xterm)
+         (function-item :tag "Text browser in an Emacs window"
+                        :value browse-url-text-emacs)
          (function-item :tag "KDE" :value browse-url-kde)
          (function-item :tag "Elinks" :value browse-url-elinks)
          (function-item :tag "Specified by `Browse Url Generic Program'"
@@ -462,7 +446,7 @@ commands reverses the effect of this variable.  Requires Netscape version
     ,@(if (memq system-type '(windows-nt ms-dos cygwin))
           '(("^\\([a-zA-Z]:\\)[\\/]" . "file:\\1/")
             ("^[\\/][\\/]+" . "file://")))
-    ("^/+" . "file:/"))
+    ("^/+" . "file:///"))
   "An alist of (REGEXP . STRING) pairs used by `browse-url-of-file'.
 Any substring of a filename matching one of the REGEXPs is replaced by
 the corresponding STRING using `replace-match', not treating STRING
@@ -482,7 +466,7 @@ address to an HTTP URL:
   :type '(repeat (cons :format "%v"
                        (regexp :tag "Regexp")
                        (string :tag "Replacement")))
-  :version "20.3"
+  :version "23.1"
   :group 'browse-url)
 
 (defcustom browse-url-save-file nil
@@ -518,7 +502,7 @@ enabled.  The port number should be set in `browse-url-CCI-port'."
 (make-variable-buffer-local 'browse-url-temp-file-name)
 
 (defcustom browse-url-xterm-program "xterm"
-  "The name of the terminal emulator used by `browse-url-lynx-xterm'.
+  "The name of the terminal emulator used by `browse-url-text-xterm'.
 This might, for instance, be a separate color version of xterm."
   :type 'string
   :group 'browse-url)
@@ -529,17 +513,6 @@ These might set its size, for instance."
   :type '(repeat (string :tag "Argument"))
   :group 'browse-url)
 
-(defcustom browse-url-lynx-emacs-args (and (not window-system)
-                                           '("-show_cursor"))
-  "A list of strings defining options for Lynx in an Emacs buffer.
-
-The default is none in a window system, otherwise `-show_cursor' to
-indicate the position of the current link in the absence of
-highlighting, assuming the normal default for showing the cursor."
-  :type '(repeat (string :tag "Argument"))
-  :version "20.3"
-  :group 'browse-url)
-
 (defcustom browse-url-gnudoit-program "gnudoit"
   "The name of the `gnudoit' program used by `browse-url-w3-gnudoit'."
   :type 'string
@@ -576,28 +549,47 @@ incompatibly at version 4."
   :type 'number
   :group 'browse-url)
 
-(defcustom browse-url-lynx-input-field 'avoid
-  "Action on selecting an existing Lynx buffer at an input field.
-What to do when sending a new URL to an existing Lynx buffer in Emacs
-if the Lynx cursor is on an input field (in which case the `g' command
+(defcustom browse-url-text-browser "lynx"
+  "The name of the text browser to invoke."
+  :type 'string
+  :group 'browse-url
+  :version "23.1")
+
+(defcustom browse-url-text-emacs-args (and (not window-system)
+                                          '("-show_cursor"))
+  "A list of strings defining options for a text browser in an Emacs buffer.
+
+The default is none in a window system, otherwise `-show_cursor' to
+indicate the position of the current link in the absence of
+highlighting, assuming the normal default for showing the cursor."
+  :type '(repeat (string :tag "Argument"))
+  :version "23.1"
+  :group 'browse-url)
+
+(defcustom browse-url-text-input-field 'avoid
+  "Action on selecting an existing text browser buffer at an input field.
+What to do when sending a new URL to an existing text browser buffer in Emacs
+if the browser cursor is on an input field (in which case the `g' command
 would be entered as data).  Such fields are recognized by the
-underlines ____.  Allowed values: nil: disregard it, 'warn: warn the
-user and don't emit the URL, 'avoid: try to avoid the field by moving
+underlines ____.  Allowed values: nil: disregard it, `warn': warn the
+user and don't emit the URL, `avoid': try to avoid the field by moving
 down (this *won't* always work)."
   :type '(choice (const :tag "Move to try to avoid field" :value avoid)
                  (const :tag "Disregard" :value nil)
                  (const :tag "Warn, don't emit URL" :value warn))
-  :version "20.3"
+  :version "23.1"
   :group 'browse-url)
 
-(defcustom browse-url-lynx-input-attempts 10
-  "How many times to try to move down from a series of lynx input fields."
+(defcustom browse-url-text-input-attempts 10
+  "How many times to try to move down from a series of text browser input fields."
   :type 'integer
+  :version "23.1"
   :group 'browse-url)
 
-(defcustom browse-url-lynx-input-delay 0.2
-  "How many seconds to wait for lynx between moves down from an input field."
+(defcustom browse-url-text-input-delay 0.2
+  "Seconds to wait for a text browser between moves down from an input field."
   :type 'number
+  :version "23.1"
   :group 'browse-url)
 
 (defcustom browse-url-kde-program "kfmclient"
@@ -831,6 +823,7 @@ to use."
 ;; --- Default MS-Windows browser ---
 
 (defvar dos-windows-version)
+(declare-function w32-shell-execute "w32fns.c")    ;; Defined in C.
 
 (defun browse-url-default-windows-browser (url &optional new-window)
   (interactive (browse-url-interactive-arg "URL: "))
@@ -880,8 +873,7 @@ 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, Firefox,
-Galeon, Konqueror, Netscape, Mosaic, IXI Mosaic, Lynx in an
-xterm, MMM, and then W3."
+Galeon, Konqueror, Netscape, Mosaic, Lynx in an xterm, and then W3."
   (apply
    (cond
     ((executable-find browse-url-gnome-moz-program) 'browse-url-gnome-moz)
@@ -891,12 +883,10 @@ xterm, MMM, and then W3."
     ((executable-find browse-url-kde-program) 'browse-url-kde)
     ((executable-find browse-url-netscape-program) 'browse-url-netscape)
     ((executable-find browse-url-mosaic-program) 'browse-url-mosaic)
-    ((executable-find "tellw3b") 'browse-url-iximosaic)
-    ((executable-find browse-url-xterm-program) 'browse-url-lynx-xterm)
-    ((executable-find "mmm") 'browse-url-mmm)
+    ((executable-find browse-url-xterm-program) 'browse-url-text-xterm)
     ((locate-library "w3") 'browse-url-w3)
     (t
-     (lambda (&ignore args) (error "No usable browser found"))))
+     (lambda (&rest ignore) (error "No usable browser found"))))
    url args))
 
 ;;;###autoload
@@ -1170,6 +1160,8 @@ used instead of `browse-url-new-window-flag'."
               browse-url-epiphany-program
               (append browse-url-epiphany-startup-arguments (list url))))))
 
+(defvar url-handler-regexp)
+
 ;;;###autoload
 (defun browse-url-emacs (url &optional new-window)
   "Ask Emacs to load URL into a buffer and show it in another window."
@@ -1257,28 +1249,6 @@ used instead of `browse-url-new-window-flag'."
             (append browse-url-mosaic-arguments (list url)))
       (message "Starting %s...done" browse-url-mosaic-program))))
 
-;; --- Grail ---
-
-(defvar browse-url-grail
-  (concat (or (getenv "GRAILDIR") "~/.grail") "/user/rcgrail.py")
-  "Location of Grail remote control client script `rcgrail.py'.
-Typically found in $GRAILDIR/rcgrail.py, or ~/.grail/user/rcgrail.py.")
-
-;;;###autoload
-(defun browse-url-grail (url &optional new-window)
-  "Ask the Grail WWW browser to load URL.
-Default to the URL around or before point.  Runs the program in the
-variable `browse-url-grail'."
-  (interactive (browse-url-interactive-arg "Grail URL: "))
-  (message "Sending URL to Grail...")
-  (with-current-buffer (get-buffer-create " *Shell Command Output*")
-    (erase-buffer)
-    ;; don't worry about this failing.
-    (if (browse-url-maybe-new-window new-window)
-       (call-process browse-url-grail nil 0 nil "-b" url)
-      (call-process browse-url-grail nil 0 nil url))
-    (message "Sending URL to Grail... done")))
-
 ;; --- Mosaic using CCI ---
 
 ;;;###autoload
@@ -1310,19 +1280,12 @@ used instead of `browse-url-new-window-flag'."
   (process-send-string "browse-url" "disconnect\r\n")
   (delete-process "browse-url"))
 
-;; --- IXI Mosaic ---
-
-;;;###autoload
-(defun browse-url-iximosaic (url &optional new-window)
-  ;; new-window ignored
-  "Ask the IXIMosaic WWW browser to load URL.
-Default to the URL around or before point."
-  (interactive (browse-url-interactive-arg "IXI Mosaic URL: "))
-  (start-process "tellw3b" nil "tellw3b"
-                "-service WWW_BROWSER ixi_showurl " url))
-
 ;; --- W3 ---
 
+;; External.
+(declare-function w3-fetch-other-window "ext:w3m" (&optional url))
+(declare-function w3-fetch              "ext:w3m" (&optional url target))
+
 ;;;###autoload
 (defun browse-url-w3 (url &optional new-window)
   "Ask the w3 WWW browser to load URL.
@@ -1356,38 +1319,41 @@ The `browse-url-gnudoit-program' program is used with options given by
 ;; --- Lynx in an xterm ---
 
 ;;;###autoload
-(defun browse-url-lynx-xterm (url &optional new-window)
+(defun browse-url-text-xterm (url &optional new-window)
   ;; new-window ignored
-  "Ask the Lynx WWW browser to load URL.
-Default to the URL around or before point.  A new Lynx process is run
+  "Ask a text browser to load URL.
+URL defaults to the URL around or before point.
+This runs the text browser specified by `browse-url-text-browser'.
 in an Xterm window using the Xterm program named by `browse-url-xterm-program'
 with possible additional arguments `browse-url-xterm-args'."
-  (interactive (browse-url-interactive-arg "Lynx URL: "))
-  (apply #'start-process `(,(concat "lynx" url) nil ,browse-url-xterm-program
-                          ,@browse-url-xterm-args "-e" "lynx"
+  (interactive (browse-url-interactive-arg "Text browser URL: "))
+  (apply #'start-process `(,(concat browse-url-text-browser url)
+                          nil ,browse-url-xterm-program
+                          ,@browse-url-xterm-args "-e" ,browse-url-text-browser
                           ,url)))
 
 ;; --- Lynx in an Emacs "term" window ---
 
 ;;;###autoload
-(defun browse-url-lynx-emacs (url &optional new-buffer)
-  "Ask the Lynx WWW browser to load URL.
-Default to the URL around or before point.  With a prefix argument, run
-a new Lynx process in a new buffer.
+(defun browse-url-text-emacs (url &optional new-buffer)
+  "Ask a text browser to load URL.
+URL defaults to the URL around or before point.
+This runs the text browser specified by `browse-url-text-browser'.
+With a prefix argument, it runs a new browser process in a new buffer.
 
 When called interactively, if variable `browse-url-new-window-flag' is
-non-nil, load the document in a new lynx in a new term window,
+non-nil, load the document in a new browser process in a new term window,
 otherwise use any existing one.  A non-nil interactive prefix argument
 reverses the effect of `browse-url-new-window-flag'.
 
 When called non-interactively, optional second argument NEW-WINDOW is
 used instead of `browse-url-new-window-flag'."
-  (interactive (browse-url-interactive-arg "Lynx URL: "))
+  (interactive (browse-url-interactive-arg "Text browser URL: "))
   (let* ((system-uses-terminfo t)     ; Lynx uses terminfo
         ;; (term-term-name "vt100") ; ??
-        (buf (get-buffer "*lynx*"))
+        (buf (get-buffer "*text browser*"))
         (proc (and buf (get-buffer-process buf)))
-        (n browse-url-lynx-input-attempts))
+        (n browse-url-text-input-attempts))
     (if (and (browse-url-maybe-new-window new-buffer) buf)
        ;; Rename away the OLD buffer. This isn't very polite, but
        ;; term insists on working in a buffer named *lynx* and would
@@ -1398,11 +1364,13 @@ used instead of `browse-url-new-window-flag'."
            (not buf)
            (not proc)
            (not (memq (process-status proc) '(run stop))))
-       ;; start a new lynx
+       ;; start a new text browser
        (progn
           (setq buf
                 (apply #'make-term
-                       `("lynx" "lynx" nil ,@browse-url-lynx-emacs-args
+                       `(,browse-url-text-browser
+                        ,browse-url-text-browser
+                        nil ,@browse-url-text-emacs-args
                         ,url)))
           (switch-to-buffer buf)
           (term-char-mode)
@@ -1414,18 +1382,18 @@ used instead of `browse-url-new-window-flag'."
              (if (not (memq (process-status process) '(run stop)))
                  (let ((buf (process-buffer process)))
                    (if buf (kill-buffer buf)))))))
-      ;; send the url to lynx in the old buffer
+      ;; Send the url to the text browser in the old buffer
       (let ((win (get-buffer-window buf t)))
        (if win
            (select-window win)
          (switch-to-buffer buf)))
       (if (eq (following-char) ?_)
-         (cond ((eq browse-url-lynx-input-field 'warn)
+         (cond ((eq browse-url-text-input-field 'warn)
                 (error "Please move out of the input field first"))
-               ((eq browse-url-lynx-input-field 'avoid)
+               ((eq browse-url-text-input-field 'avoid)
                 (while (and (eq (following-char) ?_) (> n 0))
                   (term-send-down)     ; down arrow
-                  (sit-for browse-url-lynx-input-delay))
+                  (sit-for browse-url-text-input-delay))
                 (if (eq (following-char) ?_)
                     (error "Cannot move out of the input field, sorry")))))
       (term-send-string proc (concat "g"    ; goto
@@ -1433,24 +1401,6 @@ used instead of `browse-url-new-window-flag'."
                                     url
                                     "\r")))))
 
-;; --- MMM ---
-
-;;;###autoload
-(defun browse-url-mmm (url &optional new-window)
-  "Ask the MMM WWW browser to load URL.
-Default to the URL around or before point."
-  (interactive (browse-url-interactive-arg "MMM URL: "))
-  (message "Sending URL to MMM...")
-  (with-current-buffer (get-buffer-create " *Shell Command Output*")
-    (erase-buffer)
-    ;; mmm_remote just SEGVs if the file isn't there...
-    (if (or (file-exists-p (expand-file-name "~/.mmm_remote"))
-           ;; location in v 0.4:
-           (file-exists-p (expand-file-name "~/.mmm/remote")))
-       (call-process "mmm_remote" nil 0 nil url)
-      (call-process "mmm" nil 0 nil "-external" url))
-    (message "Sending URL to MMM... done")))
-
 ;; --- mailto ---
 
 (autoload 'rfc2368-parse-mailto-url "rfc2368")
@@ -1519,7 +1469,7 @@ Default to the URL around or before point."
 
 (defun browse-url-elinks-new-window (url)
   "Ask the Elinks WWW browser to load URL in a new window."
-  (let ((process-environment (browse-url-process-environment)))     
+  (let ((process-environment (browse-url-process-environment)))
     (apply #'start-process
           (append (list (concat "elinks:" url)
                         nil)