help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: buffer substring of only visible text


From: Michael Heerdegen
Subject: Re: buffer substring of only visible text
Date: Thu, 22 Sep 2022 11:14:54 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Samuel Wales <samologist@gmail.com> writes:

> i want to copy visible text from a region in a buffer, into
> a string.
>
> if any invisible regions are in the region, i want them to
> not be in the string.

Not a complicated task - and it seems that `backtrace--filter-visible'
is implementing exactly that:

#+begin_src emacs-lisp
(defun backtrace--filter-visible (beg end &optional _delete)
  "Return the visible text between BEG and END."
  (let ((result ""))
    (while (< beg end)
      (let ((next (next-single-char-property-change beg 'invisible)))
        (unless (get-char-property beg 'invisible)
          (setq result (concat result (buffer-substring beg (min end next)))))
        (setq beg next)))
    result))
#+end_src

If you don't want to rely on an internal function you might just copy
these few lines.

Michael.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]