;; control but which window DO you want to control and how do you
;; discover its id?
-;; William M. Perry's excellent "w3" WWW browser for
+;; 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.
:group 'browse-url)
(defcustom browse-url-new-window-flag nil
- "If non-nil, always open a new browser window with appropriate browsers.
+ "Non-nil means 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."
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; URL encoding
-(defun browse-url-encode-url (url &optional filename-p)
- "Encode all `confusing' characters in URL.
-If FILENAME-P is nil, the confusing characters are [,)$].
-Otherwise, the confusing characters are [*\"()',=;?% ]."
- (let ((conf-char (if filename-p "[*\"()',=;?% ]" "[,)$]"))
- (encoded-url (copy-sequence url))
+(defun browse-url-url-encode-chars (text chars)
+ "URL-encode the chars in TEXT that match CHARS.
+CHARS is a regexp-like character alternative (e.g., \"[,)$]\")."
+ (let ((encoded-url (copy-sequence url))
(s 0))
- (while (setq s (string-match conf-char encoded-url s))
+ (while (setq s (string-match chars encoded-url s))
(setq encoded-url
(replace-match (format "%%%x"
(string-to-char (match-string 0 encoded-url)))
s (1+ s)))
encoded-url))
+(defun browse-url-encode-url (url)
+ "Escape annoying characters in URL.
+The annoying characters are those that can mislead a webbrowser
+regarding its parameter treatment. For instance, `,' can
+be misleading because it could be used to separate URLs."
+ (browse-url-url-encode-chars url "[,)$]"))
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; URL input
(or file-name-coding-system
default-file-name-coding-system))))
(if coding (setq file (encode-coding-string file coding))))
- (setq file (browse-url-encode-url file 'url-is-filename))
+ (setq file (browse-url-url-encode-chars file "[*\"()',=;?% ]"))
(dolist (map browse-url-filename-alist)
(when (and map (string-match (car map) file))
(setq file (replace-match (cdr map) t nil file))))
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)
- ((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)
- ((locate-library "w3") 'browse-url-w3)
- (t
- (lambda (&ignore args) (error "No usable browser found"))))
- url args))
+ (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)
+ ((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)
+ ((locate-library "w3") 'browse-url-w3)
+ (t
+ (lambda (&ignore args) (error "No usable browser found"))))
+ url args))
;;;###autoload
(defun browse-url-netscape (url &optional new-window)
;; <peter.kruse@psychologie.uni-regensburg.de>.
(browse-url-netscape-send (if (>= browse-url-netscape-version 4)
"xfeDoCommand(reload)"
- "reload")))
+ "reload")))
(defun browse-url-netscape-send (command)
"Send a remote control command to Netscape."
(append
browse-url-gnome-moz-arguments
(if (browse-url-maybe-new-window new-window)
- '("--newwin"))
+ '("--newwin"))
(list "--raise" url))))
;; --- Mosaic ---
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
+ (require 'w3) ; w3-fetch-other-window not autoloaded
(if (browse-url-maybe-new-window new-window)
(w3-fetch-other-window url)
(w3-fetch url)))
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)"))))
+ (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 xterm ---
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"
- ,url)))
+ ,@browse-url-xterm-args "-e" "lynx"
+ ,url)))
;; --- Lynx in an Emacs "term" window ---
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
+ (let* ((system-uses-terminfo t) ; Lynx uses terminfo
;; (term-term-name "vt100") ; ??
(buf (get-buffer "*lynx*"))
(proc (and buf (get-buffer-process buf)))
(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
+ (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
+ (term-send-string proc (concat "g" ; goto
"\C-u" ; kill default url
url
"\r")))))
don't offer a form of remote control."
(interactive (browse-url-interactive-arg "URL: "))
(if (not browse-url-generic-program)
- (error "No browser defined (`browse-url-generic-program')"))
+ (error "No browser defined (`browse-url-generic-program')"))
(apply 'call-process browse-url-generic-program nil
0 nil
(append browse-url-generic-args (list url))))
(interactive (browse-url-interactive-arg "KDE URL: "))
(message "Sending URL to KDE...")
(apply #'start-process (concat "KDE " url) nil browse-url-kde-program
- (append browse-url-kde-args (list url))))
+ (append browse-url-kde-args (list url))))
;;;###autoload
(defun browse-url-elinks (url)
(setq url (browse-url-encode-url url))
(let ((process-environment (browse-url-process-environment))
(elinks-ping-process (start-process "elinks-ping" nil
- "elinks" "-remote" "ping()")))
+ "elinks" "-remote" "ping()")))
(set-process-sentinel elinks-ping-process
`(lambda (process change)
(browse-url-elinks-sentinel process ,url)))))
;; 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.
- (apply #'start-process
- (append (list (concat "elinks:" url) nil)
- browse-url-elinks-wrapper
- (list "elinks" url))))
- (0
- ;; Found an instance, open URL in new tab.
- (start-process (concat "elinks:" url) nil
- "elinks" "-remote"
- (concat "openURL(\"" url "\",new-tab)")))
- (otherwise
- (error "Undefined exit-code of process `elinks'.")))))
+ (5
+ ;; No instance, start a new one.
+ (apply #'start-process
+ (append (list (concat "elinks:" url) nil)
+ browse-url-elinks-wrapper
+ (list "elinks" url))))
+ (0
+ ;; Found an instance, open URL in new tab.
+ (start-process (concat "elinks:" url) nil
+ "elinks" "-remote"
+ (concat "openURL(\"" url "\",new-tab)")))
+ (otherwise
+ (error "Undefined exit-code of process `elinks'")))))
(provide 'browse-url)