From: Reuben Thomas <rrt@sc3d.org>
Cc: bug-gnu-emacs@gnu.org, Simon Josefsson <jas@extundo.com>
Subject: Re: [Reuben Thomas] browse-url.el Opera support
Date: Sat, 17 Jan 2004 16:27:17 +0100 (CET) [thread overview]
Message-ID: <Pine.LNX.4.58.0401171616070.1565@mnemosyne> (raw)
In-Reply-To: <rzq7jzrfmz4.fsf@albion.dl.ac.uk>
[-- Attachment #1: Type: TEXT/PLAIN, Size: 2328 bytes --]
> I don't understand `several kb of script'
I was looking at the length of browse-url.el. I now see that a lot of it
isn't just calling browsers, but the bit that is (especially the support
for particular browsers) is embarrassingly long.
> The current mechanism would have been junked if I'd been able to
> continue maintaining browse-url.
I've had a go at reworking browse-url-generic to be useful with more
browsers and simpler to customise.
> In most cases, I'd hope you wouldn't have to configure anything.
:-) Well, browse-url already defaults to htmlview for the generic browser,
which works well for me.
OK, I attach a preliminary rework of browse-url.el. I've done three main
things:
1. In line with what RMS said elsewhere, I've removed support for non-free
browsers. Most of the code in this category was to support old versions of
Netscape. Mozilla and new versions of Netscape are adequately supported by
my new implementation of browse-url-generic.
2. I've removed support for other browsers that can be supported by my new
browse-url-generic, e.g. MMM, Grail, Lynx-in-xterm.
3. I've rewritten browse-url-generic so that browse-url-generic-args is a
string, not a list (I've not redone the other browser support code to be
consistent with this; perhaps it's not worthwhile or even
counterproductive). This string may contain the token __URL__; if so, the
URL given is substituted for it. Otherwise, the URL is added as an extra
final argument. The string is split at spaces to be passed to
start-process.
The reason for using a string rather than a list of args is that it's
easier for users to configure. Slightly more careful parsing of the string
(e.g. respecting quotes when splitting it into individual args) would
solve most remaining problems with that approach.
I'm also sorely tempted to remove the special support for Mosaic, as it's
long and the program is obsolete, but perhaps there are enough users on
older hardware who don't have alternative more modern browsers.
The version of browse-url.el I attach is a modified version of that
supplied with Emacs 21.3.1, and all the modifications are by me (I didn't
use any of the XEmacs code I mentioned before). It's also a little under
half the size of the 21.3.1 version.
--
http://www.mupsych.org/~rrt/ | Floc: an egregiously good aperitif
[-- Attachment #2: Type: TEXT/PLAIN, Size: 32103 bytes --]
;;; browse-url.el --- pass a URL to a WWW browser
;; Copyright (C) 1995, 96, 97, 98, 99, 2000, 2001
;; Free Software Foundation, Inc.
;; Author: Denis Howe <dbh@doc.ic.ac.uk>
;; Maintainer: Dave Love <fx@gnu.org>
;; Created: 03 Apr 1995
;; Keywords: hypertext, hypermedia, mouse
;; This file is part of GNU Emacs.
;; 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 2, 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
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; 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., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
;;; Commentary:
;; This package provides functions which read a URL (Uniform Resource
;; Locator) from the minibuffer, defaulting to the URL around point,
;; and ask a World-Wide Web browser to load it. It can also load the
;; URL associated with the current buffer. Different browsers use
;; different methods of remote control so there is one function for
;; each supported browser. If the chosen browser is not running, it
;; is started. Currently there is support for the following browsers,
;; some of them probably now obsolete:
;; Function Browser Earliest version
;; browse-url-mosaic XMosaic/mMosaic <= 2.4
;; browse-url-cci XMosaic 2.5
;; browse-url-w3 w3 0
;; browse-url-w3-gnudoit w3 remotely
;; browse-url-lynx-emacs Lynx 0
;; browse-url-generic arbitrary
;; browse-url-default-windows-browser MS-Windows browser
;; browse-url-gnome-moz GNOME interface to Mozilla
;; Browsers can cache Web pages so it may be necessary to tell them to
;; reload the current page if it has changed (e.g. if you have edited
;; it). There is currently no perfect automatic solution to this.
;; If using XMosaic before version 2.5, check the definition of
;; browse-url-usr1-signal below.
;; <URL:http://www.ncsa.uiuc.edu/SDG/Software/XMosaic/remote-control.html>
;; XMosaic version 2.5 introduced Common Client Interface allowing you
;; to control mosaic through Unix sockets.
;; <URL:http://www.ncsa.uiuc.edu/SDG/Software/XMosaic/CCI/cci-spec.html>
;; William M. Perry's excellent "w3" WWW browser for
;; Emacs <URL:ftp://cs.indiana.edu/pub/elisp/w3/>
;; has a function w3-follow-url-at-point, but that
;; doesn't let you edit the URL like browse-url.
;; The `gnuserv' package that can be used to control it in another
;; Emacs process is available from
;; <URL:ftp://ftp.splode.com/pub/users/friedman/packages/>.
;; Lynx is now distributed by the FSF. See also
;; <URL:http://lynx.browser.org/>.
;; Free graphical browsers that could be used by `browse-url-generic'
;; include Chimera <URL:ftp://ftp.cs.unlv.edu/pub/chimera> and
;; <URL:http://www.unlv.edu/chimera/>, Arena
;; <URL:ftp://ftp.yggdrasil.com/pub/dist/web/arena>, Grail
;; <URL:http://grail.sourceforge.net/>, and Amaya
;; <URL:ftp://ftp.w3.org/pub/amaya>. mMosaic
;; <URL:ftp://ftp.enst.fr/pub/mbone/mMosaic/>,
;; <URL:http://perso.enst.fr/~dauphin/mMosaic/> (with development
;; support for Java applets and multicast) can be used like Mosaic by
;; setting `browse-url-mosaic-program' appropriately.
;; I [Denis Howe, not Dave Love] recommend Nelson Minar
;; <nelson@santafe.edu>'s excellent html-helper-mode.el for editing
;; HTML and thank Nelson for his many useful comments on this code.
;; <URL:http://www.santafe.edu/%7Enelson/hhm-beta/>
;; See also hm--html-menus <URL:http://www.tnt.uni-hannover.de/%7Emuenkel/
;; software/own/hm--html-menus/>. For composing correct HTML see also
;; PSGML the general SGML structure editor package
;; <URL:ftp://ftp.lysator.liu.se/pub/sgml>; hm--html-menus can be used
;; with this.
;; This package generalises function html-previewer-process in Marc
;; Andreessen's html-mode (LCD modes/html-mode.el.Z). See also the
;; ffap.el package. The huge hyperbole package also contains similar
;; functions.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Help!
;; Can you write and test some code for the Macintosh and Windows
;; Mozilla remote control APIs? (See the URL above).
;; Do any other browsers have remote control?
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Usage
;; To display the URL at or before point:
;; M-x browse-url-at-point RET
;; or, similarly but with the opportunity to edit the URL extracted from
;; the buffer, use:
;; M-x browse-url
;; To display a URL by shift-clicking on it, put this in your ~/.emacs
;; file:
;; (global-set-key [S-mouse-2] 'browse-url-at-mouse)
;; (Note that using Shift-mouse-1 is not desirable because
;; that event has a standard meaning in Emacs.)
;; To display the current buffer in a web browser:
;; M-x browse-url-of-buffer RET
;; To display the current region in a web browser:
;; M-x browse-url-of-region RET
;; In Dired, to display the file named on the current line:
;; M-x browse-url-of-dired-file RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Customisation (~/.emacs)
;; To see what variables are available for customization, type
;; `M-x set-variable browse-url TAB'. Better, use
;; `M-x customize-group browse-url'.
;; Bind the browse-url commands to keys with the `C-c C-z' prefix
;; (as used by html-helper-mode):
;; (global-set-key "\C-c\C-z." 'browse-url-at-point)
;; (global-set-key "\C-c\C-zb" 'browse-url-of-buffer)
;; (global-set-key "\C-c\C-zr" 'browse-url-of-region)
;; (global-set-key "\C-c\C-zu" 'browse-url)
;; (global-set-key "\C-c\C-zv" 'browse-url-of-file)
;; (add-hook 'dired-mode-hook
;; (lambda ()
;; (local-set-key "\C-c\C-zf" 'browse-url-of-dired-file)))
;; Browse URLs in mail messages under RMAIL by clicking mouse-2:
;; (add-hook 'rmail-mode-hook (lambda () ; rmail-mode startup
;; (define-key rmail-mode-map [mouse-2] 'browse-url-at-mouse)))
;; Alternatively, add `goto-address' to `rmail-show-message-hook'.
;; Gnus provides a standard feature to activate URLs in article
;; buffers for invocation of browse-url.
;; Use the Emacs w3 browser when not running under X11:
;; (or (eq window-system 'x)
;; (setq browse-url-browser-function 'browse-url-w3))
;; To always save modified buffers before displaying the file in a browser:
;; (setq browse-url-save-file t)
;; To invoke different browsers for different URLs:
;; (setq browse-url-browser-function '(("^mailto:" . browse-url-mail)
;; ("." . browse-url-generic)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Variables
(eval-when-compile (require 'thingatpt)
(require 'term)
(require 'dired)
(require 'w3-auto nil t))
(defgroup browse-url nil
"Use a web browser to look at a URL."
:prefix "browse-url-"
:link '(emacs-commentary-link "browse-url")
:group 'hypermedia)
;;;###autoload
(defcustom browse-url-browser-function
(if (memq system-type '(windows-nt ms-dos))
'browse-url-default-windows-browser
'browse-url-generic)
"*Function to display the current buffer in a WWW browser.
This is used by the `browse-url-at-point', `browse-url-at-mouse', and
`browse-url-of-file' commands.
If the value is not a function it should be a list of pairs
\(REGEXP . FUNCTION). In this case the function called will be the one
associated with the first REGEXP which matches the current URL. The
function is passed the URL and any other args of `browse-url'. The last
regexp should probably be \".\" to specify a default browser."
:type '(choice
(function-item :tag "Emacs W3" :value browse-url-w3)
(function-item :tag "W3 in another Emacs via `gnudoit'"
:value browse-url-w3-gnudoit)
(function-item :tag "Mosaic" :value browse-url-mosaic)
(function-item :tag "Mosaic using CCI" :value browse-url-cci)
(function-item :tag "Lynx in an Emacs window"
:value browse-url-lynx-emacs)
(function-item :tag "Specified by `Browse Url Generic Program'"
:value browse-url-generic)
(function-item :tag "Default Windows browser"
:value browse-url-default-windows-browser)
(function :tag "Your own function")
(alist :tag "Regexp/function association list"
:key-type regexp :value-type function))
:version "21.1"
:group 'browse-url)
;;;###autoload
(defcustom browse-url-new-window-flag nil
"*If non-nil, always open a new browser window with appropriate browsers.
Passing an interactive argument to \\[browse-url], or specific browser
commands reverses the effect of this variable. Requires Netscape version
1.1N or later or XMosaic version 2.5 or later if using those browsers."
:type 'boolean
:group 'browse-url)
(defcustom browse-url-mosaic-program "xmosaic"
"The name by which to invoke Mosaic (or mMosaic)."
:type 'string
:version "20.3"
:group 'browse-url)
(defcustom browse-url-mosaic-arguments nil
"A list of strings to pass to Mosaic as arguments."
:type '(repeat (string :tag "Argument"))
:group 'browse-url)
(defcustom browse-url-filename-alist
(\` ; Backquote syntax won't work.
(("^/\\(ftp@\\|anonymous@\\)?\\([^:]+\\):/*" . "ftp://\\2/")
;; The above loses the username to avoid the browser prompting for
;; it in anonymous cases. If it's not anonymous the next regexp
;; applies.
("^/\\([^:@]+@\\)?\\([^:]+\\):/*" . "ftp://\\1\\2/")
(,@ (if (memq system-type '(windows-nt ms-dos))
'(("^\\([a-zA-Z]:\\)[\\/]" . "file:\\1/")
("^[\\/][\\/]+" . "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
literally. All pairs are applied in the order given. The default
value converts ange-ftp/EFS-style paths into ftp URLs and prepends
`file:' to any path beginning with `/'.
For example, adding to the default a specific translation of an ange-ftp
address to an HTTP URL:
(setq browse-url-filename-alist
'((\"/webmaster@webserver:/home/www/html/\" .
\"http://www.acme.co.uk/\")
(\"^/\\(ftp@\\|anonymous@\\)?\\([^:]+\\):/*\" . \"ftp://\\2/\")
(\"^/\\([^:@]+@\\)?\\([^:]+\\):/*\" . \"ftp://\\1\\2/\")
(\"^/+\" . \"file:/\")))
"
:type '(repeat (cons :format "%v"
(regexp :tag "Regexp")
(string :tag "Replacement")))
:version "20.3"
:group 'browse-url)
;;;###autoload
(defcustom browse-url-save-file nil
"*If non-nil, save the buffer before displaying its file.
Used by the `browse-url-of-file' command."
:type 'boolean
:group 'browse-url)
(defcustom browse-url-of-file-hook nil
"Run after `browse-url-of-file' has asked a browser to load a file."
:type 'hook
:group 'browse-url)
(defvar browse-url-usr1-signal
(if (and (boundp 'emacs-major-version)
(or (> emacs-major-version 19) (>= emacs-minor-version 29)))
'SIGUSR1 ; Why did I think this was in lower case before?
30) ; Check /usr/include/signal.h.
"The argument to `signal-process' for sending SIGUSR1 to XMosaic.
Emacs 19.29 accepts 'SIGUSR1, earlier versions require an integer
which is 30 on SunOS and 16 on HP-UX and Solaris.")
(defcustom browse-url-CCI-port 3003
"Port to access XMosaic via CCI.
This can be any number between 1024 and 65535 but must correspond to
the value set in the browser."
:type 'integer
:group 'browse-url)
(defcustom browse-url-CCI-host "localhost"
"*Host to access XMosaic via CCI.
This should be the host name of the machine running XMosaic with CCI
enabled. The port number should be set in `browse-url-CCI-port'."
:type 'string
:group 'browse-url)
(defvar browse-url-temp-file-name nil)
(make-variable-buffer-local 'browse-url-temp-file-name)
(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
:group 'browse-url)
(defcustom browse-url-gnudoit-args '("-q")
"*A list of strings defining options for `browse-url-gnudoit-program'.
These might set the port, for instance."
:type '(repeat (string :tag "Argument"))
:group 'browse-url)
;;;###autoload
(defcustom browse-url-generic-program "htmlview"
"*The name of the browser program used by `browse-url-generic'."
:type '(choice string (const :tag "None" nil))
:group 'browse-url)
(defcustom browse-url-generic-args ""
"*A string defining options for `browse-url-generic-program'."
:type 'string
:group 'browse-url)
(defcustom browse-url-temp-dir temporary-file-directory
"The name of a directory for browse-url's temporary files.
Such files are generated by functions like `browse-url-of-region'.
You might want to set this to somewhere with restricted read permissions
for privacy's sake."
:type 'string
: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
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
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"
:group 'browse-url)
(defvar browse-url-lynx-input-attempts 10
"*How many times to try to move down from a series of lynx input fields.")
(defcustom browse-url-lynx-input-delay 0.2
"How many seconds to wait for lynx between moves down from an input field.")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; URL input
(defun browse-url-url-at-point ()
(let ((url (thing-at-point 'url)))
(set-text-properties 0 (length url) nil url)
url))
;; Having this as a separate function called by the browser-specific
;; functions allows them to be stand-alone commands, making it easier
;; to switch between browsers.
(defun browse-url-interactive-arg (prompt)
"Read a URL from the minibuffer, prompting with PROMPT.
Default to the URL at or before point. If invoked with a mouse button,
set point to the position clicked first. Return a list for use in
`interactive' containing the URL and `browse-url-new-window-flag' or its
negation if a prefix argument was given."
(let ((event (elt (this-command-keys) 0)))
(and (listp event) (mouse-set-point event)))
(list (read-string prompt (browse-url-url-at-point))
(not (eq (null browse-url-new-window-flag)
(null current-prefix-arg)))))
;; interactive-p needs to be called at a function's top-level, hence
;; the macro.
(defmacro browse-url-maybe-new-window (arg)
`(if (interactive-p)
,arg
browse-url-new-window-flag))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 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
interactively. Turn the filename into a URL with function
`browse-url-file-url'. Pass the URL to a browser using the
`browse-url' function then run `browse-url-of-file-hook'."
(interactive)
(or file
(setq file (buffer-file-name))
(error "Current buffer has no file"))
(let ((buf (get-file-buffer file)))
(if buf
(save-excursion
(set-buffer buf)
(cond ((not (buffer-modified-p)))
(browse-url-save-file (save-buffer))
(t (message "%s modified since last save" file))))))
(browse-url (browse-url-file-url file))
(run-hooks 'browse-url-of-file-hook))
(defun browse-url-file-url (file)
"Return the URL corresponding to FILE.
Use variable `browse-url-filename-alist' to map filenames to URLs."
;; URL-encode special chars, do % first
(let ((s 0))
(while (setq s (string-match "%" file s))
(setq file (replace-match "%25" t t file)
s (1+ s))))
(while (string-match "[*\"()',=;? ]" file)
(let ((enc (format "%%%x" (aref file (match-beginning 0)))))
(setq file (replace-match enc t t file))))
(dolist (map browse-url-filename-alist)
(when (and map (string-match (car map) file))
(setq file (replace-match (cdr map) t nil file))))
file)
;;;###autoload
(defun browse-url-of-buffer (&optional buffer)
"Ask a WWW browser to display BUFFER.
Display the current buffer if BUFFER is nil. Display only the
currently visible part of BUFFER (from a temporary file) if buffer is
narrowed."
(interactive)
(save-excursion
(and buffer (set-buffer buffer))
(let ((file-name
;; Ignore real name if restricted
(and (= (- (point-max) (point-min)) (buffer-size))
(or buffer-file-name
(and (boundp 'dired-directory) dired-directory)))))
(or file-name
(progn
(or browse-url-temp-file-name
(setq browse-url-temp-file-name
(convert-standard-filename
(make-temp-file
(expand-file-name "burl" browse-url-temp-dir)))))
(setq file-name browse-url-temp-file-name)
(write-region (point-min) (point-max) file-name nil 'no-message)))
(browse-url-of-file file-name))))
(defun browse-url-delete-temp-file (&optional temp-file-name)
;; Delete browse-url-temp-file-name from the file system
;; If optional arg TEMP-FILE-NAME is non-nil, delete it instead
(let ((file-name (or temp-file-name browse-url-temp-file-name)))
(if (and file-name (file-exists-p file-name))
(delete-file file-name))))
(add-hook 'kill-buffer-hook 'browse-url-delete-temp-file)
;;;###autoload
(defun browse-url-of-dired-file ()
"In Dired, ask a WWW browser to display the file named on this line."
(interactive)
(browse-url-of-file (dired-get-filename)))
;;;###autoload
(defun browse-url-of-region (min max)
"Ask a WWW browser to display the current region."
(interactive "r")
(save-excursion
(save-restriction
(narrow-to-region min max)
(browse-url-of-buffer))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Browser-independent commands
;; A generic command to call the current browse-url-browser-function
;;;###autoload
(defun browse-url (url &rest args)
"Ask a WWW browser to load URL.
Prompts for a URL, defaulting to the URL at or before point. Variable
`browse-url-browser-function' says which browser to use."
(interactive (browse-url-interactive-arg "URL: "))
(unless (interactive-p)
(setq args (or args (list browse-url-new-window-flag))))
(if (functionp browse-url-browser-function)
(apply browse-url-browser-function url args)
;; The `function' can be an alist; look down it for first match
;; and apply the function (which might be a lambda).
(catch 'done
(dolist (bf browse-url-browser-function)
(when (string-match (car bf) url)
(apply (cdr bf) url args)
(throw 'done t)))
(error "No browse-url-browser-function matching URL %s"
url))))
;;;###autoload
(defun browse-url-at-point (&optional arg)
"Ask a WWW browser to load the URL at or before point.
Doesn't let you edit the URL like `browse-url'. Variable
`browse-url-browser-function' says which browser to use."
(interactive "P")
(let ((url (browse-url-url-at-point)))
(if url
(browse-url url (if arg
(not browse-url-new-window-flag)
browse-url-new-window-flag))
(error "No URL found"))))
;;;###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
but point is not changed. Doesn't let you edit the URL like
`browse-url'. Variable `browse-url-browser-function' says which browser
to use."
(interactive "e")
(save-excursion
(mouse-set-point event)
;; This handles browse-url-new-window-flag properly
;; when it gets no arg.
(browse-url-at-point)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Browser-specific commands
;; --- Default MS-Windows browser ---
(defun browse-url-default-windows-browser (url &optional new-window)
(interactive (browse-url-interactive-arg "URL: "))
(if (eq system-type 'ms-dos)
(if dos-windows-version
(shell-command (concat "start " (shell-quote-argument url)))
(error "Browsing URLs is not supported on this system"))
(w32-shell-execute "open" url)))
;;;###autoload
(defun browse-url-mosaic (url &optional new-window)
"Ask the XMosaic WWW browser to load URL.
Default to the URL around or before point. The strings in variable
`browse-url-mosaic-arguments' are also passed to Mosaic and the
program is invoked according to the variable
`browse-url-mosaic-program'.
When called interactively, if variable `browse-url-new-window-flag' is
non-nil, load the document in a new Mosaic window, otherwise use a
random 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 "Mosaic URL: "))
(let ((pidfile (expand-file-name "~/.mosaicpid"))
pid)
(if (file-readable-p pidfile)
(save-excursion
(find-file pidfile)
(goto-char (point-min))
(setq pid (read (current-buffer)))
(kill-buffer nil)))
(if (and pid (zerop (signal-process pid 0))) ; Mosaic running
(save-excursion
(find-file (format "/tmp/Mosaic.%d" pid))
(erase-buffer)
(insert (if (browse-url-maybe-new-window new-window)
"newwin\n"
"goto\n")
url "\n")
(save-buffer)
(kill-buffer nil)
;; Send signal SIGUSR to Mosaic
(message "Signalling Mosaic...")
(signal-process pid browse-url-usr1-signal)
;; Or you could try:
;; (call-process "kill" nil 0 nil "-USR1" (int-to-string pid))
(message "Signalling Mosaic...done")
)
;; Mosaic not running - start it
(message "Starting Mosaic...")
(apply 'start-process "xmosaic" nil browse-url-mosaic-program
(append browse-url-mosaic-arguments (list url)))
(message "Starting Mosaic...done"))))
;; --- Mosaic using CCI ---
;;;###autoload
(defun browse-url-cci (url &optional new-window)
"Ask the XMosaic WWW browser to load URL.
Default to the URL around or before point.
This function only works for XMosaic version 2.5 or later. You must
select `CCI' from XMosaic's File menu, set the CCI Port Address to the
value of variable `browse-url-CCI-port', and enable `Accept requests'.
When called interactively, if variable `browse-url-new-window-flag' is
non-nil, load the document in a new browser window, otherwise use a
random 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 "Mosaic URL: "))
(open-network-stream "browse-url" " *browse-url*"
browse-url-CCI-host browse-url-CCI-port)
;; Todo: start browser if fails
(process-send-string "browse-url"
(concat "get url (" url ") output "
(if (browse-url-maybe-new-window new-window)
"new"
"current")
"\r\n"))
(process-send-string "browse-url" "disconnect\r\n")
(delete-process "browse-url"))
;; --- W3 ---
;;;###autoload
(defun browse-url-w3 (url &optional new-window)
"Ask the w3 WWW browser to load URL.
Default to the URL around or before point.
When called interactively, if variable `browse-url-new-window-flag' is
non-nil, load the document in a new window. 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 "W3 URL: "))
(require 'w3) ; w3-fetch-other-window not autoloaded
(if (browse-url-maybe-new-window new-window)
(w3-fetch-other-window url)
(w3-fetch url)))
;;;###autoload
(defun browse-url-w3-gnudoit (url &optional new-window)
;; new-window ignored
"Ask another Emacs running gnuserv to load the URL using the W3 browser.
The `browse-url-gnudoit-program' program is used with options given by
`browse-url-gnudoit-args'. Default to the URL around or before point."
(interactive (browse-url-interactive-arg "W3 URL: "))
(apply 'start-process (concat "gnudoit:" url) nil
browse-url-gnudoit-program
(append browse-url-gnudoit-args
(list (concat "(w3-fetch \"" url "\")")
"(raise-frame)"))))
;; --- 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.
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,
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: "))
(let* ((system-uses-terminfo t) ; Lynx uses terminfo
;; (term-term-name "vt100") ; ??
(buf (get-buffer "*lynx*"))
(proc (and buf (get-buffer-process buf)))
(n browse-url-lynx-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
;; choke on *lynx*<1>
(progn (set-buffer buf)
(rename-uniquely)))
(if (or (browse-url-maybe-new-window new-buffer)
(not buf)
(not proc)
(not (memq (process-status proc) '(run stop))))
;; start a new lynx
(progn
(setq buf
(apply #'make-term
`("lynx" "lynx" nil ,@browse-url-lynx-emacs-args
,url)))
(switch-to-buffer buf)
(term-char-mode)
(set-process-sentinel
(get-buffer-process buf)
;; Don't leave around a dead one (especially because of its
;; munged keymap.)
(lambda (process event)
(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
(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)
(error "Please move out of the input field first"))
((eq browse-url-lynx-input-field 'avoid)
(while (and (eq (following-char) ?_) (> n 0))
(term-send-down) ; down arrow
(sit-for browse-url-lynx-input-delay))
(if (eq (following-char) ?_)
(error "Cannot move out of the input field, sorry")))))
(term-send-string proc (concat "g" ; goto
"\C-u" ; kill default url
url
"\r")))))
;; --- mailto ---
;;;###autoload
(defun browse-url-mail (url &optional new-window)
"Open a new mail message buffer within Emacs.
Default to using the mailto: URL around or before point as the
recipient's address. Supplying a non-nil interactive prefix argument
will cause the mail to be composed in another window rather than the
current one.
When called interactively, if variable `browse-url-new-window-flag' is
non-nil use `compose-mail-other-window', otherwise `compose-mail'. 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 "Mailto URL: "))
(save-excursion
(let ((to (if (string-match "^mailto:" url)
(substring url 7)
url)))
(if (browse-url-maybe-new-window new-window)
(compose-mail-other-window to nil nil nil
(list 'insert-buffer (current-buffer)))
(compose-mail to nil nil nil nil
(list 'insert-buffer (current-buffer)))))))
;; --- Random browser ---
;;;###autoload
(defun browse-url-generic (url &optional new-window)
;; new-window ignored
"Ask the WWW browser defined by `browse-url-generic-program' to load
URL. Default to the URL around or before point. The arguments passed
are defined by the string `browse-url-generic', in which the URL is
substituted for `__URL__' if it exists, or added as a final argument
if not."
(interactive (browse-url-interactive-arg "URL: "))
(if (not browse-url-generic-program)
(error "No browser defined (`browse-url-generic-program')"))
(let ((args
(if (string-match "__URL__" browse-url-generic-args)
(replace-match url t t browse-url-generic-args)
(concat browse-url-generic-args "" url))))
(apply 'start-process (concat browse-url-generic-program " " url) nil
browse-url-generic-program
(split-string args " "))))
; Values for browse-url-generic-args
;
; These could be put in a list indexed by browser name to allow common
; browsers to be chosen from a list and the method of starting the URL
; (same window, new window, new tab) to be an option.
;
; Browser Same window New window New tab
;
; Opera "" -remote openURL(__URL__,new-window) -remote openURL(__URL__,new-page)
; Konqueror ?? "" ??
; Mozilla -remote openURL(__URL__) -remote openURL(__URL__,new-window) -remote openURL(__URL__,new-tab)
; gnome-moz-remote --raise __URL__ --raise --newwin __URL__ --raise --remote=openURL(__URL__,new-tab)
; lynx-xterm n/a xterm -e lynx __URL__ n/a
(provide 'browse-url)
;;; browse-url.el ends here
[-- Attachment #3: Type: text/plain, Size: 148 bytes --]
_______________________________________________
Bug-gnu-emacs mailing list
Bug-gnu-emacs@gnu.org
http://mail.gnu.org/mailman/listinfo/bug-gnu-emacs
next prev parent reply other threads:[~2004-01-17 15:27 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.693.1074172442.928.bug-gnu-emacs@gnu.org>
2004-01-15 13:48 ` [Reuben Thomas] browse-url.el Opera support Simon Josefsson
2004-01-15 14:12 ` Reuben Thomas
2004-01-15 14:28 ` Simon Josefsson
2004-01-16 19:54 ` Richard Stallman
2004-01-17 15:15 ` Reuben Thomas
2004-01-18 6:32 ` Simon Josefsson
2004-01-18 7:15 ` Reuben Thomas
2004-01-18 22:27 ` Reuben Thomas
2004-01-19 20:12 ` Richard Stallman
2004-01-19 18:35 ` Reuben Thomas
2004-01-19 18:38 ` Reuben Thomas
2004-02-05 15:44 ` Dave Love
2004-02-05 16:09 ` Reuben Thomas
2004-01-18 19:14 ` Richard Stallman
[not found] ` <mailman.829.1074355733.928.bug-gnu-emacs@gnu.org>
2004-01-17 20:43 ` David Kastrup
[not found] ` <mailman.789.1074285000.928.bug-gnu-emacs@gnu.org>
2004-01-16 21:43 ` David Kastrup
2004-01-17 12:53 ` Richard Stallman
2004-01-17 0:16 ` Dave Love
2004-01-17 15:27 ` Reuben Thomas [this message]
[not found] ` <mailman.716.1074194876.928.bug-gnu-emacs@gnu.org>
2004-01-15 22:32 ` Kevin Rodgers
2004-01-15 12:12 Dave Love
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.58.0401171616070.1565@mnemosyne \
--to=rrt@sc3d.org \
--cc=bug-gnu-emacs@gnu.org \
--cc=jas@extundo.com \
--cc=rrt@mupsych.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).