From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.bugs Subject: bug#58904: [PATCH] Handle buffer streams that operate on lines, pages, etc. Date: Sun, 30 Oct 2022 21:30:44 +0000 Message-ID: <87k04hdmnv.fsf@posteo.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="35209"; mail-complaints-to="usenet@ciao.gmane.io" To: 58904@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Oct 30 22:32:27 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 1opFus-0008t2-3v for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 30 Oct 2022 22:32:26 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1opFuX-0001ay-Qt; Sun, 30 Oct 2022 17:32:05 -0400 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 1opFuV-0001ad-2a for bug-gnu-emacs@gnu.org; Sun, 30 Oct 2022 17:32:03 -0400 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 1opFuU-0007c4-OG for bug-gnu-emacs@gnu.org; Sun, 30 Oct 2022 17:32:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1opFuU-0000NP-BM for bug-gnu-emacs@gnu.org; Sun, 30 Oct 2022 17:32:02 -0400 X-Loop: help-debbugs@gnu.org 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 X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.16671654761389 (code B ref -1); Sun, 30 Oct 2022 21:32:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 30 Oct 2022 21:31:16 +0000 Original-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 Original-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 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 1opFte-0001Wv-Eh for bug-gnu-emacs@gnu.org; Sun, 30 Oct 2022 17:31:10 -0400 Original-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 Original-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== Original-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) 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 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-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: , Original-Sender: "bug-gnu-emacs" Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:246651 Archived-At: --=-=-= 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 --=-=-=--