]> code.delx.au - gnu-emacs/blobdiff - lisp/browse-url.el
(backup-extract-version-start): New variable.
[gnu-emacs] / lisp / browse-url.el
index cc51a9a6bfaede9b6e79a347fb1f599d9a24cd1e..2f6012c68dfd3d1048a307393593a864852db10f 100644 (file)
 
 ;; Do any other browsers have remote control?
 
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Installation
-
-;; Put the following in your ~/.emacs file:
-;;
-;; (autoload 'browse-url-at-point "browse-url"
-;;   "Ask a WWW browser to load the URL at or before point." t)
-;; (autoload 'browse-url-at-mouse "browse-url"
-;;   "Ask a WWW browser to load a URL clicked with the mouse." t)
-;; (autoload 'browse-url-of-buffer "browse-url"
-;;   "Ask a WWW browser to display BUFFER." t)
-;; (autoload 'browse-url-of-file "browse-url"
-;;   "Ask a WWW browser to display FILE." t)
-;; (autoload 'browse-url-of-dired-file "browse-url"
-;;   "In Dired, ask a WWW browser to display the file named on this line." t)
-
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Usage
 
@@ -305,33 +289,50 @@ Hostname matching is stricter in this case than for
    browse-url-path-regexp)
   "A regular expression probably matching a complete URL.")
 
+;;;###autoload
+(defgroup browse-url nil
+  "Use a web browser to look at a URL."
+  :group 'emacs)
 
 ;;;###autoload
-(defvar browse-url-browser-function
+(defcustom browse-url-browser-function
   'browse-url-netscape
   "*Function to display the current buffer in a WWW browser.
-Used by the `browse-url-at-point', `browse-url-at-mouse', and
-`browse-url-of-file' commands.")
-
-(defvar browse-url-netscape-command "netscape"
-  "*The name by which to invoke Netscape.")
-
-(defvar browse-url-netscape-arguments nil
-  "*A list of strings to pass to Netscape as arguments.")
-
-(defvar browse-url-netscape-startup-arguments browse-url-netscape-arguments
+This is used by the `browse-url-at-point', `browse-url-at-mouse', and
+`browse-url-of-file' commands.
+The function should take one argument, an URL."
+  :type 'function
+  :group 'browse-url)
+
+(defcustom browse-url-netscape-program "netscape"
+  "*The name by which to invoke Netscape."
+  :type 'string
+  :group 'browse-url)
+
+(defcustom browse-url-netscape-arguments nil
+  "*A list of strings to pass to Netscape as arguments."
+  :type '(repeat (string :tag "Argument"))
+  :group 'browse-url)
+
+(defcustom browse-url-netscape-startup-arguments browse-url-netscape-arguments
   "*A list of strings to pass to Netscape when it starts up.
-Defaults to the value of browse-url-netscape-arguments at the time
-browse-url is loaded.")
+Defaults to the value of `browse-url-netscape-arguments' at the time
+browse-url is loaded."
+  :type '(repeat (string :tag "Argument"))
+  :group 'browse-url)
 
-(defvar browse-url-new-window-p nil
+(defcustom browse-url-new-window-p nil
   "*If non-nil, always open a new browser window.
 Passing an interactive argument to \\[browse-url-netscape] or
 \\[browse-url-cci] reverses the effect of this variable.  Requires
-Netscape version 1.1N or later or XMosaic version 2.5 or later.")
+Netscape version 1.1N or later or XMosaic version 2.5 or later."
+  :type 'boolean
+  :group 'browse-url)
 
-(defvar browse-url-mosaic-arguments nil
-  "*A list of strings to pass to Mosaic as arguments.")
+(defcustom browse-url-mosaic-arguments nil
+  "*A list of strings to pass to Mosaic as arguments."
+  :type '(repeat (string :tag "Argument"))
+  :group 'browse-url)
 
 (defvar browse-url-filename-alist
   '(("^/+" . "file:/"))
@@ -384,32 +385,12 @@ enabled.  The port number should be set in `browse-url-CCI-port'.")
 (defun browse-url-url-at-point ()
   "Return the URL around or before point.
 Search backwards for the start of a URL ending at or after 
-point.  If no URL found, return the empty string.  The
-access scheme, `http://' will be prepended if absent."
-  (cond ((browse-url-looking-at browse-url-regexp)
-        (buffer-substring (match-beginning 0) (match-end 0)))
-       ;; Access scheme omitted?
-       ((browse-url-looking-at browse-url-short-regexp)
-        (concat "http://"
-                (buffer-substring (match-beginning 0) (match-end 0))))
-       (t "")))                        ; No match
-
-(defun browse-url-looking-at (regexp)
-  "Return non-nil if point is in or just after a match for REGEXP.
-Set the match data from the earliest such match in the current line
-ending at or after point."
-  (save-excursion
-    (let ((old-point (point))
-         (eol (progn (end-of-line) (point)))
-         (hit nil))
-      (beginning-of-line)
-      (or (and (looking-at regexp)
-              (>= (match-end 0) old-point))
-         (progn
-           (while (and (re-search-forward regexp eol t)
-                       (<= (match-beginning 0) old-point)
-                       (not (setq hit (>= (match-end 0) old-point)))))
-           hit)))))
+point.  If no URL found, return the empty string.
+A file name is also acceptable, and `http://' will be prepended to it."
+  (or (thing-at-point 'url)
+      (let ((file (thing-at-point 'filename)))
+       (if file (concat "http://" file)))
+      ""))
 
 ;; Having this as a separate function called by the browser-specific
 ;; functions allows them to be stand-alone commands, making it easier
@@ -430,6 +411,7 @@ negation if a prefix argument was given."
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Browse current buffer
 
+;;;###autoload
 (defun browse-url-of-file (&optional file)
   "Ask a WWW browser to display FILE.
 Display the current buffer's file if FILE is nil or if called
@@ -477,6 +459,7 @@ Convert EFS file names of the form /USER@HOST:PATH to ftp://HOST/PATH."
                          "/" (substring file (match-end 0)))))
   file)
 
+;;;###autoload
 (defun browse-url-of-buffer (&optional buffer)
   "Ask a WWW browser to display BUFFER.
 Display the current buffer if BUFFER is nil."
@@ -524,6 +507,7 @@ Display the current buffer if BUFFER is nil."
 (add-hook 'kill-buffer-hook 'browse-url-delete-temp-file)
 (add-hook 'kill-emacs-hook 'browse-url-delete-temp-file-list)
 
+;;;###autoload
 (defun browse-url-of-dired-file ()
   "In Dired, ask a WWW browser to display the file named on this line."
   (interactive)
@@ -541,6 +525,7 @@ Prompts for a URL, defaulting to the URL at or before point.  Variable
   (interactive (browse-url-interactive-arg "URL: "))
   (apply browse-url-browser-function args))
 
+;;;###autoload
 (defun browse-url-at-point ()
   "Ask a WWW browser to load the URL at or before point.
 Doesn't let you edit the URL like browse-url.  Variable
@@ -560,6 +545,7 @@ Doesn't let you edit the URL like browse-url.  Variable
       (defun event-point (event)
        (posn-point (event-start event)))))
 
+;;;###autoload
 (defun browse-url-at-mouse (event)
   "Ask a WWW browser to load a URL clicked with the mouse.
 The URL is the one around or before the position of the mouse click