From unknown Sat Jul 26 23:24:22 2025 X-Loop: help-debbugs@gnu.org Subject: bug#58904: [PATCH] Handle buffer streams that operate on lines, pages, etc. Resent-From: Philip Kaludercic Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 30 Oct 2022 21:32:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 58904 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: 58904@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.16671654761389 (code B ref -1); Sun, 30 Oct 2022 21:32:02 +0000 Received: (at submit) by debbugs.gnu.org; 30 Oct 2022 21:31:16 +0000 Received: from localhost ([127.0.0.1]:39092 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1opFtj-0000ML-Qu for submit@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 ) id 1opFte-0000MA-S9 for submit@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 ) id 1opFte-0001Wv-Eh for bug-gnu-emacs@gnu.org; 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 ) id 1opFtb-0007KE-RY for bug-gnu-emacs@gnu.org; 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 ; 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 ; Sun, 30 Oct 2022 22:31:01 +0100 (CET) From: Philip Kaludercic Autocrypt: addr=philipk@posteo.net; 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@posteo.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=185.67.36.65; envelope-from=philipk@posteo.net; 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-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" 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 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 ;; 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 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sat Nov 12 15:34:01 2022 Received: (at control) by debbugs.gnu.org; 12 Nov 2022 20:34:01 +0000 Received: from localhost ([127.0.0.1]:49126 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1otxCS-0004jf-UT for submit@debbugs.gnu.org; Sat, 12 Nov 2022 15:34:01 -0500 Received: from mail-oi1-f174.google.com ([209.85.167.174]:42655) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1otxCQ-0004jE-OW for control@debbugs.gnu.org; Sat, 12 Nov 2022 15:33:59 -0500 Received: by mail-oi1-f174.google.com with SMTP id q186so7943739oia.9 for ; Sat, 12 Nov 2022 12:33:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:mime-version:from:from:to:cc:subject :date:message-id:reply-to; bh=XnyBEjZUZRkSxvBEZ6KH3gIUWkLxKRLUJ8nT/XgHvYk=; b=oBa+pJWQjyAwTVFDvAVaMUwbVdzujywu0eEVD7kl968l73l/yUWgXTBCRXyUTbKGKW 8OxN0B2YLcPz1j4Rm/cPjkd/YkpZRnlI4YbUHmbNlNwmAR/J5IBXzi7N0l8OI00+poHi NIbWkRQzkSMWcLe+CODPlH2W4rfRC2QY5sNHjFmhEaOtl6NZTY99gqw19puhxgEKtAjJ 8Z9Obul6GVk7e6FmeAOIheD01d5xTwSMAj/IzXtHR36L6tUlFpqB1eQ54P1H/BAw/kyU qUKTt0L6EDnubLTQmdMxY7vlF/qKWI61gTWrwWGr9bpzkmdPcrMGEFHaqbXm4y5L9JhR g1cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:mime-version:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=XnyBEjZUZRkSxvBEZ6KH3gIUWkLxKRLUJ8nT/XgHvYk=; b=MqaNqkKHaHbhwyVzn5WsYLeXgAMM25PSM+Ldnc9rsFblSb3XYX/i2UmTjDv/AkuoQX HPFmHykNpmeIVl6UtIN6cNZ8H3SGSBkQt/XKA+WRNeEiFqROjL4/b44kiLJz1TYe2Ijq lbXd74ag8/3w2feoOq1DtOb51oms7mr1T4MfGWNeHJukszXiC0g2UPwU0+YrFhJHRSHR HrJtpzuPUZ89rFwauG1Xq4yynJ6Ls+fJX73iTtyPF6Zr3ncZN1xN73DCnM0txsevl25X loruHd2odnULp8YGUTMPQMllogvgnhGd8ImaSAYbMmgDJ8CO9tFJqnq71iwHMjunBxoW e4og== X-Gm-Message-State: ANoB5pn82T63dKeI1iB8OWlJunsvG4x3/SloZKkUqjTlnZSOMqvU4RcH UL56wGyN+7DUbRRMBwEvHrcY9/ylrZL00KY2fX0ODgCJ X-Google-Smtp-Source: AA0mqf7UNAz6pA15Ej7/O6ZD/WxxZcB7HfvvIgjeaAqeU3tpvSb4XTkNC1eMYJMWT+EhphG5KB53i9xdrrP0A6OIaVk= X-Received: by 2002:a54:4889:0:b0:359:dc32:4f9e with SMTP id r9-20020a544889000000b00359dc324f9emr3169198oic.92.1668285233252; Sat, 12 Nov 2022 12:33:53 -0800 (PST) Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Sat, 12 Nov 2022 12:33:52 -0800 From: Stefan Kangas X-Hashcash: 1:20:221112:control@debbugs.gnu.org::bChZdpQvNAnlEoY7:1z+8 MIME-Version: 1.0 Date: Sat, 12 Nov 2022 12:33:52 -0800 Message-ID: Subject: control message for bug #58904 To: control@debbugs.gnu.org Content-Type: text/plain; charset="UTF-8" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) severity 58904 wishlist quit From unknown Sat Jul 26 23:24:22 2025 X-Loop: help-debbugs@gnu.org Subject: bug#58904: [PATCH] Handle buffer streams that operate on lines, pages, etc. Resent-From: Stefan Kangas Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 24 Nov 2022 19:41:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58904 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Philip Kaludercic Cc: Nicolas Petton , 58904@debbugs.gnu.org Received: via spool by 58904-submit@debbugs.gnu.org id=B58904.16693188173972 (code B ref 58904); Thu, 24 Nov 2022 19:41:01 +0000 Received: (at 58904) by debbugs.gnu.org; 24 Nov 2022 19:40:17 +0000 Received: from localhost ([127.0.0.1]:60262 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oyI4v-00011l-SJ for submit@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 ) id 1oyI4u-00011X-Cm for 58904@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@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 In-Reply-To: <87k04hdmnv.fsf@posteo.net> (Philip Kaludercic's message of "Sun, 30 Oct 2022 21:30:44 +0000") References: <87k04hdmnv.fsf@posteo.net> X-Hashcash: 1:20:221124:nicolas@petton.fr::Eh1wjljFRphj/+J8:2TWk MIME-Version: 1.0 Date: Thu, 24 Nov 2022 11:40:02 -0800 Message-ID: Content-Type: text/plain; charset="UTF-8" X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Philip Kaludercic 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 > 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 > ;; 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") From unknown Sat Jul 26 23:24:22 2025 X-Loop: help-debbugs@gnu.org Subject: bug#58904: [PATCH] Handle buffer streams that operate on lines, pages, etc. Resent-From: Stefan Kangas Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 07 Sep 2023 20:37:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58904 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Philip Kaludercic Cc: Nicolas Petton , 58904@debbugs.gnu.org Received: via spool by 58904-submit@debbugs.gnu.org id=B58904.169411899526301 (code B ref 58904); Thu, 07 Sep 2023 20:37:02 +0000 Received: (at 58904) by debbugs.gnu.org; 7 Sep 2023 20:36:35 +0000 Received: from localhost ([127.0.0.1]:41482 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qeLjt-0006q6-0z for submit@debbugs.gnu.org; Thu, 07 Sep 2023 16:36:35 -0400 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]:61739) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qeLjm-0006pl-8X for 58904@debbugs.gnu.org; Thu, 07 Sep 2023 16:36:31 -0400 Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-5007616b756so2315858e87.3 for <58904@debbugs.gnu.org>; Thu, 07 Sep 2023 13:36:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694118978; x=1694723778; darn=debbugs.gnu.org; h=cc:to:subject:message-id:date:mime-version:references:in-reply-to :from:from:to:cc:subject:date:message-id:reply-to; bh=PFYhVdDjeZtvuCDN2OEXmtzUIzguT2zF07r/+Jbp9wY=; b=Jf0GhU9j4inmDBPORu4EHdmJpbFEp5fjvONwxdOrFGzvROZfpw9K7+11fVzwGt0bzN dcsXlw/lZvc7NR4QmPMIxFACFqhqV6ki0ISvvJMpBv1CDQfKsxl9h4boOK8lb5rKdRse LPvFKLpM4mYww5b9fnE5wFnqTP5ailhRzbv1Yjx5ArL66rQiF+pMrwX1lwaNmkTh6cDK j9mI06q+WhPTFS8D8x9xN5rgARRNQP7NIEUYkZew+h+n6WvpVwVMYT+Sc7PvwYp6b250 AvbXgbdfAijq4e9VY5AFgyqpxapNvIUEeJwnk/vtWarymowZSQ7fabxBfj6b0bWI4TIx j5Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694118978; x=1694723778; 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=PFYhVdDjeZtvuCDN2OEXmtzUIzguT2zF07r/+Jbp9wY=; b=Fc/aOjHY8wRpcs7gvMroYfALgQLCz4FoMQ45g19M9aNs7U6QJaeA62mradR4Cb6rHl 90MTVLaUFssfZxiwBrS51hiJ5tDEI3w9XaOm9rFHR3ziD8madEjwsQCChz9lJJgoNE3G 0AOoEIL0njmE9DdJcFBdWOz9eWZ3wRSt4fvhr5kn4gWkalJXTkKyzpOp3+LZCTQ34GDy 6iB5hoeYVFB/7XKlxXZdbOcVzT3QKdcI+c2DMfOWWLe+uyDcbsFGxk9zl7Xene6+fg4v 67DmtueJF17k2YWj3jMAHcSca4m5nuerOlzHrLKcRFYob/eJuVrns2lJOkF28795UW2Q Uc9w== X-Gm-Message-State: AOJu0YyRja+XisQZFR5n9mnfJnbK3sTJRXGZEzTyNEBZvOfjpw4WRAwV 7C1mDaKL5guW4zFhObDMCUGBmINaln/c2dPTfAo= X-Google-Smtp-Source: AGHT+IFkmz0cRuxWXG0lQjwUC6Mx7/5/hLleki33zGU55anRTbmjs5CXjs3NhmjNh02zcbzPpMKAIxIecBgTe0Fp1yI= X-Received: by 2002:ac2:4bc7:0:b0:4fe:5860:7abf with SMTP id o7-20020ac24bc7000000b004fe58607abfmr432702lfq.13.1694118977934; Thu, 07 Sep 2023 13:36:17 -0700 (PDT) Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Thu, 7 Sep 2023 13:36:17 -0700 From: Stefan Kangas In-Reply-To: (Stefan Kangas's message of "Thu, 24 Nov 2022 11:40:02 -0800") References: <87k04hdmnv.fsf@posteo.net> MIME-Version: 1.0 Date: Thu, 7 Sep 2023 13:36:17 -0700 Message-ID: Content-Type: text/plain; charset="UTF-8" X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Philip, Stefan Kangas writes: > Philip Kaludercic writes: > >> The commentary for stream.el mentions that the following streams are >> supported: (That's the `stream' package on GNU ELPA, to be clear.) >>> ;; - 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. Nicolas didn't seem to have any comments, so please go ahead and install this if you think it makes sense. I guess you could also bump the version, if you think that makes sense. >> -;; Copyright (C) 2016-2020 Free Software Foundation, Inc. >> +;; Copyright (C) 2016-2020, 2022 Free Software Foundation, Inc. It's okay to write it like this: 2016-2023 From unknown Sat Jul 26 23:24:22 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: Philip Kaludercic Subject: bug#58904: closed (Re: bug#58904: [PATCH] Handle buffer streams that operate on lines, pages, etc.) Message-ID: References: <874jk585v3.fsf@posteo.net> <87k04hdmnv.fsf@posteo.net> X-Gnu-PR-Message: they-closed 58904 X-Gnu-PR-Package: emacs X-Gnu-PR-Keywords: patch Reply-To: 58904@debbugs.gnu.org Date: Fri, 08 Sep 2023 07:47:03 +0000 Content-Type: multipart/mixed; boundary="----------=_1694159223-28936-1" This is a multi-part message in MIME format... ------------=_1694159223-28936-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #58904: [PATCH] Handle buffer streams that operate on lines, pages, etc. which was filed against the emacs package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 58904@debbugs.gnu.org. --=20 58904: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D58904 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1694159223-28936-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 58904-done) by debbugs.gnu.org; 8 Sep 2023 07:46:39 +0000 Received: from localhost ([127.0.0.1]:42082 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qeWCM-0007VU-OG for submit@debbugs.gnu.org; Fri, 08 Sep 2023 03:46:39 -0400 Received: from mout01.posteo.de ([185.67.36.65]:49959) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qeWCI-0007VF-9U for 58904-done@debbugs.gnu.org; Fri, 08 Sep 2023 03:46:37 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id 7D32A24002B for <58904-done@debbugs.gnu.org>; Fri, 8 Sep 2023 09:46:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1694159186; bh=1c0D24ETCz3/xeqVB4UQS8SNAgHe1GdEJVkLIoXxA5o=; h=From:To:Cc:Subject:Autocrypt:Date:Message-ID:MIME-Version:From; b=cvEMmx2wZwqKMSg1Q1k/y+RkQMTBMNfXk541M3Hx/rFTsT+4eMCRhcHzijWw8zWXD 626Nm482yOx+IzHZYpAI6RN/K6CKQY1Cx7rZfOebEugFdj7qu+g1eTDhOfwtF0jj+X z1Lu6cYpU/SxKxnAQRrWquuprFW05acbNp20UNMAqNSqGypp6sg1CUwlwBpV8UP/GE /+K1DLRlA9ZIWhnHAEizZvHyE1/vyfHzYTS2gOqGZY9BxEFKjuohhsSMnfTDmiafvr asOL+pmt5W6kzgsinkYtoUwOFPEB8pmYOQf3v7aDK26w9H30dTrVLpLpf/6Y1N/btZ xZMGmZmd9nf2g== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Rhp8K5ZC1z6txb; Fri, 8 Sep 2023 09:46:25 +0200 (CEST) From: Philip Kaludercic To: Stefan Kangas Subject: Re: bug#58904: [PATCH] Handle buffer streams that operate on lines, pages, etc. In-Reply-To: (Stefan Kangas's message of "Thu, 7 Sep 2023 13:36:17 -0700") References: <87k04hdmnv.fsf@posteo.net> X-Hashcash: 1:20:230908:stefankangas@gmail.com::2aUMnuF3WBDyDB+a:B2L X-Hashcash: 1:20:230908:58904@debbugs.gnu.org::crEqnc6ZTpfmtgAF:06od X-Hashcash: 1:20:230908:nicolas@petton.fr::TG74XvPrYn8lUhoF:36DO Autocrypt: addr=philipk@posteo.net; keydata= mDMEZBBQQhYJKwYBBAHaRw8BAQdAHJuofBrfqFh12uQu0Yi7mrl525F28eTmwUDflFNmdui0QlBo aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0 ZW8ubmV0PoiWBBMWCAA+FiEEDg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwMFCQHhM4AFCwkI BwIGFQoJCAsCBBYCAwECHgECF4AACgkQ8xYDWXahwulikAEA77hloUiSrXgFkUVJhlKBpLCHUjA0 mWZ9j9w5d08+jVwBAK6c4iGP7j+/PhbkxaEKa4V3MzIl7zJkcNNjHCXmvFcEuDgEZBBQQhIKKwYB BAGXVQEFAQEHQI5NLiLRjZy3OfSt1dhCmFyn+fN/QKELUYQetiaoe+MMAwEIB4h+BBgWCAAmFiEE Dg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwwFCQHhM4AACgkQ8xYDWXahwukm+wEA8cml4JpK NeAu65rg+auKrPOP6TP/4YWRCTIvuYDm0joBALw98AMz7/qMHvSCeU/hw9PL6u6R2EScxtpKnWof z4oM Date: Fri, 08 Sep 2023 07:46:24 +0000 Message-ID: <874jk585v3.fsf@posteo.net> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 58904-done Cc: 58904-done@debbugs.gnu.org, Nicolas Petton X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Stefan Kangas writes: > Philip, > > Stefan Kangas writes: > >> Philip Kaludercic writes: >> >>> The commentary for stream.el mentions that the following streams are >>> supported: > > (That's the `stream' package on GNU ELPA, to be clear.) > >>>> ;; - 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. > > Nicolas didn't seem to have any comments, so please go ahead and install > this if you think it makes sense. > > I guess you could also bump the version, if you think that makes sense. Done and done. >>> -;; Copyright (C) 2016-2020 Free Software Foundation, Inc. >>> +;; Copyright (C) 2016-2020, 2022 Free Software Foundation, Inc. > > It's okay to write it like this: 2016-2023 That change was made by `copyright-update', but I have updated it manually. -- Philip Kaludercic ------------=_1694159223-28936-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 30 Oct 2022 21:31:16 +0000 Received: from localhost ([127.0.0.1]:39092 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1opFtj-0000ML-Qu for submit@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 ) id 1opFte-0000MA-S9 for submit@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 ) id 1opFte-0001Wv-Eh for bug-gnu-emacs@gnu.org; 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 ) id 1opFtb-0007KE-RY for bug-gnu-emacs@gnu.org; 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 ; 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 ; Sun, 30 Oct 2022 22:31:01 +0100 (CET) From: Philip Kaludercic To: bug-gnu-emacs@gnu.org Subject: [PATCH] Handle buffer streams that operate on lines, pages, etc. Autocrypt: addr=philipk@posteo.net; 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@posteo.net> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=185.67.36.65; envelope-from=philipk@posteo.net; 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@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" 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 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 ;; 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 --=-=-=-- ------------=_1694159223-28936-1--