From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Kangas Newsgroups: gmane.emacs.bugs Subject: bug#58904: [PATCH] Handle buffer streams that operate on lines, pages, etc. Date: Thu, 24 Nov 2022 11:40:02 -0800 Message-ID: References: <87k04hdmnv.fsf@posteo.net> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7203"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Nicolas Petton , 58904@debbugs.gnu.org To: Philip Kaludercic Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Nov 24 23:07:58 2022 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 1oyKNx-0001Xt-GV for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 24 Nov 2022 23:07:57 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyI5v-0004jg-9n; Thu, 24 Nov 2022 14:41:11 -0500 Original-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 1oyI5n-0004i3-DW for bug-gnu-emacs@gnu.org; Thu, 24 Nov 2022 14:41:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oyI5m-0006tF-Ex for bug-gnu-emacs@gnu.org; Thu, 24 Nov 2022 14:41:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oyI5m-00014Z-0Z for bug-gnu-emacs@gnu.org; Thu, 24 Nov 2022 14:41:02 -0500 X-Loop: help-debbugs@gnu.org 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 Original-Received: via spool by 58904-submit@debbugs.gnu.org id=B58904.16693188173972 (code B ref 58904); Thu, 24 Nov 2022 19:41:01 +0000 Original-Received: (at 58904) by debbugs.gnu.org; 24 Nov 2022 19:40:17 +0000 Original-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 Original-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 Original-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) Original-Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Thu, 24 Nov 2022 11:40:02 -0800 In-Reply-To: <87k04hdmnv.fsf@posteo.net> (Philip Kaludercic's message of "Sun, 30 Oct 2022 21:30:44 +0000") X-Hashcash: 1:20:221124:nicolas@petton.fr::Eh1wjljFRphj/+J8:2TWk 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:248923 Archived-At: 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")