From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#50680: eww-retrieve-synchronously Date: Sun, 19 Sep 2021 19:12:39 +0300 Organization: LINKOV.NET Message-ID: <874kagmv98.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="33338"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu) To: 50680@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Sep 19 18:31:59 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mRzjS-0008TS-61 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 19 Sep 2021 18:31:58 +0200 Original-Received: from localhost ([::1]:55836 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mRzjQ-0007Fm-Tz for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 19 Sep 2021 12:31:56 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42200) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mRzge-0005dv-0Z for bug-gnu-emacs@gnu.org; Sun, 19 Sep 2021 12:29:05 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:56364) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mRzgc-0004UP-2w for bug-gnu-emacs@gnu.org; Sun, 19 Sep 2021 12:29:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mRzgb-0002Ua-UL for bug-gnu-emacs@gnu.org; Sun, 19 Sep 2021 12:29:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 19 Sep 2021 16:29:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 50680 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.16320689279543 (code B ref -1); Sun, 19 Sep 2021 16:29:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 19 Sep 2021 16:28:47 +0000 Original-Received: from localhost ([127.0.0.1]:39674 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mRzgK-0002Tm-TY for submit@debbugs.gnu.org; Sun, 19 Sep 2021 12:28:47 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:56580) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mRzgF-0002TX-Lw for submit@debbugs.gnu.org; Sun, 19 Sep 2021 12:28:43 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42112) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mRzgF-0005NG-9Y for bug-gnu-emacs@gnu.org; Sun, 19 Sep 2021 12:28:39 -0400 Original-Received: from relay12.mail.gandi.net ([217.70.178.232]:55913) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mRzgD-00047g-DP for bug-gnu-emacs@gnu.org; Sun, 19 Sep 2021 12:28:39 -0400 Original-Received: (Authenticated sender: juri@linkov.net) by relay12.mail.gandi.net (Postfix) with ESMTPSA id C1747200002 for ; Sun, 19 Sep 2021 16:28:34 +0000 (UTC) Received-SPF: pass client-ip=217.70.178.232; envelope-from=juri@linkov.net; helo=relay12.mail.gandi.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:214747 Archived-At: --=-=-= Content-Type: text/plain 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: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=eww-retrieve-synchronously.patch 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) --=-=-=--