GNU bug report logs - #36398
Lax char-fold search

Previous Next

Package: emacs;

Reported by: Juri Linkov <juri <at> linkov.net>

Date: Wed, 26 Jun 2019 21:38:01 UTC

Severity: wishlist

Tags: patch

Fixed in version 27.0.50

Done: Juri Linkov <juri <at> linkov.net>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 36398 in the body.
You can then email your comments to 36398 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#36398; Package emacs. (Wed, 26 Jun 2019 21:38:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Juri Linkov <juri <at> linkov.net>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 26 Jun 2019 21:38:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: bug-gnu-emacs <at> gnu.org
Subject: Lax char-fold search
Date: Thu, 27 Jun 2019 00:12:08 +0300
[Message part 1 (text/plain, inline)]
Before finishing bug#35689, I'd like to implement the argument LAX of
char-fold-to-regexp, so e.g. during isearch when point is at the beginning
of the word with ligature “fix”, typing three letters ‘f’, ‘i’, ‘x’
will keep point matching on the same word:

[char-fold-to-regexp-lax.patch (text/x-diff, inline)]
diff --git a/lisp/char-fold.el b/lisp/char-fold.el
index 7223ecf738..9d3ea17b41 100644
--- a/lisp/char-fold.el
+++ b/lisp/char-fold.el
@@ -148,12 +148,18 @@ char-fold--make-space-string
                  (make-list n (or (aref char-fold-table ?\s) " ")))))
 
 ;;;###autoload
-(defun char-fold-to-regexp (string &optional _lax from)
+(defun char-fold-to-regexp (string &optional lax from)
   "Return a regexp matching anything that char-folds into STRING.
 Any character in STRING that has an entry in
 `char-fold-table' is replaced with that entry (which is a
 regexp) and other characters are `regexp-quote'd.
 
+When LAX is non-nil, then the final character also matches ligatures
+partially, for instance, the search string \"f\" will match \"fi\",
+so when typing the search string in isearch while the cursor is on
+a ligature, the search won't try to immediately advance to the next
+complete match, but will stay on the partially matched ligature.
+
 If the resulting regexp would be too long for Emacs to handle,
 just return the result of calling `regexp-quote' on STRING.
 
@@ -183,7 +189,11 @@ char-fold-to-regexp
                  ;; Long string.  The regexp would probably be too long.
                  (alist (unless (> end 50)
                           (aref multi-char-table c))))
-             (push (let ((matched-entries nil)
+             (push (if (and lax alist (= (1+ i) end))
+                       (concat "\\(?:" regexp "\\|"
+                               (mapconcat (lambda (entry)
+                                            (cdr entry)) alist "\\|") "\\)")
+                     (let ((matched-entries nil)
                            (max-length 0))
                        (dolist (entry alist)
                          (let* ((suffix (car entry))
@@ -212,7 +222,7 @@ char-fold-to-regexp
                                            (concat suffix-regexp
                                                    (char-fold-to-regexp subs nil length))))
                                        `((0 . ,regexp) . ,matched-entries) "\\|")
-                          "\\)"))))
+                            "\\)")))))
                    out))))
       (setq i (1+ i)))
     (when (> spaces 0)
diff --git a/test/lisp/char-fold-tests.el b/test/lisp/char-fold-tests.el
index 3fde312a13..e9dfd2b733 100644
--- a/test/lisp/char-fold-tests.el
+++ b/test/lisp/char-fold-tests.el
@@ -82,6 +82,14 @@ char-fold--test-search-with-contents
       (set-char-table-extra-slot char-fold-table 0 multi)
       (char-fold--test-match-exactly (car it) (cdr it)))))
 
+(ert-deftest char-fold--test-multi-lax ()
+ (dolist (it '(("f" . "fi") ("f" . "ff")))
+   (with-temp-buffer
+     (insert (cdr it))
+     (goto-char (point-min))
+     (should (search-forward-regexp
+              (char-fold-to-regexp (car it) 'lax) nil 'noerror)))))
+
 (ert-deftest char-fold--test-fold-to-regexp ()
   (let ((char-fold-table (make-char-table 'char-fold-table))
         (multi  (make-char-table 'char-fold-table)))

Severity set to 'wishlist' from 'normal' Request was from Juri Linkov <juri <at> linkov.net> to control <at> debbugs.gnu.org. (Thu, 04 Jul 2019 20:51:01 GMT) Full text and rfc822 format available.

Added tag(s) patch. Request was from Juri Linkov <juri <at> linkov.net> to control <at> debbugs.gnu.org. (Thu, 04 Jul 2019 20:51:01 GMT) Full text and rfc822 format available.

bug marked as fixed in version 27.0.50, send any further explanations to 36398 <at> debbugs.gnu.org and Juri Linkov <juri <at> linkov.net> Request was from Juri Linkov <juri <at> linkov.net> to control <at> debbugs.gnu.org. (Thu, 04 Jul 2019 20:51:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 02 Aug 2019 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 6 years and 54 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.