GNU bug report logs - #23430
25.0.93; iter-defun does not support special form save-current-buffer

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Dmitry Gutov <dgutov@HIDDEN>; dated Tue, 3 May 2016 01:33:02 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

Message received at 23430 <at> debbugs.gnu.org:


Received: (at 23430) by debbugs.gnu.org; 5 May 2016 22:47:04 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu May 05 18:47:04 2016
Received: from localhost ([127.0.0.1]:40899 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1ayS2y-0006f5-4j
	for submit <at> debbugs.gnu.org; Thu, 05 May 2016 18:47:04 -0400
Received: from mail-wm0-f48.google.com ([74.125.82.48]:36555)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <raaahh@HIDDEN>) id 1ayS2w-0006eb-Hn
 for 23430 <at> debbugs.gnu.org; Thu, 05 May 2016 18:47:02 -0400
Received: by mail-wm0-f48.google.com with SMTP id n129so37670151wmn.1
 for <23430 <at> debbugs.gnu.org>; Thu, 05 May 2016 15:47:02 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
 h=sender:subject:to:references:from:message-id:date:user-agent
 :mime-version:in-reply-to;
 bh=EaqK3pqKqR+agt1HRSoBKnz95NLii6uzmqdHMHTG91k=;
 b=QMVIygi2d+oDfaWpCs+vBbTqHeCOHCqcq0NNYjUx+KrGqeM1F/bqijOTW76Ol4muOr
 /iYy6LpYcaKarjcMBbriMMxuWVTeiOaDRD+7Je67nybtnbm/Fip3ITZhnd8POARuK5qw
 eQHUM5W37FkMR5IF8YjH8aVcx/aZOJlIw90fGY5T1iMOoH28lWY61CKM/UXKJMkTwb2j
 ie30XARueNDWv0bQce2xLda0/EtrFqWJWy1zKG4+q7CCbUir9Cvar3WRAF1BzstgGZW7
 IRth4/98X8uQPLLM5fPzhu/Hh4TXQnZYDLlAVgGl8k6Mlr1MkFu1yTnOSLIemLcEkxcy
 QK1A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20130820;
 h=x-gm-message-state:sender:subject:to:references:from:message-id
 :date:user-agent:mime-version:in-reply-to;
 bh=EaqK3pqKqR+agt1HRSoBKnz95NLii6uzmqdHMHTG91k=;
 b=EAY7E8E4MiKTHv5cIC0Y2MFnINnAXUR3331C4WF+Z/0nLLTX0KNgYF1byFYJfHPFMP
 TBeonnYA5o9kptpbW84Q+5mYaJBc/GwxXr3lVycioRBBXcIpHGeGLzqf+WX1Ty8vcjOE
 Ltzo5dTRN04P1BdpYPfkQ0mC9/5x/WU5I2dcGtIoi1OnnEMT/i8eEMpUelYPQRSkLv0Q
 UxBLCBQHrjMXAaX+qbr+piq4hWR3v3Ge/VBGqvK5c3uzb3DaGyTH/efOCGH0Hf0Xqpuh
 uTuv3XdNKdSQrJXM51KKQcLRpMpBsYZgXBQHD2rZoF3lj2SqKpxuzlCEmax9LPyakcGx
 oQ7Q==
X-Gm-Message-State: AOPr4FV/vcrmtKVz1hSWUap62tpV7KwST+bKtrr83wOfJEdd7M6T/Gb74DJAkhugn1sFhA==
X-Received: by 10.28.234.130 with SMTP id g2mr6174736wmi.42.1462488416934;
 Thu, 05 May 2016 15:46:56 -0700 (PDT)
Received: from [192.168.1.2] ([185.105.175.24])
 by smtp.googlemail.com with ESMTPSA id jq1sm11873826wjc.28.2016.05.05.15.46.55
 for <23430 <at> debbugs.gnu.org> (version=TLSv1/SSLv3 cipher=OTHER);
 Thu, 05 May 2016 15:46:56 -0700 (PDT)
Subject: Re: bug#23430: 25.0.93; iter-defun does not support special form
 save-current-buffer
To: 23430 <at> debbugs.gnu.org
References: <86k2jc2ahf.fsf@HIDDEN>
From: Dmitry Gutov <dgutov@HIDDEN>
Message-ID: <bba9665d-c646-5ec0-3c8b-233b4007c5ec@HIDDEN>
Date: Fri, 6 May 2016 01:46:54 +0300
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
 Thunderbird/45.1
MIME-Version: 1.0
In-Reply-To: <86k2jc2ahf.fsf@HIDDEN>
Content-Type: multipart/mixed; boundary="------------78EECA99810C866BEA655167"
X-Spam-Score: -0.5 (/)
X-Debbugs-Envelope-To: 23430
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.5 (/)

