GNU bug report logs - #58904
[PATCH] Handle buffer streams that operate on lines, pages, etc.

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; Severity: wishlist; Reported by: Philip Kaludercic <philipk@HIDDEN>; Keywords: patch; dated Sun, 30 Oct 2022 21:32:02 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

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


Received: (at 58904) by debbugs.gnu.org; 24 Nov 2022 19:40:17 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Nov 24 14:40:17 2022
Received: from localhost ([127.0.0.1]:60262 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1oyI4v-00011l-SJ
	for submit <at> debbugs.gnu.org; Thu, 24 Nov 2022 14:40:17 -0500
Received: from mail-oi1-f180.google.com ([209.85.167.180]:46761)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <stefankangas@HIDDEN>) id 1oyI4u-00011X-Cm
 for 58904 <at> debbugs.gnu.org; Thu, 24 Nov 2022 14:40:08 -0500
Received: by mail-oi1-f180.google.com with SMTP id r76so2415223oie.13
 for <58904 <at> debbugs.gnu.org>; Thu, 24 Nov 2022 11:40:08 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
 h=cc:to:subject:message-id:date:mime-version:references:in-reply-to
 :from:from:to:cc:subject:date:message-id:reply-to;
 bh=4Qi61wa5wp7V9NF3Rg0CreHcLZnLafqdqvmKQqeSC0A=;
 b=pzdjvXr5mhVqSY04BTpqaOrUwXT8V+xcrNAPVZ+O850uy0nteY65yzUU+eXT5xzYbd
 j7RwxV3a3/QleAxBtuhtjfzD3IXX/wbcq9z6PYr43PfYWa6pHU/Y+NH4RYRDjI9unHcc
 A1ReYDWhuQSQ8SL+rbg2zg/NuoIZ1zg1oANXvtIJX8AHVMV/j0Duw4EHWSvB9HTk/Eye
 XiBq3MbXhhCRsNH/szGxelLSGp755/NYWhhmsEF2arD+XiYW8fTkzO1oPdjtPBGWW10Q
 F8WsrCODTZOreIr1NtXrwlY6dRVS9zmj5XP7+VQ3tdt7Rli1Y+qch2tIJOWi7fM+L7OE
 j3lw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20210112;
 h=cc:to:subject:message-id:date:mime-version:references:in-reply-to
 :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
 bh=4Qi61wa5wp7V9NF3Rg0CreHcLZnLafqdqvmKQqeSC0A=;
 b=4G+qI6+S70JEe7+zwzi/Bncw4WQs3Irp3h61PaUIJXHaPC3+A+d8mgiywU7UJbV3TP
 HC8xF+q2n2vrqt3H65kgpwjjENYa5hBuQ9K+1jhjpWbSRfERWbUEFeNLV0kz1hRJjsIj
 PdEfNx5KG1bOUEB9FygRMRAQ1smMLvCk8qeZOtk7vb7GftKJl85aU0MCX6NYzGGviPTf
 iSUFQ4sUbprZ3FGh6aCP+dF63la6nQkrbc4YdwVWBdCS9g3ca4UTNFzXbZhoQQ9zzM0P
 Mq6bRL1KaoqPISY+QwNgIJWPOVUCzemyua4v6HZAFUPRJio5Zn5yOOmYGczLM9nUv4Rm
 Desg==
X-Gm-Message-State: ANoB5pkNsQ5a4ISdEQ4MK7x26cORX2zpdrmulB++J9V3PBwUoyuQCYew
 KtePrBym1EoKYSAClR65B1L0U3kWQPmxffXwhU1h31nD
X-Google-Smtp-Source: AA0mqf7gt036AeSagikeRIKtNISbjY6KdRj/sk+pZPVBreo4R86qpqnNsvNLFStIL2G2LUqIZSni6pbmhsFS5BhvgWs=
X-Received: by 2002:a05:6808:1287:b0:359:dc32:4f9e with SMTP id
 a7-20020a056808128700b00359dc324f9emr8533207oiw.92.1669318802836; Thu, 24 Nov
 2022 11:40:02 -0800 (PST)
Received: from 753933720722 named unknown by gmailapi.google.com with
 HTTPREST; Thu, 24 Nov 2022 11:40:02 -0800
