From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: =?utf-8?Q?G=C3=B6ktu=C4=9F_Kayaalp?= Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Enable customisation for electric-quote-mode chars Date: Mon, 29 Aug 2016 08:28:19 +0300 Message-ID: <87d1ksdtzg.fsf@xi.bootis> References: <45fb742d-0121-3588-e87d-3a80c9d1d056@cs.ucla.edu> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1472447887 21833 195.159.176.226 (29 Aug 2016 05:18:07 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 29 Aug 2016 05:18:07 +0000 (UTC) Cc: eliz@gnu.org, emacs-devel@gnu.org To: Paul Eggert Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Aug 29 07:18:02 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 1beExN-000532-1J for ged-emacs-devel@m.gmane.org; Mon, 29 Aug 2016 07:18:01 +0200 Original-Received: from localhost ([::1]:41873 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beExK-0006Hb-8t for ged-emacs-devel@m.gmane.org; Mon, 29 Aug 2016 01:17:58 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:42881) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beExA-0006HU-Lh for emacs-devel@gnu.org; Mon, 29 Aug 2016 01:17:50 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1beEx8-0000UF-Q8 for emacs-devel@gnu.org; Mon, 29 Aug 2016 01:17:48 -0400 Original-Received: from relay5-d.mail.gandi.net ([217.70.183.197]:40081) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beEx2-0000Tu-N7; Mon, 29 Aug 2016 01:17:41 -0400 Original-Received: from mfilter14-d.gandi.net (mfilter14-d.gandi.net [217.70.178.142]) by relay5-d.mail.gandi.net (Postfix) with ESMTP id 461E241C07D; Mon, 29 Aug 2016 07:17:38 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter14-d.gandi.net Original-Received: from relay5-d.mail.gandi.net ([IPv6:::ffff:217.70.183.197]) by mfilter14-d.gandi.net (mfilter14-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id cIWNo-Mu3_1F; Mon, 29 Aug 2016 07:17:36 +0200 (CEST) X-Originating-IP: 78.181.205.50 Original-Received: from localhost (unknown [78.181.205.50]) (Authenticated sender: self@gkayaalp.com) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 6277F41C088; Mon, 29 Aug 2016 07:17:35 +0200 (CEST) In-Reply-To: <45fb742d-0121-3588-e87d-3a80c9d1d056@cs.ucla.edu> (message from Paul Eggert on Sun, 28 Aug 2016 18:55:06 -0700) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 217.70.183.197 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:206858 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Paz, A=C4=9Fu 28 2016 at 06:55:06 PM, Paul Eggert w= rote: > G=C3=B6ktu=C4=9F Kayaalp wrote: > [...] > > * Part of the code still assumes English-style single quoting, and won't = work if=20 > electric-quote-chars is set appropriately for (say) French. Look for inst= ances=20 > of the two characters =E2=80=98 and =E2=80=99 in the string constants. Mo= re generally, I'd look=20 > for any non-ASCII character in that file. > > * The documentation should say "curved" rather than "curvy" for consisten= cy with=20 > what's there now. > > * The documentation is a bit sloppy about which quotes are used for what,= e.g.,=20 > "the first two are used for left single quotes" is not correct and the do= c=20 > string is a bit hard to follow. For the documentation I suggest specifyin= g the=20 > default value in the manual, as that should make it easier to explain the= format=20 > of the variable. > > * Perhaps use pcase instead of 4 calls to nth? It'd make the code easier = to read. All done, I hope that's okay to apply now. The new patch is attached. I'll try to improve it if need be. > * Finally, it's a nontrivial patch so I assume you're OK with assigning=20 > copyright to the FSF? If so, I can start the ball rolling on the paperwor= k for you. Allright, I'm okay with that, please go ahead. BTW I also have a patch submitted recently to the bug-gnu-emacs@ for bug#24082, should I post it here instead? > Thanks again. You're welcome, I'm glad if this is helpful. --=20 =C4=B0. G=C3=B6ktu=C4=9F Kayaalp. http://gkayaalp.com/ --=-=-= Content-Type: text/x-diff; charset=utf-8 Content-Disposition: inline; filename=electric.patch Content-Transfer-Encoding: quoted-printable Content-Description: fixed patch 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 @@ beginning of a line. @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 @@ left and right single or double quotation marks @t{= =E2=80=98like this=E2=80=99} or @t{=E2=80=9Clike this=E2=80=9D}. In text files, typewriter quotes are sim= ple 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 a= re 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 @@ type @kbd{C-q `} or @kbd{C-q '} instead of @kbd{`} or = @kbd{'}. To 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 ]} for @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 1290fa4..e7682fb 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -56,6 +56,11 @@ affected by this, as SGI stopped supporting IRIX in Dece= mber 2013. * Changes in Emacs 25.2 =20 +++ +** 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. + ++++ ** The new funtion 'call-shell-region' executes a command in an inferior shell with the buffer region as input. =20 diff --git a/lisp/electric.el b/lisp/electric.el index e289601..c0c4b47 100644 --- a/lisp/electric.el +++ b/lisp/electric.el @@ -425,16 +425,26 @@ The variable `electric-layout-rules' says when and ho= w to insert newlines." :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-system + 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 @@ This requotes when a quoting key is typed." (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-p= airs)) - (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)=20 + (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-pairs)) + (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 exa= ctly 4 characters.")))))) =20 (put 'electric-quote-post-self-insert-function 'priority 10) =20 @@ -497,6 +510,9 @@ and text paragraphs, and these are selectively controll= ed with `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 --=-=-=--