]> git.eshelyaron.com Git - emacs.git/commitdiff
Switch to literal mode with message when regexp is too big in char-fold search
authorJuri Linkov <juri@linkov.net>
Sat, 28 Mar 2020 23:41:29 +0000 (01:41 +0200)
committerJuri Linkov <juri@linkov.net>
Sat, 28 Mar 2020 23:41:29 +0000 (01:41 +0200)
* lisp/char-fold.el (char-fold-to-regexp): Don't use regexp-quote
when the length of regexp reaches 5000.  (Bug#40216)

* lisp/isearch.el (isearch-search): On big regexp in char-fold mode
gracefully fall back to literal mode, try to search again and display
momentary-message about switching to literal mode.
(isearch--momentary-message): Add optional arg SECONDS.

lisp/char-fold.el
lisp/isearch.el

index f8a303956e3f9b0662f18450da08d2ea72b27cbc..5a3c20c7832cc2528bb8d846106adb04bd44d61c 100644 (file)
@@ -370,11 +370,7 @@ from which to start."
       (setq i (1+ i)))
     (when (> spaces 0)
       (push (char-fold--make-space-string spaces) out))
-    (let ((regexp (apply #'concat (nreverse out))))
-      ;; Limited by `MAX_BUF_SIZE' in `regex-emacs.c'.
-      (if (> (length regexp) 5000)
-          (regexp-quote string)
-        regexp))))
+    (apply #'concat (nreverse out))))
 
 \f
 ;;; Commands provided for completeness.
index ddf9190dc6d1c1540b80d2d46f182edc7295c1cc..7625ec12b58eb0828b652d6289f53af421e2f167 100644 (file)
@@ -2011,15 +2011,16 @@ Turning on character-folding turns off regexp mode.")
 (defvar isearch-message-properties minibuffer-prompt-properties
   "Text properties that are added to the isearch prompt.")
 
-(defun isearch--momentary-message (string)
-  "Print STRING at the end of the isearch prompt for 1 second."
+(defun isearch--momentary-message (string &optional seconds)
+  "Print STRING at the end of the isearch prompt for 1 second.
+The optional argument SECONDS overrides the number of seconds."
   (let ((message-log-max nil))
     (message "%s%s%s"
              (isearch-message-prefix nil isearch-nonincremental)
              isearch-message
              (apply #'propertize (format " [%s]" string)
                     isearch-message-properties)))
-  (sit-for 1))
+  (sit-for (or seconds 1)))
 
 (isearch-define-mode-toggle lax-whitespace " " nil
   "In ordinary search, toggles the value of the variable
@@ -3443,7 +3444,10 @@ Optional third argument, if t, means if fail just return nil (no error).
            (string-match "\\`Regular expression too big" isearch-error))
        (cond
        (isearch-regexp-function
-        (setq isearch-error "Too many words"))
+         (setq isearch-error nil)
+         (setq isearch-regexp-function nil)
+         (isearch-search-and-update)
+         (isearch--momentary-message "Too many words; switched to literal mode" 2))
        ((and isearch-lax-whitespace search-whitespace-regexp)
         (setq isearch-error "Too many spaces for whitespace matching"))))))