emacs-devel
[Top][All Lists]
Advanced

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

Re: emacs-28 a866674b2a: Fix inaccuracies in "lax search" documentation


From: Juri Linkov
Subject: Re: emacs-28 a866674b2a: Fix inaccuracies in "lax search" documentation
Date: Mon, 25 Jul 2022 22:49:11 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu)

>>> > Should we make `char-fold-to-regexp' into a command and refer to it
>>> > from here? Or add something like `char-fold-show-equivalences'?
>>>
>>> A better name would be `describe-char-fold'.
>>
>> For a command, I'd say describe-character-foldings.  But
>> char-fold-show-equivalences is IMO a better name.
>
> All similar commands have names starting with the `describe-' prefix like
> `describe-char', `describe-character-set'.  So maybe then
> `describe-char-fold-equivalences'.

Ok, then let's use describe-char-fold-equivalences:

diff --git a/lisp/char-fold.el b/lisp/char-fold.el
index 05ae52cae0..71a1fb1910 100644
--- a/lisp/char-fold.el
+++ b/lisp/char-fold.el
@@ -48,6 +48,7 @@
 
 
 (eval-and-compile
+  (defvar char-fold--no-regexp nil)
   (defun char-fold--make-table ()
     (let* ((equiv (make-char-table 'char-fold-table))
            (equiv-multi (make-char-table 'char-fold-table))
@@ -201,11 +202,14 @@
            symmetric)))
 
       ;; Convert the lists of characters we compiled into regexps.
-      (map-char-table
-       (lambda (char decomp-list)
-         (let ((re (regexp-opt (cons (char-to-string char) decomp-list))))
-           (aset equiv char re)))
-       equiv)
+      (unless char-fold--no-regexp
+        ;; Non-nil `char-fold--no-regexp' unoptimized for regexp
+        ;; is used by `describe-char-fold-equivalences'.
+        (map-char-table
+         (lambda (char decomp-list)
+           (let ((re (regexp-opt (cons (char-to-string char) decomp-list))))
+             (aset equiv char re)))
+         equiv))
       equiv)))
 
 (defconst char-fold-table
@@ -421,6 +425,28 @@ char-fold-search-backward
   (interactive "sSearch: ")
   (re-search-backward (char-fold-to-regexp string) bound noerror count))
 
+
+(defun describe-char-fold-equivalences ()
+  "Describe character equivalences of `char-fold-to-regexp'."
+  (interactive)
+  (require 'help-fns)
+  (let ((help-buffer-under-preparation t))
+    (help-setup-xref (list #'describe-char-fold-equivalences)
+                     (called-interactively-p 'interactive))
+    (let ((equivalences nil))
+      (map-char-table
+       (lambda (char list)
+         (setq equivalences (cons (cons char list) equivalences)))
+       (let ((char-fold--no-regexp t))
+         (char-fold--make-table)))
+      (with-help-window (help-buffer)
+        (with-current-buffer standard-output
+          (insert "A list char-fold equivalences for 
`char-fold-to-regexp'.\n\n")
+          (dolist (equiv (nreverse equivalences))
+            (insert (format "%c: %s\n" (car equiv)
+                            (mapconcat #'identity (cdr equiv)
+                                       " ")))))))))
+
 (provide 'char-fold)
 
 ;;; char-fold.el ends here

reply via email to

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