[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 31be4d7: Add a way to use an external command to download HTML in
From: |
Lars Ingebrigtsen |
Subject: |
master 31be4d7: Add a way to use an external command to download HTML in eww |
Date: |
Sat, 12 Sep 2020 18:12:44 -0400 (EDT) |
branch: master
commit 31be4d7ca48fd21bdcd5428ce4164790efd39099
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
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.
---
doc/misc/eww.texi | 17 +++++++++++++++++
etc/NEWS | 5 +++++
lisp/net/eww.el | 32 ++++++++++++++++++++++++++++++--
3 files changed, 52 insertions(+), 2 deletions(-)
diff --git a/doc/misc/eww.texi b/doc/misc/eww.texi
index 85be112..e814d0a 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 8ff62b6..ddc2fb9 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 07aa48a..bc23fb9 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.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 31be4d7: Add a way to use an external command to download HTML in eww,
Lars Ingebrigtsen <=