From: Stefan Kangas <stefankangas@HIDDEN>
In-Reply-To: <87k04hdmnv.fsf@HIDDEN> (Philip Kaludercic's message of "Sun, 
 30 Oct 2022 21:30:44 +0000")
References: <87k04hdmnv.fsf@HIDDEN>
X-Hashcash: 1:20:221124:nicolas@HIDDEN::Eh1wjljFRphj/+J8:2TWk
MIME-Version: 1.0
Date: Thu, 24 Nov 2022 11:40:02 -0800
Message-ID: <CADwFkmmmp+uscGU13JO_2C=nhdg4N2cVbLLqoiVn=KgqUM8urg@HIDDEN>
Subject: Re: bug#58904: [PATCH] Handle buffer streams that operate on lines,
 pages, etc.
To: Philip Kaludercic <philipk@HIDDEN>
Content-Type: text/plain; charset="UTF-8"
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 58904
Cc: Nicolas Petton <nicolas@HIDDEN>, 58904 <at> debbugs.gnu.org
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: -1.0 (-)

Philip Kaludercic <philipk@HIDDEN> writes:

> Tags: patch
>
> The commentary for stream.el mentions that the following streams are
> supported:
>
>> ;; - buffers (by character)
>> ;; - buffers (by line)
>> ;; - buffers (by page)
>
> But I couldn't find anything beyond charachter-streams.  The following
> patch would implement that and more, by re-using thingatpt to define any
> kind of stream one would want.

Copying in Nicolas Petton, in case he has any comments.

> In GNU Emacs 29.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
>  3.24.30, cairo version 1.16.0) of 2022-10-30 built on heron
> Repository revision: 2a4f37fe520b4f18295cff6671f289a47c1578df
> Repository branch: feature/package+vc
> System Description: Guix System
>
> Configured using:
>  'configure --with-pgtk --with-imagemagick
>  PKG_CONFIG_PATH=/gnu/store/ssg343s6ldqdwh30136pnawhbgd0cb6i-profile/lib/pkgconfig:/gnu/store/ssg343s6ldqdwh30136pnawhbgd0cb6i-profile/share/pkgconfig'
>
>>From 1593ba1da6a5caad7f74603ce9f8d5bf1e55de77 Mon Sep 17 00:00:00 2001
> From: Philip Kaludercic <philipk@HIDDEN>
> Date: Sun, 30 Oct 2022 22:28:25 +0100
> Subject: [PATCH] Handle buffer streams that operate on lines, pages, etc.
>
> * stream.el (stream): Add optional argument THING.
>
> This is promised by the package commentary but apparently wasn't
> actually implemented.
> ---
>  stream.el | 48 ++++++++++++++++++++++++++++++++++--------------
>  1 file changed, 34 insertions(+), 14 deletions(-)
>
> diff --git a/stream.el b/stream.el
> index eb81b14220..d8d4bfc3c7 100644
> --- a/stream.el
> +++ b/stream.el
> @@ -1,6 +1,6 @@
>  ;;; stream.el --- Implementation of streams  -*- lexical-binding: t -*-
>
> -;; Copyright (C) 2016-2020 Free Software Foundation, Inc.
> +;; Copyright (C) 2016-2020, 2022 Free Software Foundation, Inc.
>
>  ;; Author: Nicolas Petton <nicolas@HIDDEN>
>  ;; Keywords: stream, laziness, sequences
> @@ -120,22 +120,42 @@ SEQ can be a list, vector or string."
>       (car list)
>       (stream (cdr list)))))
>
> -(cl-defmethod stream ((buffer buffer) &optional pos)
> +(cl-defmethod stream ((buffer buffer) &optional pos thing)
>    "Return a stream of the characters of the buffer BUFFER.
> -BUFFER may be a buffer or a string (buffer name).
> -The sequence starts at POS if non-nil, `point-min' otherwise."
> +BUFFER may be a buffer or a string (buffer name).  The sequence
> +starts at POS if non-nil, `point-min' otherwise.  By default the
> +stream will consist of characters.  If THING is non-nil, it must
> +be a symbol supported by `thing-at-point' and `forward-thing'
> +that will be used to extract and navigate through things.
> +Examples include \\='line, \\='page, or \\='defun."
>    (with-current-buffer buffer
>      (unless pos (setq pos (point-min)))
> -    (if (>= pos (point-max))
> -        (stream-empty))
> -    (stream-cons
> -     (with-current-buffer buffer
> -       (save-excursion
> -         (save-restriction
> -           (widen)
> -           (goto-char pos)
> -           (char-after (point)))))
> -     (stream buffer (1+ pos)))))
> +    (cond
> +     ((>= pos (point-max))
> +      (stream-empty))
> +     ((not (null thing))
> +      (with-current-buffer buffer
> +        (let ((this (save-excursion
> +                      (save-restriction
> +                        (widen)
> +                        (goto-char pos)
> +                        (thing-at-point thing))))
> +              (next (save-excursion
> +                      (save-restriction
> +                        (widen)
> +                        (goto-char pos)
> +                        (forward-thing thing)
> +                        (point)))))
> +          (stream-cons this (stream buffer next thing)))))
> +     ((null thing)
> +      (stream-cons
> +       (with-current-buffer buffer
> +         (save-excursion
> +           (save-restriction
> +             (widen)
> +             (goto-char pos)
> +             (char-after (point)))))
> +       (stream buffer (1+ pos)))))))
>
>  (declare-function iter-next "generator")




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#58904; Package emacs. Full text available.
Severity set to 'wishlist' from 'normal' Request was from Stefan Kangas <stefankangas@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

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


