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: Sun, 28 Aug 2016 04:00:48 +0300 Message-ID: <87twe57lmn.fsf@xi.bootis> References: <01484c2f-9094-998e-e60c-d0bb95450b0b@cs.ucla.edu> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1472345437 16589 195.159.176.226 (28 Aug 2016 00:50:37 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 28 Aug 2016 00:50:37 +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 Sun Aug 28 02:50:33 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 1bdoIy-0003uq-FM for ged-emacs-devel@m.gmane.org; Sun, 28 Aug 2016 02:50:32 +0200 Original-Received: from localhost ([::1]:37653 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bdoIv-0003x6-OX for ged-emacs-devel@m.gmane.org; Sat, 27 Aug 2016 20:50:29 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37451) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bdoIo-0003wk-U5 for emacs-devel@gnu.org; Sat, 27 Aug 2016 20:50:24 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bdoIm-0006lU-Cd for emacs-devel@gnu.org; Sat, 27 Aug 2016 20:50:21 -0400 Original-Received: from relay2-d.mail.gandi.net ([217.70.183.194]:51906) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bdoIg-0006ip-GV; Sat, 27 Aug 2016 20:50:14 -0400 Original-Received: from mfilter42-d.gandi.net (mfilter42-d.gandi.net [217.70.178.172]) by relay2-d.mail.gandi.net (Postfix) with ESMTP id 45640C5A51; Sun, 28 Aug 2016 02:50:13 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter42-d.gandi.net Original-Received: from relay2-d.mail.gandi.net ([IPv6:::ffff:217.70.183.194]) by mfilter42-d.gandi.net (mfilter42-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id sKxiENLc6alP; Sun, 28 Aug 2016 02:50:11 +0200 (CEST) X-Originating-IP: 78.181.205.50 Original-Received: from localhost (unknown [78.181.205.50]) (Authenticated sender: self@gkayaalp.com) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id C49B3C5A49; Sun, 28 Aug 2016 02:50:09 +0200 (CEST) In-Reply-To: <01484c2f-9094-998e-e60c-d0bb95450b0b@cs.ucla.edu> (message from Paul Eggert on Sat, 27 Aug 2016 12:16:39 -0700) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 217.70.183.194 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:206842 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Sat, 27 Aug 2016 17:38:24 +0300, Eli Zaretskii wrote: > Thanks, but please include in the patch the necessary changes for > etc/NEWS and for the user manual. On Cts, A=C4=9Fu 27 2016 at 12:16:39 PM, Paul Eggert w= rote: > G=C3=B6ktu=C4=9F Kayaalp wrote: >> You're welcome, I'll be able to send that in tomorrow, on this thread. > > Thanks. Also, please change the argument of electric--insertable-p from s= tring=20 > to character. This function is private so it's OK to change the API. This new (attached) patch satisfies both of your requests, and fixes my use of functions from cl.el. =E2=80=98electric--insertable-p=E2=80=99 now = accepts either a string or a character, and makes a one-char string if given a single character, as inside the function the argument is passed to another function that needs a string. On a side note, I guess the build system should require a certain minimum version for the texinfo compiler (I only read info, so IDK which program), as while the build goes fine with the default texinfo 4.8 on my FreeBSD 10.3, the end result renders multibyte characters as octal escape sequences (all okay when I installed 6.1 from ports). =E2=80=98doc/emacs/docstyle.texi=E2=80=99 from 25.1-rc2 has this: @c Emacs documentation style settings @documentencoding UTF-8 @c These two require Texinfo 5.0 or later, so we use the older @c equivalent @set variables supported in 4.11 and hence Build doesn't fail but says "unrecognised encoding UTF-8". --=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: updated patch diff --git a/doc/emacs/text.texi b/doc/emacs/text.texi index 579f788..ac899d6 100644 --- a/doc/emacs/text.texi +++ b/doc/emacs/text.texi @@ -412,6 +412,7 @@ @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 @@ -436,7 +437,15 @@ non-@code{nil}, and in programming-language strings if @code{electric-quote-string} is non-@code{nil}. The default is @code{nil} for @code{electric-quote-string} and @code{t} for the other -variables. +variables. + +@vindex electric-quote-chars + By default @code{electric-quote-mode} inserts curvy double quotes, +but it is possible to customize what characters are used. The +variable @code{electric-quote-chars} contains a list of four +characters, where the first two are used for left single quotes, and +the last two is used for double quotes. This variable may be modified +to determine what types of quote characters to use. =20 Electric Quote mode is disabled by default. To toggle it, type @kbd{M-x electric-quote-mode}. To toggle it in a single buffer, use diff --git a/etc/NEWS b/etc/NEWS index 1290fa4..4746710 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -56,6 +56,11 @@ * Changes in Emacs 25.2 =20 +++ +** The new user variable 'electric-quote-chars' provides a list +of curvy 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..0cd9e34 100644 --- a/lisp/electric.el +++ b/lisp/electric.el @@ -425,23 +425,38 @@ :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) + "List of characters to use as replacements for `electric-quote-mode'. + +The first and the second elements are single quotes, and the +third and the fourth elements are double quotes." + :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'. This requotes when a quoting key is typed." (when (and electric-quote-mode (memq last-command-event '(?\' ?\`))) - (let ((start + (let ((q1 (nth 0 electric-quote-chars)) + (q2 (nth 1 electric-quote-chars)) + (q3 (nth 2 electric-quote-chars)) + (q4 (nth 3 electric-quote-chars)) + (start (if (and comment-start comment-use-syntax) (when (or electric-quote-comment electric-quote-string) (let* ((syntax (syntax-ppss)) @@ -460,27 +475,27 @@ (when start (save-excursion (if (eq last-command-event ?\`) - (cond ((and (electric--insertable-p "=E2=80=9C") + (cond ((and (electric--insertable-p q3) (search-backward "=E2=80=98`" (- (point) 2) t)) - (replace-match "=E2=80=9C") + (replace-match (string q3)) (when (and electric-pair-mode (eq (cdr-safe - (assq ?=E2=80=98 electric-pair-text-p= airs)) + (assq q1 electric-pair-text-pairs)) (char-after))) (delete-char 1)) - (setq last-command-event ?=E2=80=9C)) - ((and (electric--insertable-p "=E2=80=98") + (setq last-command-event q3)) + ((and (electric--insertable-p q1) (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") + (replace-match (string q1)) + (setq last-command-event q1))) + (cond ((and (electric--insertable-p q4) (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") + (replace-match (string q4)) + (setq last-command-event q4)) + ((and (electric--insertable-p q2) (search-backward "'" (1- (point)) t)) - (replace-match "=E2=80=99") - (setq last-command-event ?=E2=80=99))))))))) + (replace-match (string q2)) + (setq last-command-event q2))))))))) =20 (put 'electric-quote-post-self-insert-function 'priority 10) =20 @@ -497,6 +512,9 @@ `electric-quote-comment', `electric-quote-string', and `electric-quote-paragraph'. =20 +Customize `electric-quote-chars' in order to determine which +quote characters to use. + This is a global minor mode. To toggle the mode in a single buffer, use `electric-quote-local-mode'." :global t :group 'electricity --=-=-=--