unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#50680: eww-retrieve-synchronously
@ 2021-09-19 16:12 Juri Linkov
  2021-09-20  5:49 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 3+ messages in thread
From: Juri Linkov @ 2021-09-19 16:12 UTC (permalink / raw)
  To: 50680

[-- Attachment #1: Type: text/plain, Size: 634 bytes --]

Tags: patch

This is a spin-off from bug#50497.

>> What do you think about supporting synchronous mode in eww?
>> When adding a variable that causes eww-retrieve to use
>> url-retrieve-synchronously, isearch part could look like this:
>>
>>   (defun eww-isearch-next-buffer (&optional _buffer wrap)
>>     (let ((eww-synchronous t))
>>       (if wrap
>>           (condition-case nil
>>               (eww-top-url)
>>             (error nil))
>>         (if isearch-forward
>>             (eww-next-url)
>>           (eww-previous-url))))
>>     (current-buffer))
>
> Sure, makes sense to me.

Here is a patch that implements this:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: eww-retrieve-synchronously.patch --]
[-- Type: text/x-diff, Size: 2648 bytes --]

diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index c1202974f4..7ae44fdc71 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -143,11 +143,13 @@ eww-history-limit
 
 (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."
+If nil, `url-retrieve' is used to download the data.
+If `sync', `url-retrieve-synchronously' is used.
+For other non-nil values, 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)
+                 (const :tag "Use `url-retrieve-synchronously'" sync)
                  (repeat string)))
 
 (defcustom eww-use-external-browser-for-content-type
@@ -366,9 +368,16 @@ eww
                     (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)))
+  (cond
+   ((null eww-retrieve-command)
+    (url-retrieve url #'eww-render
+                  (list url nil (current-buffer))))
+   ((eq eww-retrieve-command 'sync)
+    (let ((orig-buffer (current-buffer))
+          (data-buffer (url-retrieve-synchronously url)))
+      (with-current-buffer data-buffer
+        (eww-render nil url nil orig-buffer))))
+   (t
     (let ((buffer (generate-new-buffer " *eww retrieve*"))
           (error-buffer (generate-new-buffer " *eww error*")))
       (with-current-buffer buffer
@@ -388,7 +397,7 @@ eww-retrieve
                          (with-current-buffer buffer
                            (goto-char (point-min))
                            (insert "Content-type: text/html; charset=utf-8\n\n")
-                           (apply #'funcall callback nil cbargs))))))))))
+                           (apply #'funcall callback nil cbargs)))))))))))
 
 (function-put 'eww 'browse-url-browser-kind 'internal)
 
@@ -2398,13 +2407,14 @@ eww-restore-desktop
 
 (defun eww-isearch-next-buffer (&optional _buffer wrap)
   "Go to the next page to search using `rel' attribute for navigation."
-  (if wrap
-      (condition-case nil
-	  (eww-top-url)
-	(error nil))
-    (if isearch-forward
-	(eww-next-url)
-      (eww-previous-url)))
+  (let ((eww-retrieve-command 'sync))
+    (if wrap
+        (condition-case nil
+	    (eww-top-url)
+	  (error nil))
+      (if isearch-forward
+	  (eww-next-url)
+        (eww-previous-url))))
   (current-buffer))
 
 (provide 'eww)

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* bug#50680: eww-retrieve-synchronously
  2021-09-19 16:12 bug#50680: eww-retrieve-synchronously Juri Linkov
@ 2021-09-20  5:49 ` Lars Ingebrigtsen
  2021-09-20  7:16   ` Juri Linkov
  0 siblings, 1 reply; 3+ messages in thread
From: Lars Ingebrigtsen @ 2021-09-20  5:49 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 50680

Juri Linkov <juri@linkov.net> writes:

> Here is a patch that implements this:

I haven't tried the patch, but skimming it, it makes sense to me, so
please go ahead and push it.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#50680: eww-retrieve-synchronously
  2021-09-20  5:49 ` Lars Ingebrigtsen
@ 2021-09-20  7:16   ` Juri Linkov
  0 siblings, 0 replies; 3+ messages in thread
From: Juri Linkov @ 2021-09-20  7:16 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 50680

tags 50680 fixed
close 50680 28.0.50
quit

>> Here is a patch that implements this:
>
> I haven't tried the patch, but skimming it, it makes sense to me, so
> please go ahead and push it.

Now pushed.





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-09-20  7:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-19 16:12 bug#50680: eww-retrieve-synchronously Juri Linkov
2021-09-20  5:49 ` Lars Ingebrigtsen
2021-09-20  7:16   ` Juri Linkov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).