From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#35689: Customizable char-fold Date: Tue, 21 May 2019 23:34:20 +0300 Organization: LINKOV.NET Message-ID: <87y32zwmtf.fsf@mail.linkov.net> References: <87imug8z4i.fsf@mail.linkov.net> <8736lj3dgm.fsf@mail.linkov.net> <87mujrh0uv.fsf@gmail.com> <87o9466z1t.fsf@mail.linkov.net> <87d0kmgfrp.fsf@gmail.com> <406F1DF2-CB22-441F-B3E2-19770425322A@gnu.org> <87d0kkyesr.fsf@mail.linkov.net> <85v9ya1mng.fsf@gmail.com> <87zhnmgntu.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="266264"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (x86_64-pc-linux-gnu) Cc: 35689@debbugs.gnu.org To: npostavs@gmail.com Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue May 21 22:56:14 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hTBnx-00179L-7o for geb-bug-gnu-emacs@m.gmane.org; Tue, 21 May 2019 22:56:13 +0200 Original-Received: from localhost ([127.0.0.1]:59438 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTBnw-0003K1-9v for geb-bug-gnu-emacs@m.gmane.org; Tue, 21 May 2019 16:56:12 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:37566) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTBno-0003Hi-Mi for bug-gnu-emacs@gnu.org; Tue, 21 May 2019 16:56:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTBnm-0000ih-5A for bug-gnu-emacs@gnu.org; Tue, 21 May 2019 16:56:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:55809) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTBnl-0000ib-RQ for bug-gnu-emacs@gnu.org; Tue, 21 May 2019 16:56:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hTBnl-0004e3-Pb for bug-gnu-emacs@gnu.org; Tue, 21 May 2019 16:56:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 21 May 2019 20:56:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 35689 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 35689-submit@debbugs.gnu.org id=B35689.155847214317827 (code B ref 35689); Tue, 21 May 2019 20:56:01 +0000 Original-Received: (at 35689) by debbugs.gnu.org; 21 May 2019 20:55:43 +0000 Original-Received: from localhost ([127.0.0.1]:41120 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hTBnT-0004dS-0U for submit@debbugs.gnu.org; Tue, 21 May 2019 16:55:43 -0400 Original-Received: from insect.birch.relay.mailchannels.net ([23.83.209.93]:26538) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hTBnO-0004dF-GR for 35689@debbugs.gnu.org; Tue, 21 May 2019 16:55:42 -0400 X-Sender-Id: dreamhost|x-authsender|jurta@jurta.org Original-Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 51BEA5E2A0C; Tue, 21 May 2019 20:55:37 +0000 (UTC) Original-Received: from pdx1-sub0-mail-a9.g.dreamhost.com (100-96-86-18.trex.outbound.svc.cluster.local [100.96.86.18]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id C049D5E3306; Tue, 21 May 2019 20:55:36 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|jurta@jurta.org Original-Received: from pdx1-sub0-mail-a9.g.dreamhost.com ([TEMPUNAVAIL]. [64.90.62.162]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384) by 0.0.0.0:2500 (trex/5.17.2); Tue, 21 May 2019 20:55:37 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|jurta@jurta.org X-MailChannels-Auth-Id: dreamhost X-Fumbling-Wipe: 05df0efd71dc9d30_1558472137170_1769330798 X-MC-Loop-Signature: 1558472137170:3065849930 X-MC-Ingress-Time: 1558472137170 Original-Received: from pdx1-sub0-mail-a9.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a9.g.dreamhost.com (Postfix) with ESMTP id 386908046D; Tue, 21 May 2019 13:55:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=linkov.net; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=linkov.net; bh=Kkw8RflGtZi/r/UKU5OgCOZQbpc=; b= 1ASTiLJ1womgziwbcOyJ2KJsS6aY4SJ86I5ANe0jGvnZPTMjxNjH94Na+XieGxGu USb6v15LNGgjJeULQEldTWCxAJUfnIjWcy9rAO9WhT4QbcKwjQUxOliNugkSU2KV CEbvzlo/lvBAMPpAl2OpNPduVLHagZTkNOQL89/QwS8= Original-Received: from mail.jurta.org (m91-129-96-230.cust.tele2.ee [91.129.96.230]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: jurta@jurta.org) by pdx1-sub0-mail-a9.g.dreamhost.com (Postfix) with ESMTPSA id 2071D8045B; Tue, 21 May 2019 13:55:33 -0700 (PDT) X-DH-BACKEND: pdx1-sub0-mail-a9 In-Reply-To: <87zhnmgntu.fsf@mail.linkov.net> (Juri Linkov's message of "Thu, 16 May 2019 23:13:17 +0300") X-VR-OUT-STATUS: OK X-VR-OUT-SCORE: 0 X-VR-OUT-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeduuddruddutddgudehjecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucggtfgfnhhsuhgsshgtrhhisggvpdfftffgtefojffquffvnecuuegrihhlohhuthemuceftddtnecunecujfgurhephffvufhofhffjgfkfgggtgesmhdtreertdertdenucfhrhhomheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqeenucfkphepledurdduvdelrdeliedrvdeftdenucfrrghrrghmpehmohguvgepshhmthhppdhhvghlohepmhgrihhlrdhjuhhrthgrrdhorhhgpdhinhgvthepledurdduvdelrdeliedrvdeftddprhgvthhurhhnqdhprghthheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqedpmhgrihhlfhhrohhmpehjuhhriheslhhinhhkohhvrdhnvghtpdhnrhgtphhtthhopehnphhoshhtrghvshesghhmrghilhdrtghomhenucevlhhushhtvghrufhiiigvpedt X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:159620 Archived-At: --=-=-= Content-Type: text/plain >>> I can't find a standard way of doing this. So instead of using eval-and-compile >>> I'll try to recalculate the value explicitly when variables are customized: >>> >>> (when (or (get 'char-fold-include-base 'customized-value) >>> (get 'char-fold-include-alist 'customized-value) >>> (get 'char-fold-exclude-alist 'customized-value)) >>> (setq char-fold-table (char-fold-make-table))) >> >> Instead of looking at symbol property values, which can make for a >> confusing time when setting variables outside of customize, I think it >> would be nicer to do something like this: >> >> (defcustom char-fold-include-base char-fold--include-base-default >> :initialize #'custom-initialize-changed >> :set (lambda (sym val) >> (set-default sym val) >> ;; FIXME: Maybe delay this until after-init-time, >> ;; to avoid redundant calls to char-fold-make-table. > > I tried different possible values of :initialize, > but not custom-initialize-changed. I'll try this now. I see no problems other than redundant calls to char-fold-make-table when more than one variable is customized. char-fold.el is autoloaded when isearch calls char-fold-to-regexp for the first time, so I'm not sure how after-init-hook could help in this case. --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: inline; filename=char-fold-defcustom.4.patch Content-Transfer-Encoding: quoted-printable diff --git a/lisp/char-fold.el b/lisp/char-fold.el index 426b1a9f84..16d6d484f0 100644 --- a/lisp/char-fold.el +++ b/lisp/char-fold.el @@ -21,13 +21,22 @@ =20 ;;; Code: =20 -(eval-and-compile (put 'char-fold-table 'char-table-extra-slots 1)) +(eval-and-compile + (put 'char-fold-table 'char-table-extra-slots 1) + (defconst char-fold--symmetric-default nil) + (defconst char-fold--include-alist-default + '((?\" "=EF=BC=82" "=E2=80=9C" "=E2=80=9D" "=E2=80=9D" "=E2=80=9E" "= =E2=B9=82" "=E3=80=9E" "=E2=80=9F" "=E2=80=9F" "=E2=9D=9E" "=E2=9D=9D" "=E2= =9D=A0" "=E2=80=9C" "=E2=80=9E" "=E3=80=9D" "=E3=80=9F" "=F0=9F=99=B7" "=F0= =9F=99=B6" "=F0=9F=99=B8" "=C2=AB" "=C2=BB") + (?' "=E2=9D=9F" "=E2=9D=9B" "=E2=9D=9C" "=E2=80=98" "=E2=80=99" "=E2= =80=9A" "=E2=80=9B" "=E2=80=9A" "=F3=A0=80=A2" "=E2=9D=AE" "=E2=9D=AF" "=E2= =80=B9" "=E2=80=BA") + (?` "=E2=9D=9B" "=E2=80=98" "=E2=80=9B" "=F3=A0=80=A2" "=E2=9D=AE"= "=E2=80=B9"))) + (defconst char-fold--exclude-alist-default nil)) + =0C -(defconst char-fold-table - (eval-when-compile - (let ((equiv (make-char-table 'char-fold-table)) - (equiv-multi (make-char-table 'char-fold-table)) - (table (unicode-property-table-internal 'decomposition))) +(eval-and-compile + (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) ; bug#35802 + (table (unicode-property-table-internal 'decomposition))) (set-char-table-extra-slot equiv 0 equiv-multi) =20 ;; Ensure the table is populated. @@ -75,7 +84,12 @@ 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 (or (bound-and-true-p char-fold-symmetric) + char-fold--symmetric-default) + (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 '=C3=A4'. @@ -97,13 +111,20 @@ char-fold-table table) =20 ;; Add some manual entries. - (dolist (it '((?\" "=EF=BC=82" "=E2=80=9C" "=E2=80=9D" "=E2=80=9D"= "=E2=80=9E" "=E2=B9=82" "=E3=80=9E" "=E2=80=9F" "=E2=80=9F" "=E2=9D=9E" = "=E2=9D=9D" "=E2=9D=A0" "=E2=80=9C" "=E2=80=9E" "=E3=80=9D" "=E3=80=9F" "= =F0=9F=99=B7" "=F0=9F=99=B6" "=F0=9F=99=B8" "=C2=AB" "=C2=BB") - (?' "=E2=9D=9F" "=E2=9D=9B" "=E2=9D=9C" "=E2=80=98" = "=E2=80=99" "=E2=80=9A" "=E2=80=9B" "=E2=80=9A" "=F3=A0=80=A2" "=E2=9D=AE= " "=E2=9D=AF" "=E2=80=B9" "=E2=80=BA") - (?` "=E2=9D=9B" "=E2=80=98" "=E2=80=9B" "=F3=A0=80=A2= " "=E2=9D=AE" "=E2=80=B9"))) + (dolist (it (or (bound-and-true-p char-fold-include-alist) + char-fold--include-alist-default)) (let ((idx (car it)) (chars (cdr it))) (aset equiv idx (append chars (aref equiv idx))))) =20 + ;; Remove some entries. + (dolist (it (or (bound-and-true-p char-fold-exclude-alist) + char-fold--exclude-alist-default)) + (let ((idx (car it)) + (char (cdr it))) + (when (aref equiv idx) + (aset equiv idx (remove (char-to-string char) (aref equiv id= x)))))) + ;; Convert the lists of characters we compiled into regexps. (map-char-table (lambda (char dec-list) @@ -112,7 +133,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. =20 @@ -135,6 +160,40 @@ char-fold-table =20 Exceptionally for the space character (32), ALIST is ignored.") =20 +(defcustom char-fold-symmetric char-fold--symmetric-default + "Include symmetric mappings from composite character back to base lett= er." + :type 'boolean + :initialize #'custom-initialize-changed + :set (lambda (sym val) + (set-default sym val) + ;; FIXME: Maybe delay this until after-init-hook, + ;; to avoid redundant calls to char-fold-make-table. + (setq char-fold-table (char-fold-make-table))) + :group 'matching + :version "27.1") + +(defcustom char-fold-include-alist char-fold--include-alist-default + "Additional character mappings to include." + :type '(alist :key-type (character :tag "From") + :value-type (repeat (string :tag "To"))) + :initialize #'custom-initialize-changed + :set (lambda (sym val) + (set-default sym val) + (setq char-fold-table (char-fold-make-table))) + :group 'lisp + :version "27.1") + +(defcustom char-fold-exclude-alist char-fold--exclude-alist-default + "Character mappings to exclude from default setting." + :type '(alist :key-type (character :tag "From") + :value-type (character :tag "To")) + :initialize #'custom-initialize-changed + :set (lambda (sym val) + (set-default sym val) + (setq char-fold-table (char-fold-make-table))) + :group 'lisp + :version "27.1") + (defun char-fold--make-space-string (n) "Return a string that matches N spaces." (format "\\(?:%s\\|%s\\)" --=-=-=--