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, 9 Oct 2016 20:57:56 -0700 Organization: UCLA Computer Science Department Message-ID: <7103c4cf-1f1d-23f4-d421-1090c30fcde3@cs.ucla.edu> References: <871szsc8lf.fsf@xi.bootis> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------7A12A8E2DC25AB7A392B63D1" X-Trace: blaine.gmane.org 1476071966 23823 195.159.176.226 (10 Oct 2016 03:59:26 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 10 Oct 2016 03:59:26 +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 Mon Oct 10 05:59:22 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 1btRkE-0005Gp-Vu for ged-emacs-devel@m.gmane.org; Mon, 10 Oct 2016 05:59:19 +0200 Original-Received: from localhost ([::1]:47245 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btRkD-0003iA-8h for ged-emacs-devel@m.gmane.org; Sun, 09 Oct 2016 23:59:17 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49625) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btRj3-0003dN-I4 for emacs-devel@gnu.org; Sun, 09 Oct 2016 23:58:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1btRiy-0007Ma-EM for emacs-devel@gnu.org; Sun, 09 Oct 2016 23:58:04 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:60582) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1btRiy-0007M4-3A for emacs-devel@gnu.org; Sun, 09 Oct 2016 23:58:00 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id E1B12161294; Sun, 9 Oct 2016 20:57:58 -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 UPh7aqDgdAN7; Sun, 9 Oct 2016 20:57:57 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 7063016129C; Sun, 9 Oct 2016 20:57:57 -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 MZv7QULKrMBB; Sun, 9 Oct 2016 20:57:57 -0700 (PDT) Original-Received: from [192.168.1.9] (unknown [47.153.191.53]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 34DD5161294; Sun, 9 Oct 2016 20:57:57 -0700 (PDT) In-Reply-To: <871szsc8lf.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:208132 Archived-At: This is a multi-part message in MIME format. --------------7A12A8E2DC25AB7A392B63D1 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable G=C3=B6ktu=C4=9F Kayaalp wrote: > I'm rather > uninitiated about the conventions regarding that file, so please warn m= e > if anything's wrong It's helpful to use 'git format-patch' to prepare patches, and to prepare= =20 ChangeLog entries in the style suggested in the CONTRIBUTE file. Also, I = think=20 some of the checking can be done at variable-setting time rather than at=20 run-time. How about the attached patches instead? The first one is yours = with a=20 ChangeLog entry; the second one contains some proposed minor fixups. You can apply these patches to a fresh checkout from 'master' by using th= e=20 command 'git am'. --------------7A12A8E2DC25AB7A392B63D1 Content-Type: text/x-diff; name="0001-New-user-variable-electric-quote-chars.patch" Content-Disposition: attachment; filename="0001-New-user-variable-electric-quote-chars.patch" Content-Transfer-Encoding: quoted-printable >From d63be0394bc94c8b763f4869759f2f2603ff6981 Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?G=3DC3=3DB6ktu=3DC4=3D9F=3D20Kayaalp?=3D Date: Sun, 9 Oct 2016 11:29:50 -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 | 74 ++++++++++++++++++++++++++++++++---------------= ------ 3 files changed, 61 insertions(+), 31 deletions(-) diff --git a/doc/emacs/text.texi b/doc/emacs/text.texi index 579f788..74b68dd 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,11 +421,17 @@ 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}. These conversions= are suppressed in buffers whose coding systems cannot represent curved -quote characters. +quote characters. 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 @@ -445,7 +452,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 14450a6..d52dbe6 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 0ec0a1e..5c7be35 100644 --- a/lisp/electric.el +++ b/lisp/electric.el @@ -425,16 +425,26 @@ 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" :type 'boolean :safe 'booleanp :group 'electricity) =20 -(defun electric--insertable-p (string) - (or (not buffer-file-coding-system) - (eq (coding-system-base buffer-file-coding-system) 'undecided) - (not (unencodable-char-position nil nil buffer-file-coding-system - nil string)))) +(defun electric--insertable-p (string-or-char) + (let ((str (if (characterp string-or-char) + (string string-or-char) + string-or-char))) + (or (not buffer-file-coding-system) + (eq (coding-system-base buffer-file-coding-system) 'undecided) + (not (unencodable-char-position nil nil buffer-file-coding-syste= m + nil str))))) =20 (defun electric-quote-post-self-insert-function () "Function that `electric-quote-mode' adds to `post-self-insert-hook'. @@ -457,30 +467,33 @@ 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 ((and (electric--insertable-p "=E2=80=9C") - (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)) - ((and (electric--insertable-p "=E2=80=98") - (search-backward "`" (1- (point)) t)) - (replace-match "=E2=80=98") - (setq last-command-event ?=E2=80=98))) - (cond ((and (electric--insertable-p "=E2=80=9D") - (search-backward "=E2=80=99'" (- (point) 2) t)) - (replace-match "=E2=80=9D") - (setq last-command-event ?=E2=80=9D)) - ((and (electric--insertable-p "=E2=80=99") - (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 ((and (electric--insertable-p q3) + (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)) + ((and (electric--insertable-p q1) + (search-backward "`" (1- (point)) t)) + (replace-match (string q1)) + (setq last-command-event q1))) + (cond ((and (electric--insertable-p q4) + (search-backward (string q2 ?') (- (point) 2)= t)) + (replace-match (string q4)) + (setq last-command-event q4)) + ((and (electric--insertable-p q2) + (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 @@ -497,6 +510,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 --------------7A12A8E2DC25AB7A392B63D1 Content-Type: text/x-diff; name="0002-electric-quote-chars-fixups.patch" Content-Disposition: attachment; filename="0002-electric-quote-chars-fixups.patch" Content-Transfer-Encoding: quoted-printable >From b3467c27c31ca2034f67f56438cfc8576c8f38b2 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 9 Oct 2016 11:29:50 -0700 Subject: [PATCH 2/2] electric-quote-chars fixups MIME-Version: 1.0 Content-Type: text/plain; charset=3DUTF-8 Content-Transfer-Encoding: 8bit * lisp/electric.el (electric-quote-chars): Check types and safety more carefully. (electric--insertable-p): Don=E2=80=99t bother with string argument, as that is no longer used. Don=E2=80=99t call =E2=80=98string=E2=80=99 unle= ss needed. (electric-quote-post-self-insert-function): Use more-mnemonic locals. Omit no-longer-necessary runtime error diagnostic. --- lisp/electric.el | 64 +++++++++++++++++++++++++++++---------------------= ------ 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/lisp/electric.el b/lisp/electric.el index 5c7be35..b15e8ab 100644 --- a/lisp/electric.el +++ b/lisp/electric.el @@ -427,24 +427,27 @@ 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." :version "25.1" :type 'boolean :safe 'booleanp :group 'electricity) =20 -(defun electric--insertable-p (string-or-char) - (let ((str (if (characterp string-or-char) - (string string-or-char) - string-or-char))) - (or (not buffer-file-coding-system) - (eq (coding-system-base buffer-file-coding-system) 'undecided) - (not (unencodable-char-position nil nil buffer-file-coding-syste= m - nil str))))) +(defun electric--insertable-p (char) + (or (not buffer-file-coding-system) + (eq (coding-system-base buffer-file-coding-system) 'undecided) + (not (unencodable-char-position nil nil buffer-file-coding-system + nil (string char))))) =20 (defun electric-quote-post-self-insert-function () "Function that `electric-quote-mode' adds to `post-self-insert-hook'. @@ -468,32 +471,31 @@ electric-quote-post-self-insert-function (or (eq last-command-event ?\`) (save-excursion (backward-paragraph) (point))))))) (pcase electric-quote-chars - (`(,q1 ,q2 ,q3 ,q4) + (`(,l ,r ,ll ,rr) (when start (save-excursion (if (eq last-command-event ?\`) - (cond ((and (electric--insertable-p q3) - (search-backward (string q1 ?`) (- (point) = 2) t)) - (replace-match (string q3)) + (cond ((and (electric--insertable-p ll) + (search-backward (string l ?`) (- (point) 2= ) t)) + (replace-match (string ll)) (when (and electric-pair-mode (eq (cdr-safe - (assq q1 electric-pair-text-pair= s)) + (assq l electric-pair-text-pairs= )) (char-after))) (delete-char 1)) - (setq last-command-event q3)) - ((and (electric--insertable-p q1) + (setq last-command-event ll)) + ((and (electric--insertable-p l) (search-backward "`" (1- (point)) t)) - (replace-match (string q1)) - (setq last-command-event q1))) - (cond ((and (electric--insertable-p q4) - (search-backward (string q2 ?') (- (point) 2)= t)) - (replace-match (string q4)) - (setq last-command-event q4)) - ((and (electric--insertable-p q2) + (replace-match (string l)) + (setq last-command-event l))) + (cond ((and (electric--insertable-p rr) + (search-backward (string r ?') (- (point) 2) = t)) + (replace-match (string rr)) + (setq last-command-event rr)) + ((and (electric--insertable-p r) (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 r)) + (setq last-command-event r))))))))))) =20 (put 'electric-quote-post-self-insert-function 'priority 10) =20 @@ -510,8 +512,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 --------------7A12A8E2DC25AB7A392B63D1--