emacs-devel
[Top][All Lists]
Advanced

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

Re: search-invisible and friends


From: Ihor Radchenko
Subject: Re: search-invisible and friends
Date: Fri, 11 Sep 2020 09:03:11 +0800

> Note that what I'm suggesting is somewhat orthogonal since it's about
> making it possible for a text (or overlay) property to say not to skip
> over a particular (hidden) chunk of text, regardless of whether (and
> how) we'd open the text to show it or not.

Isn't 'isearch-open-invisible property doing it already? If it is
non-nil, the hidden text is not skipped by isearch.

-----

Also, adding on the initial topic of skipping some technically not
invisible text. Similar functionality is required by org-mode branch I
am working on - some folded (temporarily hidden) may better not be
searchable. I implemented it by defining custom
`isearch-filter-predicate'.

The code I used is below. For context, org-fold--isearch-specs lists
'invisible property values that should be searchable.
org-fold-get-folding-specs-in-region retrieves all 'invisible property
values in region.

The code decides if isearch can search in region depending on the value
of 'invisible property, but it can generally be any property.

(defun org-fold--isearch-filter-predicate-text-properties (beg end)
  "Make sure that text hidden by any means other than `org-fold--isearch-specs' 
is not searchable.
This function is intended to be used as `isearch-filter-predicate'."
  (and
   ;; Check folding specs that cannot be searched
   (seq-every-p (lambda (spec) (member spec org-fold--isearch-specs)) 
(org-fold-get-folding-specs-in-region beg end))
   ;; Check 'invisible properties that are not folding specs
   (or (eq search-invisible t) ; User wants to search, allow it
       (let ((pos beg)
             unknown-invisible-property)
         (while (and (< pos end)
                     (not unknown-invisible-property))
           (when (and (get-text-property pos 'invisible)
                      (not (member (get-text-property pos 'invisible) 
org-fold--isearch-specs)))
             (setq unknown-invisible-property t))
           (setq pos (next-single-char-property-change pos 'invisible)))
         (not unknown-invisible-property)))
   (or (and (eq search-invisible t)
            ;; FIXME: this opens regions permanenly for now.
            ;; I also tried to force search-invisible 'open-all around
            ;; `isearch-range-invisible', but that somehow causes
            ;; infinite loop in `isearch-lazy-highlight'.
            (prog1 t
              ;; We still need to reveal the folded location
              (org-fold--isearch-show-temporary (cons beg end) nil)))
       (not (isearch-range-invisible beg end)))))

Best,
Ihor

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>>>> Do you mean to match text in the display replacement,
>>> No, I mean to ignore `search-invisible` on those specific chunks (but
>>> still only do the search on the buffer text).
>> FYI, I proposed similar patch earlier:
>> https://lists.gnu.org/archive/html/emacs-devel/2020-07/msg00679.html
>
> OMG, yes, it's still in my TODO.
>
> Note that what I'm suggesting is somewhat orthogonal since it's about
> making it possible for a text (or overlay) property to say not to skip
> over a particular (hidden) chunk of text, regardless of whether (and
> how) we'd open the text to show it or not.
>
>
>         Stefan



reply via email to

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