]> git.eshelyaron.com Git - emacs.git/commitdiff
New function isearch-search-fun-in-text-property (bug#14013).
authorJuri Linkov <juri@linkov.net>
Fri, 10 Jun 2022 16:43:31 +0000 (19:43 +0300)
committerJuri Linkov <juri@linkov.net>
Fri, 10 Jun 2022 16:43:31 +0000 (19:43 +0300)
* lisp/dired-aux.el (dired-isearch-search-filenames): Move most of the body
to the new function isearch-search-fun-in-text-property.

* lisp/isearch.el (isearch-search-fun-in-text-property):
New function refactored from dired-isearch-search-filenames.

lisp/dired-aux.el
lisp/isearch.el

index 4faf9431aa37a91a9178378e10cc22f17bf79acc..d16aee0fa86866dee9267f67dfaae68e389a9553 100644 (file)
@@ -3208,41 +3208,7 @@ Intended to be added to `isearch-mode-hook'."
 The returned function narrows the search to match the search string
 only as part of a file name enclosed by the text property `dired-filename'.
 It's intended to override the default search function."
-  (let ((search-fun (funcall orig-fun))
-        (property 'dired-filename))
-    (lambda (string &optional bound noerror count)
-      (let* ((old (point))
-             ;; Check if point is already on the property.
-             (beg (when (get-text-property
-                         (if isearch-forward old (max (1- old) (point-min)))
-                         property)
-                    old))
-             end found)
-        ;; Otherwise, try to search for the next property.
-        (unless beg
-          (setq beg (if isearch-forward
-                        (next-single-property-change old property)
-                      (previous-single-property-change old property)))
-          (when beg (goto-char beg)))
-        ;; Non-nil `beg' means there are more properties.
-        (while (and beg (not found))
-          ;; Search for the end of the current property.
-          (setq end (if isearch-forward
-                        (next-single-property-change beg property)
-                      (previous-single-property-change beg property)))
-          (setq found (funcall
-                       search-fun string (if bound (if isearch-forward
-                                                       (min bound end)
-                                                     (max bound end))
-                                           end)
-                       noerror count))
-          (unless found
-            (setq beg (if isearch-forward
-                          (next-single-property-change end property)
-                        (previous-single-property-change end property)))
-            (when beg (goto-char beg))))
-        (unless found (goto-char old))
-        found))))
+  (isearch-search-fun-in-text-property 'dired-filename (funcall orig-fun)))
 
 ;;;###autoload
 (defun dired-isearch-filenames ()
index 31fbdf01bf25dc7addfa64c49e9958b07ff5299a..5fbfb724a3c274fffc617a83a46cfcfa284d64e7 100644 (file)
@@ -4454,6 +4454,48 @@ LAX-WHITESPACE: The value of `isearch-lax-whitespace' and
             (add-function :after-while (local 'isearch-filter-predicate) filter)))
         (funcall after-change nil nil nil)))))
 
+\f
+(defun isearch-search-fun-in-text-property (property &optional search-fun)
+  "Return the function that searches inside fields.
+The arg PROPERTY defines the name of the text property that
+delimits fields in the current buffer.  Then the search will be
+narrowed to match only on such text properties.  The optional arg
+SEARCH-FUN can provide the default search function which is
+by default is the same as returned by `isearch-search-fun-default'."
+  (lambda (string &optional bound noerror count)
+    (let* ((old (point))
+           ;; Check if point is already on the property.
+           (beg (when (get-text-property
+                       (if isearch-forward old (max (1- old) (point-min)))
+                       property)
+                  old))
+           end found)
+      ;; Otherwise, try to search for the next property.
+      (unless beg
+        (setq beg (if isearch-forward
+                      (next-single-property-change old property)
+                    (previous-single-property-change old property)))
+        (when beg (goto-char beg)))
+      ;; Non-nil `beg' means there are more properties.
+      (while (and beg (not found))
+        ;; Search for the end of the current property.
+        (setq end (if isearch-forward
+                      (next-single-property-change beg property)
+                    (previous-single-property-change beg property)))
+        (setq found (funcall (or search-fun (isearch-search-fun-default))
+                             string (if bound (if isearch-forward
+                                                  (min bound end)
+                                                (max bound end))
+                                      end)
+                             noerror count))
+        (unless found
+          (setq beg (if isearch-forward
+                        (next-single-property-change end property)
+                      (previous-single-property-change end property)))
+          (when beg (goto-char beg))))
+      (unless found (goto-char old))
+      found)))
+
 \f
 (defun isearch-resume (string regexp word forward message case-fold)
   "Resume an incremental search.