Received: (at submit) by debbugs.gnu.org; 30 Oct 2022 21:31:16 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Oct 30 17:31:16 2022
Received: from localhost ([127.0.0.1]:39092 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1opFtj-0000ML-Qu
	for submit <at> debbugs.gnu.org; Sun, 30 Oct 2022 17:31:16 -0400
Received: from lists.gnu.org ([209.51.188.17]:37026)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <philipk@HIDDEN>) id 1opFte-0000MA-S9
 for submit <at> debbugs.gnu.org; Sun, 30 Oct 2022 17:31:14 -0400
Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <philipk@HIDDEN>)
 id 1opFte-0001Wv-Eh
 for bug-gnu-emacs@HIDDEN; Sun, 30 Oct 2022 17:31:10 -0400
Received: from mout01.posteo.de ([185.67.36.65])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <philipk@HIDDEN>)
 id 1opFtb-0007KE-RY
 for bug-gnu-emacs@HIDDEN; Sun, 30 Oct 2022 17:31:09 -0400
Received: from submission (posteo.de [185.67.36.169]) 
 by mout01.posteo.de (Postfix) with ESMTPS id 28853240027
 for <bug-gnu-emacs@HIDDEN>; Sun, 30 Oct 2022 22:31:04 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017;
 t=1667165465; bh=dWiO4B851XwgKMIwJ5dtBT+LLuR/IMo6vQXGCcSgeY4=;
 h=From:To:Subject:Autocrypt:Date:From;
 b=f/x46KyB/2sKWm+9jU32jUUypbunVcjrzY4fpE2rO/Q72sTuAG7kQY5xtNoyVe5f5
 707ITgqtNeqAo7RuWi7235y6J/zTcbc9mpeFBVp7AkKaRKJBwT4TweCwoXiKWzbT0w
 QG1aQbQSs9DKIC42B0Mz8CGsJ4rsqkFZUpwp6K9PiaEErOAdOuGcKEQvVkqi9mnFQA
 40CJYE3Nl2hhauLauqGHMX54KGOgwSbqCnoKSUWf9n+7udAveD2k5TTYJ6muE/WpjP
 AHcdiJjVTSa6ahPkIJinWLHQCLeeRxqr8yy2vIpqb9ajwOs2eo4TFVUmivmA45Co/K
 iZbFmYQlkF90A==
Received: from customer (localhost [127.0.0.1])
 by submission (posteo.de) with ESMTPSA id 4N0qGJ3Gz2z6tmB
 for <bug-gnu-emacs@HIDDEN>; Sun, 30 Oct 2022 22:31:01 +0100 (CET)
From: Philip Kaludercic <philipk@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: [PATCH] Handle buffer streams that operate on lines, pages, etc.
Autocrypt: addr=philipk@HIDDEN; prefer-encrypt=nopreference; keydata=
 mDMEYHHqUhYJKwYBBAHaRw8BAQdAp3GdmYJ6tm5McweY6dEvIYIiry+Oz9rU4MH6NHWK0Ee0QlBo
 aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0
 ZW8ubmV0PoiQBBMWCAA4FiEEDM2H44ZoPt9Ms0eHtVrAHPRh1FwFAmBx6lICGwMFCwkIBwIGFQoJ
 CAsCBBYCAwECHgECF4AACgkQtVrAHPRh1FyTkgEAjlbGPxFchvMbxzAES3r8QLuZgCxeAXunM9gh
 io0ePtUBALVhh9G6wIoZhl0gUCbQpoN/UJHI08Gm1qDob5zDxnIHuDgEYHHqUhIKKwYBBAGXVQEF
 AQEHQNcRB+MUimTMqoxxMMUERpOR+Q4b1KgncDZkhrO2ql1tAwEIB4h4BBgWCAAgFiEEDM2H44Zo
 Pt9Ms0eHtVrAHPRh1FwFAmBx6lICGwwACgkQtVrAHPRh1Fw1JwD/Qo7kvtib8jy7puyWrSv0MeTS
 g8qIxgoRWJE/KKdkCLEA/jb9b9/g8nnX+UcwHf/4VfKsjExlnND3FrBviXUW6NcB
