From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Enable customisation for electric-quote-mode chars Date: Sun, 23 Oct 2016 03:25:00 -0700 Organization: UCLA Computer Science Department Message-ID: References: <87pomsv5z4.fsf@xi.bootis> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------BD53315E521C3AD85D72D718" X-Trace: blaine.gmane.org 1477218332 15121 195.159.176.226 (23 Oct 2016 10:25:32 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 23 Oct 2016 10:25:32 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 Cc: emacs-devel@gnu.org To: =?UTF-8?Q?G=c3=b6ktu=c4=9f_Kayaalp?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Oct 23 12:25:28 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1byFxu-000203-H9 for ged-emacs-devel@m.gmane.org; Sun, 23 Oct 2016 12:25:18 +0200 Original-Received: from localhost ([::1]:40448 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1byFxw-0002VF-St for ged-emacs-devel@m.gmane.org; Sun, 23 Oct 2016 06:25:20 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54900) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1byFxj-0002Rp-Hl for emacs-devel@gnu.org; Sun, 23 Oct 2016 06:25:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1byFxg-0002Xr-Bj for emacs-devel@gnu.org; Sun, 23 Oct 2016 06:25:07 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:40124) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1byFxg-0002Xh-2G for emacs-devel@gnu.org; Sun, 23 Oct 2016 06:25:04 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 703131606D6; Sun, 23 Oct 2016 03:25:02 -0700 (PDT) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id eI91hVCh6XU0; Sun, 23 Oct 2016 03:25:00 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id B85E9161334; Sun, 23 Oct 2016 03:25:00 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id T2X9znmrvS07; Sun, 23 Oct 2016 03:25:00 -0700 (PDT) Original-Received: from [192.168.1.9] (unknown [47.153.178.162]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 90594160FA2; Sun, 23 Oct 2016 03:25:00 -0700 (PDT) In-Reply-To: <87pomsv5z4.fsf@xi.bootis> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 131.179.128.68 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:208614 Archived-At: This is a multi-part message in MIME format. --------------BD53315E521C3AD85D72D718 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable G=C3=B6ktu=C4=9F Kayaalp wrote: > I'm messaging just to ping about the status of this patch. Will be > applied or not? Need improvements? The intent is to apply it, yes. I had been waiting for Bug#24759 to settl= e down=20 first; see http://bugs.gnu.org/24759 That bug was closed recently. To help move things along I merged emacs-25= to=20 master and rebased the patch, arriving at the attached patches. Do these = look=20 good to you? --------------BD53315E521C3AD85D72D718 Content-Type: text/x-diff; name="0001-New-user-variable-electric-quote-chars.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="0001-New-user-variable-electric-quote-chars.patch" =46rom 96c18709151a422c7dbad6bcfdebe06dc50c4f3b Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?G=3DC3=3DB6ktu=3DC4=3D9F=3D20Kayaalp?=3D Date: Sun, 23 Oct 2016 03:14:52 -0700 Subject: [PATCH 1/2] New user variable 'electric-quote-chars' * doc/emacs/text.texi (Quotation Marks), etc/NEWS: Document this. * lisp/electric.el (electric-quote-chars): New defcustom. (electric-quote-post-self-insert-function): Use it. (electric--insertable-p): Arg can now be a char, too. --- doc/emacs/text.texi | 14 ++++++++++++-- etc/NEWS | 4 ++++ lisp/electric.el | 53 +++++++++++++++++++++++++++++++++--------------= ------ 3 files changed, 49 insertions(+), 22 deletions(-) diff --git a/doc/emacs/text.texi b/doc/emacs/text.texi index 7fa0804..4c6a1ff 100644 --- a/doc/emacs/text.texi +++ b/doc/emacs/text.texi @@ -412,6 +412,7 @@ Quotation Marks @cindex mode, Electric Quote @cindex curly quotes @cindex curved quotes +@cindex guillemets @findex electric-quote-mode One common way to quote is the typewriter convention, which quotes using straight apostrophes @t{'like this'} or double-quotes @t{"like @@ -420,9 +421,15 @@ Quotation Marks @t{=E2=80=9Clike this=E2=80=9D}. In text files, typewriter quotes are s= imple and portable; curved quotes are less ambiguous and typically look nicer. =20 +@vindex electric-quote-chars Electric Quote mode makes it easier to type curved quotes. As you type characters it optionally converts @t{`} to @t{=E2=80=98}, @t{'} to = @t{=E2=80=99}, -@t{``} to @t{=E2=80=9C}, and @t{''} to @t{=E2=80=9D}. +@t{``} to @t{=E2=80=9C}, and @t{''} to @t{=E2=80=9D}. It's possible to = change the +default quotes listed above, by customizing the variable +@code{electric-quote-chars}, a list of four characters, where the +items correspond to the left single quote, the right single quote, the +left double quote and the right double quote, respectively, whose +default value is @code{'(?=E2=80=98 ?=E2=80=99 ?=E2=80=9C ?=E2=80=9D)}. =20 @vindex electric-quote-paragraph @vindex electric-quote-comment @@ -443,7 +450,10 @@ Quotation Marks insert a curved quote even when Electric Quote is disabled or inactive, you can type @kbd{C-x 8 [} for @t{=E2=80=98}, @kbd{C-x 8 ]} fo= r @t{=E2=80=99}, @kbd{C-x 8 @{} for @t{=E2=80=9C}, and @kbd{C-x 8 @}} for = @t{=E2=80=9D}. -@xref{Inserting Text}. +@xref{Inserting Text}. Note that the value of +@code{electric-quote-chars} does not affect these keybindings, they +are not keybindings of @code{electric-quote-mode} but bound in +@code{global-map}. =20 @node Filling @section Filling Text diff --git a/etc/NEWS b/etc/NEWS index d9973c0..1271466 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -60,6 +60,10 @@ affected by this, as SGI stopped supporting IRIX in De= cember 2013. =20 =0C * Changes in Emacs 26.1 ++++ +** The new user variable 'electric-quote-chars' provides a list +of curved quotes for 'electric-quote-mode', allowing user to choose +the types of quotes to be used. =20 --- The group 'wp', whose label was "text", is now deprecated. diff --git a/lisp/electric.el b/lisp/electric.el index f35f8b9..19cded2 100644 --- a/lisp/electric.el +++ b/lisp/electric.el @@ -425,6 +425,13 @@ electric-quote-string :version "25.1" :type 'boolean :safe 'booleanp :group 'electricity) =20 +(defcustom electric-quote-chars '(?=E2=80=98 ?=E2=80=99 ?=E2=80=9C ?=E2=80= =9D) + "Curved quote characters for `electric-quote-mode'. +The items correspond to the left single quote, the right single +quote, the left double quote, and the right double quote, respectively."= + :version "25.1" + :type 'list :safe 'listp :group 'electricity) + (defcustom electric-quote-paragraph t "Non-nil means to use electric quoting in text paragraphs." :version "25.1" @@ -451,26 +458,29 @@ electric-quote-post-self-insert-function (derived-mode-p 'text-mode) (or (eq last-command-event ?\`) (save-excursion (backward-paragraph) (point)))))))= - (when start - (save-excursion - (if (eq last-command-event ?\`) - (cond ((search-backward "=E2=80=98`" (- (point) 2) t) - (replace-match "=E2=80=9C") - (when (and electric-pair-mode - (eq (cdr-safe - (assq ?=E2=80=98 electric-pair-text= -pairs)) - (char-after))) - (delete-char 1)) - (setq last-command-event ?=E2=80=9C)) - ((search-backward "`" (1- (point)) t) - (replace-match "=E2=80=98") - (setq last-command-event ?=E2=80=98))) - (cond ((search-backward "=E2=80=99'" (- (point) 2) t) - (replace-match "=E2=80=9D") - (setq last-command-event ?=E2=80=9D)) - ((search-backward "'" (1- (point)) t) - (replace-match "=E2=80=99") - (setq last-command-event ?=E2=80=99))))))))) + (pcase electric-quote-chars + (`(,q1 ,q2 ,q3 ,q4) + (when start + (save-excursion + (if (eq last-command-event ?\`) + (cond ((search-backward (string q1 ?`) (- (point) 2) t)= + (replace-match (string q3)) + (when (and electric-pair-mode + (eq (cdr-safe + (assq q1 electric-pair-text-pair= s)) + (char-after))) + (delete-char 1)) + (setq last-command-event q3)) + ((search-backward "`" (1- (point)) t) + (replace-match (string q1)) + (setq last-command-event q1))) + (cond ((search-backward (string q2 ?') (- (point) 2) t) + (replace-match (string q4)) + (setq last-command-event q4)) + ((search-backward "'" (1- (point)) t) + (replace-match (string q2)) + (setq last-command-event q2))))))) + (_ (error "=E2=80=98electric-quote-chars=E2=80=99 must contain e= xactly 4 characters.")))))) =20 (put 'electric-quote-post-self-insert-function 'priority 10) =20 @@ -487,6 +497,9 @@ electric-quote-mode `electric-quote-comment', `electric-quote-string', and `electric-quote-paragraph'. =20 +Customize `electric-quote-chars' in order to use quote chars +other than the ones listed here. + This is a global minor mode. To toggle the mode in a single buffer, use `electric-quote-local-mode'." :global t :group 'electricity --=20 2.7.4 --------------BD53315E521C3AD85D72D718 Content-Type: text/x-diff; name="0002-electric-quote-chars-fixups.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="0002-electric-quote-chars-fixups.patch" =46rom 7ba2590f3753157ca078250c09598dce48aaa3cd Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 23 Oct 2016 03:22:06 -0700 Subject: [PATCH 2/2] electric-quote-chars fixups * lisp/electric.el (electric-quote-chars): Check types and safety more carefully. (electric-quote-post-self-insert-function): Use more-mnemonic locals. Omit no-longer-necessary runtime error diagnostic. --- lisp/electric.el | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/lisp/electric.el b/lisp/electric.el index 19cded2..3e48737 100644 --- a/lisp/electric.el +++ b/lisp/electric.el @@ -427,10 +427,16 @@ electric-quote-string =20 (defcustom electric-quote-chars '(?=E2=80=98 ?=E2=80=99 ?=E2=80=9C ?=E2=80= =9D) "Curved quote characters for `electric-quote-mode'. -The items correspond to the left single quote, the right single -quote, the left double quote, and the right double quote, respectively."= - :version "25.1" - :type 'list :safe 'listp :group 'electricity) +This list's members correspond to left single quote, right single +quote, left double quote, and right double quote, respectively." + :version "26.1" + :type '(list character character character character) + :safe #'(lambda (x) + (pcase x + (`(,(pred characterp) ,(pred characterp) + ,(pred characterp) ,(pred characterp)) + t))) + :group 'electricity) =20 (defcustom electric-quote-paragraph t "Non-nil means to use electric quoting in text paragraphs." @@ -459,28 +465,27 @@ electric-quote-post-self-insert-function (or (eq last-command-event ?\`) (save-excursion (backward-paragraph) (point)))))))= (pcase electric-quote-chars - (`(,q1 ,q2 ,q3 ,q4) + (`(,q< ,q> ,q<< ,q>>) (when start (save-excursion (if (eq last-command-event ?\`) - (cond ((search-backward (string q1 ?`) (- (point) 2) t)= - (replace-match (string q3)) + (cond ((search-backward (string q< ?`) (- (point) 2) t)= + (replace-match (string q<<)) (when (and electric-pair-mode (eq (cdr-safe - (assq q1 electric-pair-text-pair= s)) + (assq q< electric-pair-text-pair= s)) (char-after))) (delete-char 1)) - (setq last-command-event q3)) + (setq last-command-event q<<)) ((search-backward "`" (1- (point)) t) - (replace-match (string q1)) - (setq last-command-event q1))) - (cond ((search-backward (string q2 ?') (- (point) 2) t) - (replace-match (string q4)) - (setq last-command-event q4)) + (replace-match (string q<)) + (setq last-command-event q<))) + (cond ((search-backward (string q> ?') (- (point) 2) t) + (replace-match (string q>>)) + (setq last-command-event q>>)) ((search-backward "'" (1- (point)) t) - (replace-match (string q2)) - (setq last-command-event q2))))))) - (_ (error "=E2=80=98electric-quote-chars=E2=80=99 must contain e= xactly 4 characters.")))))) + (replace-match (string q>)) + (setq last-command-event q>))))))))))) =20 (put 'electric-quote-post-self-insert-function 'priority 10) =20 @@ -497,8 +502,8 @@ electric-quote-mode `electric-quote-comment', `electric-quote-string', and `electric-quote-paragraph'. =20 -Customize `electric-quote-chars' in order to use quote chars -other than the ones listed here. +Customize `electric-quote-chars' to use characters other than the +ones listed here. =20 This is a global minor mode. To toggle the mode in a single buffer, use `electric-quote-local-mode'." --=20 2.7.4 --------------BD53315E521C3AD85D72D718--