aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ingebrigtsen2020-09-13 00:12:33 +0200
committerLars Ingebrigtsen2020-09-13 00:12:33 +0200
commit31be4d7ca48fd21bdcd5428ce4164790efd39099 (patch)
treeb90517aef4eb6ed8ccc730e200bab26e54733c67
parent3e073520b341228d7a54a242e3d09862948e5c08 (diff)
downloademacs-31be4d7ca48fd21bdcd5428ce4164790efd39099.tar.gz
emacs-31be4d7ca48fd21bdcd5428ce4164790efd39099.zip
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
212@node Advanced 212@node Advanced
213@chapter Advanced 213@chapter Advanced
214 214
215@findex eww-retrieve-command
216 EWW normally uses @code{url-retrieve} to fetch the @acronym{HTML}
217before rendering it. It can sometimes be convenient to use an external
218program to do this, and @code{eww-retrieve-command} should then be a
219list that specifies a command and the parameters. For instance, to
220use the Chromium browser, you could say something like this:
221
222@lisp
223(setq eww-retrieve-command
224 '("chromium" "--headless"
225 "--virtual-time-budget=3000"
226 "--dump-dom"))
227@end lisp
228
229The command should return the @acronym{HTML} on standard output, and
230the data should use @acronym{UTF-8} as the charset.
231
215@findex eww-view-source 232@findex eww-view-source
216@kindex v 233@kindex v
217@cindex Viewing Source 234@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.
809** EWW 809** EWW
810 810
811+++ 811+++
812*** New variable 'eww-retrieve-command'.
813This can be used to download data via an external command. If nil
814(the default), then 'url-retrieve' is used.
815
816+++
812*** New Emacs command line convenience function. 817*** New Emacs command line convenience function.
813The 'eww-browse' command has been added, which allows you to register 818The 'eww-browse' command has been added, which allows you to register
814Emacs as a MIME handler for "text/x-uri", and will call 'eww' on the 819Emacs 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'."
134 :type '(choice (const :tag "Unlimited" nil) 134 :type '(choice (const :tag "Unlimited" nil)
135 integer)) 135 integer))
136 136
137(defcustom eww-retrieve-command nil
138 "Command to retrieve an URL via an external program.
139If nil, `url-retrieve' is used to download the data. If non-nil,
140this should be a list where the first item is the program, and
141the rest are the arguments."
142 :version "28.1"
143 :type '(choice (const :tag "Use `url-retrieve'" nil)
144 (list string)))
145
137(defcustom eww-use-external-browser-for-content-type 146(defcustom eww-use-external-browser-for-content-type
138 "\\`\\(video/\\|audio/\\|application/ogg\\)" 147 "\\`\\(video/\\|audio/\\|application/ogg\\)"
139 "Always use external browser for specified content-type." 148 "Always use external browser for specified content-type."
@@ -346,9 +355,28 @@ killed after rendering."
346 (let ((eww-buffer (current-buffer))) 355 (let ((eww-buffer (current-buffer)))
347 (with-current-buffer buffer 356 (with-current-buffer buffer
348 (eww-render nil url nil eww-buffer))) 357 (eww-render nil url nil eww-buffer)))
349 (url-retrieve url #'eww-render 358 (eww-retrieve url #'eww-render
350 (list url nil (current-buffer)))))) 359 (list url nil (current-buffer))))))
351 360
361(defun eww-retrieve (url callback cbargs)
362 (if (null eww-retrieve-command)
363 (url-retrieve url #'eww-render
364 (list url nil (current-buffer)))
365 (let ((buffer (generate-new-buffer " *eww retrieve*")))
366 (with-current-buffer buffer
367 (set-buffer-multibyte nil)
368 (make-process
369 :name "*eww fetch*"
370 :buffer (current-buffer)
371 :stderr (get-buffer-create " *eww error*")
372 :command (append eww-retrieve-command (list url))
373 :sentinel (lambda (process _)
374 (unless (process-live-p process)
375 (with-current-buffer buffer
376 (goto-char (point-min))
377 (insert "Content-type: text/html; charset=utf-8\n\n")
378 (apply #'funcall callback nil cbargs)))))))))
379
352(function-put 'eww 'browse-url-browser-kind 'internal) 380(function-put 'eww 'browse-url-browser-kind 'internal)
353 381
354(defun eww--dwim-expand-url (url) 382(defun eww--dwim-expand-url (url)
@@ -1117,7 +1145,7 @@ just re-display the HTML already fetched."
1117 (eww-display-html 'utf-8 url (plist-get eww-data :dom) 1145 (eww-display-html 'utf-8 url (plist-get eww-data :dom)
1118 (point) (current-buffer))) 1146 (point) (current-buffer)))
1119 (let ((url-mime-accept-string eww-accept-content-types)) 1147 (let ((url-mime-accept-string eww-accept-content-types))
1120 (url-retrieve url #'eww-render 1148 (eww-retrieve url #'eww-render
1121 (list url (point) (current-buffer) encode)))))) 1149 (list url (point) (current-buffer) encode))))))
1122 1150
1123;; Form support. 1151;; Form support.