Date: Sun, 30 Oct 2022 21:30:44 +0000
Message-ID: <87k04hdmnv.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
Received-SPF: pass client-ip=185.67.36.65; envelope-from=philipk@HIDDEN;
 helo=mout01.posteo.de
X-Spam_score_int: -20
X-Spam_score: -2.1
X-Spam_bar: --
X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001,
 SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: -1.3 (-)
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: -2.3 (--)

--=-=-=
Content-Type: text/plain

Tags: patch

Tags: patch


The commentary for stream.el mentions that the following streams are
supported:

> ;; - buffers (by character)
> ;; - buffers (by line)
> ;; - buffers (by page)

But I couldn't find anything beyond charachter-streams.  The following
patch would implement that and more, by re-using thingatpt to define any
kind of stream one would want.

In GNU Emacs 29.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 3.24.30, cairo version 1.16.0) of 2022-10-30 built on heron
Repository revision: 2a4f37fe520b4f18295cff6671f289a47c1578df
Repository branch: feature/package+vc
System Description: Guix System

Configured using:
 'configure --with-pgtk --with-imagemagick
 PKG_CONFIG_PATH=/gnu/store/ssg343s6ldqdwh30136pnawhbgd0cb6i-profile/lib/pkgconfig:/gnu/store/ssg343s6ldqdwh30136pnawhbgd0cb6i-profile/share/pkgconfig'


--=-=-=
Content-Type: text/patch
Content-Disposition: attachment;
 filename=0001-Handle-buffer-streams-that-operate-on-lines-pages-et.patch

From 1593ba1da6a5caad7f74603ce9f8d5bf1e55de77 Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@HIDDEN>
Date: Sun, 30 Oct 2022 22:28:25 +0100
Subject: [PATCH] Handle buffer streams that operate on lines, pages, etc.

* stream.el (stream): Add optional argument THING.

This is promised by the package commentary but apparently wasn't
actually implemented.
---
 stream.el | 48 ++++++++++++++++++++++++++++++++++--------------
 1 file changed, 34 insertions(+), 14 deletions(-)

diff --git a/stream.el b/stream.el
index eb81b14220..d8d4bfc3c7 100644
--- a/stream.el
+++ b/stream.el
@@ -1,6 +1,6 @@
 ;;; stream.el --- Implementation of streams  -*- lexical-binding: t -*-
 
-;; Copyright (C) 2016-2020 Free Software Foundation, Inc.
+;; Copyright (C) 2016-2020, 2022 Free Software Foundation, Inc.
 
 ;; Author: Nicolas Petton <nicolas@HIDDEN>
 ;; Keywords: stream, laziness, sequences
@@ -120,22 +120,42 @@ SEQ can be a list, vector or string."
      (car list)
      (stream (cdr list)))))
 
-(cl-defmethod stream ((buffer buffer) &optional pos)
+(cl-defmethod stream ((buffer buffer) &optional pos thing)
   "Return a stream of the characters of the buffer BUFFER.
-BUFFER may be a buffer or a string (buffer name).
-The sequence starts at POS if non-nil, `point-min' otherwise."
+BUFFER may be a buffer or a string (buffer name).  The sequence
+starts at POS if non-nil, `point-min' otherwise.  By default the
+stream will consist of characters.  If THING is non-nil, it must
+be a symbol supported by `thing-at-point' and `forward-thing'
+that will be used to extract and navigate through things.
+Examples include \\='line, \\='page, or \\='defun."
   (with-current-buffer buffer
     (unless pos (setq pos (point-min)))
-    (if (>= pos (point-max))
-        (stream-empty))
-    (stream-cons
-     (with-current-buffer buffer
-       (save-excursion
-         (save-restriction
-           (widen)
-           (goto-char pos)
-           (char-after (point)))))
-     (stream buffer (1+ pos)))))
+    (cond
+     ((>= pos (point-max))
+      (stream-empty))
+     ((not (null thing))
+      (with-current-buffer buffer
+        (let ((this (save-excursion
+                      (save-restriction
+                        (widen)
+                        (goto-char pos)
+                        (thing-at-point thing))))
+              (next (save-excursion
+                      (save-restriction
+                        (widen)
+                        (goto-char pos)
+                        (forward-thing thing)
+                        (point)))))
+          (stream-cons this (stream buffer next thing)))))
+     ((null thing)
+      (stream-cons
+       (with-current-buffer buffer
+         (save-excursion
+           (save-restriction
+             (widen)
+             (goto-char pos)
+             (char-after (point)))))
+       (stream buffer (1+ pos)))))))
 
 (declare-function iter-next "generator")
 
-- 
2.38.0


--=-=-=--




Acknowledgement sent to Philip Kaludercic <philipk@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#58904; 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, 24 Nov 2022 19:45:02 UTC

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