all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#58904: [PATCH] Handle buffer streams that operate on lines, pages, etc.
@ 2022-10-30 21:30 Philip Kaludercic
  2022-11-24 19:40 ` Stefan Kangas
  0 siblings, 1 reply; 2+ messages in thread
From: Philip Kaludercic @ 2022-10-30 21:30 UTC (permalink / raw)
  To: 58904

[-- Attachment #1: Type: text/plain, Size: 838 bytes --]

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'


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Handle-buffer-streams-that-operate-on-lines-pages-et.patch --]
[-- Type: text/patch, Size: 2956 bytes --]

From 1593ba1da6a5caad7f74603ce9f8d5bf1e55de77 Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@posteo.net>
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@petton.fr>
 ;; 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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* bug#58904: [PATCH] Handle buffer streams that operate on lines, pages, etc.
  2022-10-30 21:30 bug#58904: [PATCH] Handle buffer streams that operate on lines, pages, etc Philip Kaludercic
@ 2022-11-24 19:40 ` Stefan Kangas
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Kangas @ 2022-11-24 19:40 UTC (permalink / raw)
  To: Philip Kaludercic; +Cc: Nicolas Petton, 58904

Philip Kaludercic <philipk@posteo.net> 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@posteo.net>
> 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@petton.fr>
>  ;; 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")





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-11-24 19:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-30 21:30 bug#58904: [PATCH] Handle buffer streams that operate on lines, pages, etc Philip Kaludercic
2022-11-24 19:40 ` Stefan Kangas

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.