Subject: bug#35802: Broken data loaded from uni-decomposition

From: Juri Linkov <[email-masked]>
Date: Sun, 16 Jun 2019 22:22:15 +0300

>>> Actually maybe it's just a matter of making isearch bind
>>> search-spaces-regexp less widely.  I'm not quite following when the your
>>> problem happens though.  Can you show a backtrace from your original
>>> problem using
>>>
>>>     (add-hook 'after-load-functions
>>>               (lambda (f) (when (string-match-p "uni-decomposition" f)
>>>                        (debug nil :search-spaces-regexp search-spaces-regexp))))
>>
>> When I eval both the above and (setq search-whitespace-regexp "\\(\\s-\\|\n\\)+")
>> then debugger still shows that search-spaces-regexp is nil
>> (also note where search-spaces-regexp is let-bound to non-nil in the backtrace,
>> see also more info after the backtrace):
>
> Hmm, can you show exactly what's needed to trigger this?  I tried the
> above after applying your patch in Bug#35802, but uni-decomposition was
> never loaded.

Here is a complete reproducible test case:

-1. Apply the following patch to master and recompile
 0. emacs -Q
 1. Eval:

   (progn
     (setq search-whitespace-regexp "\\(\\s-\\|\n\\)+")
     (add-hook 'after-load-functions
               (lambda (f) (when (string-match-p "uni-decomposition" f)
                             (debug nil :search-spaces-regexp search-spaces-regexp)))))

 2. Type C-s M-s ' a

diff --git a/lisp/char-fold.el b/lisp/char-fold.el
index d2fa7108bb..7b0e55bb11 100644
--- a/lisp/char-fold.el
+++ b/lisp/char-fold.el
@@ -28,7 +28,6 @@
   (defun char-fold-make-table ()
     (let* ((equiv (make-char-table 'char-fold-table))
            (equiv-multi (make-char-table 'char-fold-table))
-           (search-spaces-regexp nil)   ; workaround for bug#35802
            (table (unicode-property-table-internal 'decomposition)))
       (set-char-table-extra-slot equiv 0 equiv-multi)
 
@@ -141,6 +140,11 @@ char-fold-table
 
 Exceptionally for the space character (32), ALIST is ignored.")
 
+(progn
+  (message "search-spaces-regexp: %S" search-spaces-regexp)
+  ;; Emulate funcall from defcustom :set
+  (setq char-fold-table (char-fold-make-table)))
+
 (defun char-fold--make-space-string (n)
   "Return a string that matches N spaces."
   (format "\\(?:%s\\|%s\\)"