From: Philip Kaludercic <philipk@posteo.net>
To: 58904@debbugs.gnu.org
Subject: bug#58904: [PATCH] Handle buffer streams that operate on lines, pages, etc.
Date: Sun, 30 Oct 2022 21:30:44 +0000 [thread overview]
Message-ID: <87k04hdmnv.fsf@posteo.net> (raw)
[-- 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
next reply other threads:[~2022-10-30 21:30 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-30 21:30 Philip Kaludercic [this message]
2022-11-24 19:40 ` bug#58904: [PATCH] Handle buffer streams that operate on lines, pages, etc Stefan Kangas
2023-09-07 20:36 ` Stefan Kangas
2023-09-08 7:46 ` Philip Kaludercic
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87k04hdmnv.fsf@posteo.net \
--to=philipk@posteo.net \
--cc=58904@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).