From: Juri Linkov <juri@linkov.net>
To: Noam Postavsky <npostavs@gmail.com>
Cc: 35689@debbugs.gnu.org
Subject: bug#35689: Customizable char-fold
Date: Mon, 13 May 2019 23:31:58 +0300 [thread overview]
Message-ID: <87o9466z1t.fsf@mail.linkov.net> (raw)
In-Reply-To: <87mujrh0uv.fsf@gmail.com> (Noam Postavsky's message of "Sun, 12 May 2019 16:30:32 -0400")
[-- Attachment #1: Type: text/plain, Size: 674 bytes --]
>>> This patch adds long-awaited customization to char-fold.el:
>>
>> I noticed that its compilation fails with:
>>
>> ELC char-fold.elc
>> In toplevel form:
>> char-fold.el:153:31:Error: Symbol's value as variable is void: char-fold-include-base
>> Makefile:296: recipe for target 'char-fold.elc' failed
>> make[2]: *** [char-fold.elc] Error 1
>>
>> So a new patch added 'eval-and-compile' to all defcustoms:
>
> Will it actually work for a user to customize this? It looks like the
> values are used during compile time, so after changing the value the
> user would have to recompile char-fold.el?
Oh, right. Do you see a problem with a better patch:
[-- Attachment #2: char-fold-defcustom.3.patch --]
[-- Type: text/x-diff, Size: 4139 bytes --]
diff --git a/lisp/char-fold.el b/lisp/char-fold.el
index e61bc3edc6..6c3f809c2b 100644
--- a/lisp/char-fold.el
+++ b/lisp/char-fold.el
@@ -24,8 +24,43 @@
(eval-and-compile (put 'char-fold-table 'char-table-extra-slots 1))
\f
-(defconst char-fold-table
- (eval-when-compile
+(eval-and-compile (defcustom char-fold-include-base nil
+ "Include mappings from composite character to base letter."
+ :type 'boolean
+ :set (lambda (sym val)
+ (set sym val)
+ (when (boundp 'char-fold-table)
+ (setq char-fold-table (char-fold-make-table))))
+ :group 'matching
+ :version "27.1"))
+
+(eval-and-compile (defcustom char-fold-include-alist
+ '((?\" """ "“" "”" "”" "„" "⹂" "〞" "‟" "‟" "❞" "❝" "❠" "“" "„" "〝" "〟" "🙷" "🙶" "🙸" "«" "»")
+ (?' "❟" "❛" "❜" "‘" "’" "‚" "‛" "‚" "" "❮" "❯" "‹" "›")
+ (?` "❛" "‘" "‛" "" "❮" "‹"))
+ "Additional character mappings to include."
+ :type '(alist :key-type (character :tag "From")
+ :value-type (repeat (string :tag "To")))
+ :set (lambda (sym val)
+ (set sym val)
+ (when (boundp 'char-fold-table)
+ (setq char-fold-table (char-fold-make-table))))
+ :group 'lisp
+ :version "27.1"))
+
+(eval-and-compile (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"))
+ :set (lambda (sym val)
+ (set sym val)
+ (when (boundp 'char-fold-table)
+ (setq char-fold-table (char-fold-make-table))))
+ :group 'lisp
+ :version "27.1"))
+
+(eval-and-compile
+ (defun char-fold-make-table ()
(let ((equiv (make-char-table 'char-fold-table))
(equiv-multi (make-char-table 'char-fold-table))
(table (unicode-property-table-internal 'decomposition)))
@@ -76,7 +123,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 +149,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)
@@ -113,7 +169,11 @@ char-fold-table
(set-char-table-range equiv char re)
(aset equiv char re))))
equiv)
- equiv))
+ equiv)))
+
+(defconst char-fold-table
+ (eval-when-compile
+ (char-fold-make-table))
"Used for folding characters of the same group during search.
This is a char-table with the `char-fold-table' subtype.
next prev parent reply other threads:[~2019-05-13 20:31 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87o9466z1t.fsf@mail.linkov.net \
--to=juri@linkov.net \
--cc=35689@debbugs.gnu.org \
--cc=npostavs@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.