summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2020-09-13 00:12:33 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2020-09-13 00:12:33 +0200
commit31be4d7ca48fd21bdcd5428ce4164790efd39099 (patch)
treeb90517aef4eb6ed8ccc730e200bab26e54733c67
parent3e073520b341228d7a54a242e3d09862948e5c08 (diff)
downloademacs-31be4d7ca48fd21bdcd5428ce4164790efd39099.tar.gz
Add a way to use an external command to download HTML in eww
* doc/misc/eww.texi (Advanced): Document it. * lisp/net/eww.el (eww-retrieve): New function. (eww-reload): Use it. (eww): Ditto. (eww-retrieve-command): New variable.
-rw-r--r--doc/misc/eww.texi17
-rw-r--r--etc/NEWS5
-rw-r--r--lisp/net/eww.el32
3 files changed, 52 insertions, 2 deletions
diff --git a/doc/misc/eww.texi b/doc/misc/eww.texi
index 85be112402c..e814d0ac486 100644
--- a/doc/misc/eww.texi
+++ b/doc/misc/eww.texi
@@ -212,6 +212,23 @@ in an external browser by customizing
@node Advanced
@chapter Advanced
+@findex eww-retrieve-command
+ EWW normally uses @code{url-retrieve} to fetch the @acronym{HTML}
+before rendering it. It can sometimes be convenient to use an external
+program to do this, and @code{eww-retrieve-command} should then be a
+list that specifies a command and the parameters. For instance, to
+use the Chromium browser, you could say something like this:
+
+@lisp
+(setq eww-retrieve-command
+ '("chromium" "--headless"
+ "--virtual-time-budget=3000"
+ "--dump-dom"))
+@end lisp
+
+The command should return the @acronym{HTML} on standard output, and
+the data should use @acronym{UTF-8} as the charset.
+
@findex eww-view-source
@kindex v
@cindex Viewing Source
diff --git a/etc/NEWS b/etc/NEWS
index 8ff62b6dc05..ddc2fb9d600 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -809,6 +809,11 @@ background colors or transparency, such as xbm, pbm, svg, png and gif.
** EWW
+++
+*** New variable 'eww-retrieve-command'.
+This can be used to download data via an external command. If nil
+(the default), then 'url-retrieve' is used.
+
++++
*** New Emacs command line convenience function.
The 'eww-browse' command has been added, which allows you to register
Emacs as a MIME handler for "text/x-uri", and will call 'eww' on the
diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index 07aa48aeaee..bc23fb913f3 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -134,6 +134,15 @@ The string will be passed through `substitute-command-keys'."
:type '(choice (const :tag "Unlimited" nil)
integer))
+(defcustom eww-retrieve-command nil
+ "Command to retrieve an URL via an external program.
+If nil, `url-retrieve' is used to download the data. If non-nil,
+this should be a list where the first item is the program, and
+the rest are the arguments."
+ :version "28.1"
+ :type '(choice (const :tag "Use `url-retrieve'" nil)
+ (list string)))
+
(defcustom eww-use-external-browser-for-content-type
"\\`\\(video/\\|audio/\\|application/ogg\\)"
"Always use external browser for specified content-type."
@@ -346,9 +355,28 @@ killed after rendering."
(let ((eww-buffer (current-buffer)))
(with-current-buffer buffer
(eww-render nil url nil eww-buffer)))
- (url-retrieve url #'eww-render
+ (eww-retrieve url #'eww-render
(list url nil (current-buffer))))))
+(defun eww-retrieve (url callback cbargs)
+ (if (null eww-retrieve-command)
+ (url-retrieve url #'eww-render
+ (list url nil (current-buffer)))
+ (let ((buffer (generate-new-buffer " *eww retrieve*")))
+ (with-current-buffer buffer
+ (set-buffer-multibyte nil)
+ (make-process
+ :name "*eww fetch*"
+ :buffer (current-buffer)
+ :stderr (get-buffer-create " *eww error*")
+ :command (append eww-retrieve-command (list url))
+ :sentinel (lambda (process _)
+ (unless (process-live-p process)
+ (with-current-buffer buffer
+ (goto-char (point-min))
+ (insert "Content-type: text/html; charset=utf-8\n\n")
+ (apply #'funcall callback nil cbargs)))))))))
+
(function-put 'eww 'browse-url-browser-kind 'internal)
(defun eww--dwim-expand-url (url)
@@ -1117,7 +1145,7 @@ just re-display the HTML already fetched."
(eww-display-html 'utf-8 url (plist-get eww-data :dom)
(point) (current-buffer)))
(let ((url-mime-accept-string eww-accept-content-types))
- (url-retrieve url #'eww-render
+ (eww-retrieve url #'eww-render
(list url (point) (current-buffer) encode))))))
;; Form support.