From: Emanuel Berg <incal@dataswamp.org>
To: emacs-devel@gnu.org
Subject: Re: buffer-crunch.el
Date: Sun, 21 Jul 2024 00:44:50 +0200 [thread overview]
Message-ID: <87wmlf65ul.fsf@dataswamp.org> (raw)
In-Reply-To: 87zfqc53o9.fsf@dataswamp.org
This is version 0.2.1, same URL. Hit the reload button until
you see it or force your cache to empty first.
I have removed a couple of complicated things and made them
into set functions.
Don't know how much faster it became but the code
looks cooler.
I also tried it against the old 'buffer-sentences' which was
dedicated `sentence-at-point' and `forward-sentence', and
inputting those as 'read' and 'next' yields the same result.
So all good! But I'm sure it can be improved still.
;;; -*- lexical-binding: t -*-
;;
;; this file:
;; https://dataswamp.org/~incal/emacs-init/buffer-crunch.el [version 0.2.1]
;;
;; All features shown as examples:
;;
;; 1. Just a forward function:
;;
;; (buffer-crunch #'forward-line)
;;
;; 2. A forward function and endpoints:
;;
;; (buffer-crunch #'forward-word nil 10 100)
;;
;; 3. A forward function and a custom read function:
;;
;; (buffer-crunch #'forward-word (lambda () (word-at-point t)))
;;
;; 4. A custom forward function and custom read function:
;; This forward function will overflow the buffer, but
;; that isn't a problem here.
;;
;; (buffer-crunch (lambda () (forward-char 42)) (lambda () (word-at-point t)))
(require 'cl-lib)
(require 'thingatpt)
(defun strings-tidy (strs)
(let ((tst #'string=))
(cl-remove "" (cl-remove-duplicates (sort strs) :test tst) :test tst) ))
(defun wash-string (str)
(string-trim (replace-regexp-in-string "[\n\t[:space:]]+" " " str)) )
(defun buffer-crunch (next &optional read beg end)
(or beg (setq beg (point-min)))
(or end (setq end (point-max)))
(save-mark-and-excursion
(goto-char beg)
(cl-loop
with fst
with otr
with strs
with mov = t
while (and (< (point) end) mov) do
(setq fst (point))
(condition-case nil
(apply next nil)
(error (goto-char end)) )
(setq otr (point))
(if (< fst otr)
(push (or (and read (apply read nil))
(buffer-substring-no-properties fst otr) )
strs)
(setq mov nil) )
finally return (strings-tidy (cl-map 'list #'wash-string strs)) )))
(provide 'buffer-crunch)
--
underground experts united
https://dataswamp.org/~incal
next prev parent reply other threads:[~2024-07-20 22:44 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-20 18:17 buffer-crunch.el Emanuel Berg
2024-07-20 22:44 ` Emanuel Berg [this message]
2024-07-20 23:32 ` buffer-crunch.el Emanuel Berg
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87wmlf65ul.fsf@dataswamp.org \
--to=incal@dataswamp.org \
--cc=emacs-devel@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 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.