;;; browse-url.el --- pass a URL to a WWW browser
-;; Copyright (C) 1995-2012 Free Software Foundation, Inc.
+;; Copyright (C) 1995-2013 Free Software Foundation, Inc.
;; Author: Denis Howe <dbh@doc.ic.ac.uk>
;; Maintainer: FSF
;; the buffer, use:
;; M-x browse-url
-;; To display a URL by shift-clicking on it, put this in your ~/.emacs
-;; file:
+;; To display a URL by shift-clicking on it, put this in your init 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.)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Variables
-(eval-when-compile (require 'cl))
-
(defgroup browse-url nil
"Use a web browser to look at a URL."
:prefix "browse-url-"
(function-item :tag "Galeon" :value browse-url-galeon)
(function-item :tag "Epiphany" :value browse-url-epiphany)
(function-item :tag "Netscape" :value browse-url-netscape)
+ (function-item :tag "eww" :value eww-browse-url)
(function-item :tag "Mosaic" :value browse-url-mosaic)
(function-item :tag "Mosaic using CCI" :value browse-url-cci)
(function-item :tag "Text browser in an xterm window"
;; URL input
(defun browse-url-url-at-point ()
- (let ((url (thing-at-point 'url)))
- (set-text-properties 0 (length url) nil url)
- url))
+ (or (thing-at-point 'url t)
+ ;; assume that the user is pointing at something like gnu.org/gnu
+ (let ((f (thing-at-point 'filename t)))
+ (and f (concat "http://" f)))))
;; Having this as a separate function called by the browser-specific
;; functions allows them to be stand-alone commands, making it easier
(defun browse-url-file-url (file)
"Return the URL corresponding to FILE.
Use variable `browse-url-filename-alist' to map filenames to URLs."
- (let ((coding (and (default-value 'enable-multibyte-characters)
- (or file-name-coding-system
- default-file-name-coding-system))))
+ (let ((coding (if (equal system-type 'windows-nt)
+ ;; W32 pretends that file names are UTF-8 encoded.
+ 'utf-8
+ (and (default-value 'enable-multibyte-characters)
+ (or file-name-coding-system
+ default-file-name-coding-system)))))
(if coding (setq file (encode-coding-string file coding))))
(setq file (browse-url-url-encode-chars file "[*\"()',=;?% ]"))
(dolist (map browse-url-filename-alist)
(and buffer (set-buffer buffer))
(let ((file-name
;; Ignore real name if restricted
- (and (= (- (point-max) (point-min)) (buffer-size))
+ (and (not (buffer-narrowed-p))
(or buffer-file-name
(and (boundp 'dired-directory) dired-directory)))))
(or file-name
;; When connected to various displays, be careful to use the display of
;; the currently selected frame, rather than the original start display,
;; which may not even exist any more.
- (if (stringp (frame-parameter (selected-frame) 'display))
- (setenv "DISPLAY" (frame-parameter (selected-frame) 'display)))
+ (if (stringp (frame-parameter nil 'display))
+ (setenv "DISPLAY" (frame-parameter nil 'display)))
(if (and (consp function)
(not (functionp function)))
;; The `function' can be an alist; look down it for first match
(defvar dos-windows-version)
(declare-function w32-shell-execute "w32fns.c") ;; Defined in C.
-(defun browse-url-default-windows-browser (url &optional new-window)
+(defun browse-url-default-windows-browser (url &optional _new-window)
(interactive (browse-url-interactive-arg "URL: "))
(cond ((eq system-type 'ms-dos)
(if dos-windows-version
(call-process "cygstart" nil nil nil url))
(t (w32-shell-execute "open" url))))
-(defun browse-url-default-macosx-browser (url &optional new-window)
+(defun browse-url-default-macosx-browser (url &optional _new-window)
(interactive (browse-url-interactive-arg "URL: "))
(start-process (concat "open " url) nil "open" url))
((executable-find browse-url-xterm-program) 'browse-url-text-xterm)
((locate-library "w3") 'browse-url-w3)
(t
- (lambda (&rest ignore) (error "No usable browser found"))))
+ (lambda (&rest _ignore) (error "No usable browser found"))))
url args))
(defun browse-url-can-use-xdg-open ()
(append browse-url-firefox-startup-arguments (list url))))))
;;;###autoload
-(defun browse-url-chromium (url &optional new-window)
+(defun browse-url-chromium (url &optional _new-window)
"Ask the Chromium WWW browser to load URL.
Default to the URL around or before point. The strings in
variable `browse-url-chromium-arguments' are also passed to
(defvar url-handler-regexp)
;;;###autoload
-(defun browse-url-emacs (url &optional new-window)
+(defun browse-url-emacs (url &optional _new-window)
"Ask Emacs to load URL into a buffer and show it in another window."
(interactive (browse-url-interactive-arg "URL: "))
(require 'url-handlers)
(w3-fetch url)))
;;;###autoload
-(defun browse-url-w3-gnudoit (url &optional new-window)
+(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
;; --- Lynx in an xterm ---
;;;###autoload
-(defun browse-url-text-xterm (url &optional new-window)
+(defun browse-url-text-xterm (url &optional _new-window)
;; new-window ignored
"Ask a text browser to load URL.
URL defaults to the URL around or before point.
(get-buffer-process buf)
;; Don't leave around a dead one (especially because of its
;; munged keymap.)
- (lambda (process event)
+ (lambda (process _event)
(if (not (memq (process-status process) '(run stop)))
(let ((buf (process-buffer process)))
(if buf (kill-buffer buf)))))))
;; --- Random browser ---
;;;###autoload
-(defun browse-url-generic (url &optional new-window)
+(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. A fresh copy of the
(append browse-url-generic-args (list url))))
;;;###autoload
-(defun browse-url-kde (url &optional new-window)
+(defun browse-url-kde (url &optional _new-window)
"Ask the KDE WWW browser to load URL.
Default to the URL around or before point."
(interactive (browse-url-interactive-arg "KDE URL: "))
(defun browse-url-elinks-sentinel (process url)
"Determines if Elinks is running or a new one has to be started."
- (let ((exit-status (process-exit-status process)))
- ;; Try to determine if an instance is running or if we have to
- ;; create a new one.
- (case exit-status
- (5
- ;; No instance, start a new one.
- (browse-url-elinks-new-window url))
- (0
- ;; Found an instance, open URL in new tab.
- (let ((process-environment (browse-url-process-environment)))
- (start-process (concat "elinks:" url) nil
- "elinks" "-remote"
- (concat "openURL(\"" url "\",new-tab)"))))
- (otherwise
- (error "Unrecognized exit-code %d of process `elinks'"
- exit-status)))))
+ ;; Try to determine if an instance is running or if we have to
+ ;; create a new one.
+ (pcase (process-exit-status process)
+ (5
+ ;; No instance, start a new one.
+ (browse-url-elinks-new-window url))
+ (0
+ ;; Found an instance, open URL in new tab.
+ (let ((process-environment (browse-url-process-environment)))
+ (start-process (concat "elinks:" url) nil
+ "elinks" "-remote"
+ (concat "openURL(\"" url "\",new-tab)"))))
+ (exit-status
+ (error "Unrecognized exit-code %d of process `elinks'"
+ exit-status))))
(provide 'browse-url)