This is a multi-part message in MIME format.
--------------78EECA99810C866BEA655167
Content-Type: text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding: 7bit

On 05/03/2016 04:31 AM, Dmitry Gutov wrote:

> The above example seemed to me to be the prime use case for generator.el
> (e.g. lazily parsing output from an asynchronous process), so this
> is disappointing.

Actually, I take this back.

- generator.el doesn't seem useful for parsing output from an 
asynchronous process because it has no way to indicate whether the 
process has new output, or to return control back to Emacs while the 
process is still running but has no new output. It seems to call for a 
different abstraction.

- with-current-buffer turned out not to be so essential. Nor 
save-excursion. I've reimplemented xref--buf-pairs-iterator using 
iter-lambda but couldn't get the full benefit of the package because 
that function also needs a way to reliably clean up resources. The 
result is a bit more comprehensible, but also longer, so I'm hesitant to 
use it (attached).

So sum up, maybe this bug can be closed, but I'd like to see Daniel's 
opinion. Supporting with-current-buffer might turn out to be more 
essential in other cases.

--------------78EECA99810C866BEA655167
Content-Type: text/x-patch;
 name="xref-gen.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="xref-gen.diff"

diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index f651dc9..f8b3c85 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -71,6 +71,7 @@
 (require 'ring)
 (require 'pcase)
 (require 'project)
+(require 'generator)
 
 (eval-when-compile
   (require 'semantic/symref)) ;; for hit-lines slot
@@ -534,19 +535,12 @@ xref-query-replace-in-results
       (funcall iter :cleanup))))
 
 (defun xref--buf-pairs-iterator (xrefs)
-  (let (chunk-done item next-pair file-buf pairs all-pairs)
-    (lambda (action)
-      (pcase action
-        (:next
-         (when (or xrefs next-pair)
-           (setq chunk-done nil)
-           (when next-pair
-             (setq file-buf (marker-buffer (car next-pair))
-                   pairs (list next-pair)
-                   next-pair nil))
-           (while (and (not chunk-done)
-                       (setq item (pop xrefs)))
-             (save-excursion
+  (let* (item
+         file-buf pairs all-pairs
+         (iter
+          (funcall
+           (iter-lambda ()
+             (while (setq item (pop xrefs))
                (let* ((loc (xref-item-location item))
                       (beg (xref-location-marker loc))
                       (end (move-marker (make-marker)
@@ -568,9 +562,19 @@ xref--buf-pairs-iterator
                       ((equal file-buf (marker-buffer beg))
                        (push pair pairs))
                       (t
-                       (setq chunk-done t
-                             next-pair pair))))))))
-           (cons file-buf (nreverse pairs))))
+                       (iter-yield (cons file-buf (nreverse pairs)))
+                       (setq file-buf (marker-buffer beg)
+                             pairs (list pair)))))))
+               (when (null xrefs)
+                 (iter-yield (cons file-buf (nreverse pairs)))))))))
+    (lambda (action)
+      (pcase action
+        (:next
+         (condition-case nil
+             (save-excursion
+               (iter-next iter))
+           (iter-end-of-sequence
+            nil)))
         (:cleanup
          (dolist (pair all-pairs)
            (move-marker (car pair) nil)

--------------78EECA99810C866BEA655167--




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#23430; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 3 May 2016 01:32:29 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon May 02 21:32:28 2016
Received: from localhost ([127.0.0.1]:34405 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1axPCO-00011D-ON
	for submit <at> debbugs.gnu.org; Mon, 02 May 2016 21:32:28 -0400
Received: from eggs.gnu.org ([208.118.235.92]:37925)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <raaahh@HIDDEN>) id 1axPCN-00010y-QP
 for submit <at> debbugs.gnu.org; Mon, 02 May 2016 21:32:28 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <raaahh@HIDDEN>) id 1axPC9-00064Z-FI
 for submit <at> debbugs.gnu.org; Mon, 02 May 2016 21:32:19 -0400
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_05,FREEMAIL_FROM,
 T_DKIM_INVALID autolearn=disabled version=3.3.2
Received: from lists.gnu.org ([2001:4830:134:3::11]:56373)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <raaahh@HIDDEN>) id 1axPC8-00063l-A7
 for submit <at> debbugs.gnu.org; Mon, 02 May 2016 21:32:13 -0400
Received: from eggs.gnu.org ([2001:4830:134:3::10]:57066)
 by lists.gnu.org with esmtp (Exim 4.71)
 (envelope-from <raaahh@HIDDEN>) id 1axPBw-0006hY-Aa
 for bug-gnu-emacs@HIDDEN; Mon, 02 May 2016 21:32:06 -0400
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <raaahh@HIDDEN>) id 1axPBi-0005zJ-E4
 for bug-gnu-emacs@HIDDEN; Mon, 02 May 2016 21:31:52 -0400
Received: from mail-wm0-x22e.google.com ([2a00:1450:400c:c09::22e]:38590)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <raaahh@HIDDEN>) id 1axPBh-0005wl-5C
 for bug-gnu-emacs@HIDDEN; Mon, 02 May 2016 21:31:46 -0400
Received: by mail-wm0-x22e.google.com with SMTP id g17so13095842wme.1
 for <bug-gnu-emacs@HIDDEN>; Mon, 02 May 2016 18:31:30 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;
 h=sender:from:to:subject:date:message-id:mime-version;
 bh=o8R/+eAslZiChY/5fbxtbWrwXxrYnw4ukqWEo3lAJKE=;
 b=wIqc6I21lkT3SKPG+OiB1LJpcpoVxvOKITCoVnlDspj0UWlWLETa/cuGjU7O/fGvLS
 TP4XphQduMFdL22WgQvT6BF/ZeSIdcfQlKAYenEIDNp+78qf+rwtkSTEeF0kdgf0uz4G
 D5Twe0Uy5Rr9tRkI8JWy9RJBu6GBxkZW46Hsj8aYIu7+YEyROws0eF57bdCWqPiH4otH
 W9pWAp/igY9+bi5fE7zj4chYJRDCt61UZX9Fgia7cZBYGi3MX+BKIsUHc2GSCgiOzjsE
 2ExVYhPYKI/e9hCvhHi4aTCfEUMSzZucopJJ1aRq3ugeO6XU8Nw/jkXtF7bBkJDfqkJB
 pHIg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20130820;
 h=x-gm-message-state:sender:from:to:subject:date:message-id
 :mime-version;
 bh=o8R/+eAslZiChY/5fbxtbWrwXxrYnw4ukqWEo3lAJKE=;
 b=JghisUdC+7cSk6tQOrYQhvEvdi0xAFKHLn/l+OXY3W1QEkYw8r5R0JdRS7awTpQj1e
 v4JEgCljgq26KNZ4SnNFrlPhyc+v4QLQjnS/g5Ajs5Cukmrku1zzniwq5Dma1ZG4Znub
 NNkdQNHD//uu8T50LSr6db/LB1Zbk6jX5f5AdBvmFx1tHS1jdwEFg/sMSgDge++ALw/O
 UETgWq+TT6ZEsbbWrGkOe1w1nsMvMkPup1aqj7GxNJFu2gM6FDo4UkA74/BvXxQXqLLH
 MVKUJcxvT5W8eLj48kOilFOCGrdevd3iVvQkmMwZyzPum9asxhjdijwqbND3XGC+uFZs
 gdXQ==
X-Gm-Message-State: AOPr4FVrT13qERax/W106TbYvfb0LGa7EhhNcNH4cVzzph1y9RWj/+vmyJ6hEQw21uWcug==
X-Received: by 10.28.148.149 with SMTP id w143mr216400wmd.10.1462239086883;
 Mon, 02 May 2016 18:31:26 -0700 (PDT)
Received: from axl ([185.105.175.24])
 by smtp.gmail.com with ESMTPSA id yr1sm960339wjc.9.2016.05.02.18.31.25
 for <bug-gnu-emacs@HIDDEN>
 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
 Mon, 02 May 2016 18:31:26 -0700 (PDT)
From: Dmitry Gutov <dgutov@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: 25.0.93; iter-defun does not support special form save-current-buffer
Date: Tue, 03 May 2016 04:31:24 +0300
Message-ID: <86k2jc2ahf.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 2001:4830:134:3::11
X-Spam-Score: -3.8 (---)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.8 (---)

Example:

;; -*- lexical-binding: t -*-

(iter-defun (str buf)
  (with-current-buffer buf
    (goto-char (point-min)))
  (let (done)
    (while (not done)
      (with-current-buffer buf
        (if (search-forward str)
            (iter-yield (match-beginning 0))
          (setq done 0))))))

...upon evaluation, says: "special form (save-current-buffer (set-buffer
buf) (if (search-forward str) (cps-internal-yield (match-beginning 0))
(setq cps-binding-done- 0))) incorrect or not supported".

The above example seemed to me to be the prime use case for generator.el
(e.g. lazily parsing output from an asynchronous process), so this
is disappointing.

In GNU Emacs 25.0.93.2 (x86_64-unknown-linux-gnu, GTK+ Version 3.18.9)
 of 2016-04-30 built on axl
Repository revision: ffe701cb07cfb3584c4e4894976f0c9487d02c59
Windowing system distributor 'The X.Org Foundation', version 11.0.11803000
System Description:	Ubuntu 16.04 LTS




Acknowledgement sent to Dmitry Gutov <dgutov@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#23430; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Thu, 5 May 2016 23:00:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.