unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#35689: Customizable char-fold
@ 2019-05-11 21:22 Juri Linkov
  2019-05-12 19:12 ` Juri Linkov
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Juri Linkov @ 2019-05-11 21:22 UTC (permalink / raw)
  To: 35689

[-- Attachment #1: Type: text/plain, Size: 74 bytes --]

Tags: patch

This patch adds long-awaited customization to char-fold.el:


[-- Attachment #2: char-fold-defcustom.patch --]
[-- Type: text/x-diff, Size: 3040 bytes --]

diff --git a/lisp/char-fold.el b/lisp/char-fold.el
index e61bc3edc6..24882008a4 100644
--- a/lisp/char-fold.el
+++ b/lisp/char-fold.el
@@ -24,6 +24,30 @@
 
 (eval-and-compile (put 'char-fold-table 'char-table-extra-slots 1))
 \f
+(defcustom char-fold-include-base nil
+  "Include mappings from composite character to base letter."
+  :type 'boolean
+  :group 'matching
+  :version "27.1")
+
+(defcustom char-fold-include-alist
+  '((?\" """ "“" "”" "”" "„" "⹂" "〞" "‟" "‟" "❞" "❝" "❠" "“" "„" "〝" "〟" "🙷" "🙶" "🙸" "«" "»")
+    (?' "❟" "❛" "❜" "‘" "’" "‚" "‛" "‚" "󠀢" "❮" "❯" "‹" "›")
+    (?` "❛" "‘" "‛" "󠀢" "❮" "‹"))
+  "Additional character mappings to include."
+  :type '(alist :key-type (character :tag "From")
+                :value-type (repeat (string :tag "To")))
+  :group 'lisp
+  :version "27.1")
+
+(defcustom char-fold-exclude-alist nil
+  "Character mappings to exclude from default setting."
+  :type '(alist :key-type (character :tag "From")
+                :value-type (character :tag "To"))
+  :group 'lisp
+  :version "27.1")
+
+\f
 (defconst char-fold-table
   (eval-when-compile
     (let ((equiv (make-char-table 'char-fold-table))
@@ -76,7 +106,11 @@ char-fold-table
                                       (aref equiv-multi (car decomp))))
                         (aset equiv (car decomp)
                               (cons (char-to-string char)
-                                    (aref equiv (car decomp))))))))
+                                    (aref equiv (car decomp))))
+                        (when char-fold-include-base
+                          (aset equiv char
+                                (cons (char-to-string (car decomp))
+                                      (aref equiv (car decomp)))))))))
                (funcall make-decomp-match-char decomp char)
                ;; Do it again, without the non-spacing characters.
                ;; This allows 'a' to match 'ä'.
@@ -98,13 +132,18 @@ char-fold-table
        table)
 
       ;; Add some manual entries.
-      (dolist (it '((?\" """ "“" "”" "”" "„" "⹂" "〞" "‟" "‟" "❞" "❝" "❠" "“" "„" "〝" "〟" "🙷" "🙶" "🙸" "«" "»")
-                    (?' "❟" "❛" "❜" "‘" "’" "‚" "‛" "‚" "󠀢" "❮" "❯" "‹" "›")
-                    (?` "❛" "‘" "‛" "󠀢" "❮" "‹")))
+      (dolist (it char-fold-include-alist)
         (let ((idx (car it))
               (chars (cdr it)))
           (aset equiv idx (append chars (aref equiv idx)))))
 
+      ;; Remove some entries.
+      (dolist (it char-fold-exclude-alist)
+        (let ((idx (car it))
+              (char (cdr it)))
+          (when (aref equiv idx)
+            (aset equiv idx (remove (char-to-string char) (aref equiv idx))))))
+
       ;; Convert the lists of characters we compiled into regexps.
       (map-char-table
        (lambda (char dec-list)

^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2019-07-28 22:46 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-05-11 21:22 bug#35689: Customizable char-fold Juri Linkov
2019-05-12 19:12 ` Juri Linkov
2019-05-12 20:30   ` Noam Postavsky
2019-05-13 20:31     ` Juri Linkov
2019-05-13 22:18       ` Noam Postavsky
2019-05-14  6:37         ` Eli Zaretskii
2019-05-14 20:14           ` Juri Linkov
2019-05-16 14:47             ` npostavs
2019-05-16 20:13               ` Juri Linkov
2019-05-21 20:34                 ` Juri Linkov
2019-05-21 21:45                   ` npostavs
2019-06-06 20:49                     ` Juri Linkov
2019-06-24 17:33                   ` Lars Ingebrigtsen
2019-06-24 20:40                     ` Juri Linkov
2019-07-23 20:28 ` Juri Linkov
2019-07-28 22:46 ` Juri Linkov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).