all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: "Göktuğ Kayaalp" <self@gkayaalp.com>
Cc: emacs-devel@gnu.org
Subject: Re: [PATCH] Enable customisation for electric-quote-mode chars
Date: Sun, 9 Oct 2016 20:57:56 -0700	[thread overview]
Message-ID: <7103c4cf-1f1d-23f4-d421-1090c30fcde3@cs.ucla.edu> (raw)
In-Reply-To: <871szsc8lf.fsf@xi.bootis>

[-- Attachment #1: Type: text/plain, Size: 622 bytes --]

Göktuğ Kayaalp wrote:
> I'm rather
> uninitiated about the conventions regarding that file, so please warn me
> if anything's wrong

It's helpful to use 'git format-patch' to prepare patches, and to prepare 
ChangeLog entries in the style suggested in the CONTRIBUTE file. Also, I think 
some of the checking can be done at variable-setting time rather than at 
run-time. How about the attached patches instead? The first one is yours with a 
ChangeLog entry; the second one contains some proposed minor fixups.

You can apply these patches to a fresh checkout from 'master' by using the 
command 'git am'.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-New-user-variable-electric-quote-chars.patch --]
[-- Type: text/x-diff; name="0001-New-user-variable-electric-quote-chars.patch", Size: 8130 bytes --]

From d63be0394bc94c8b763f4869759f2f2603ff6981 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?G=C3=B6ktu=C4=9F=20Kayaalp?= <self@gkayaalp.com>
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{“like this”}.  In text files, typewriter quotes are simple and
 portable; curved quotes are less ambiguous and typically look nicer.
 
+@vindex electric-quote-chars
   Electric Quote mode makes it easier to type curved quotes.  As you
 type characters it optionally converts @t{`} to @t{‘}, @t{'} to @t{’},
 @t{``} to @t{“}, and @t{''} to @t{”}.  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{'(?‘ ?’ ?“ ?”)}.
 
 @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{‘}, @kbd{C-x 8 ]} for
 @t{’}, @kbd{C-x 8 @{} for @t{“}, and @kbd{C-x 8 @}} for @t{”}.
-@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}.
 
 @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 December 2013.
 
 \f
 * 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.
 
 ---
 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)
 
+(defcustom electric-quote-chars '(?‘ ?’ ?“ ?”)
+  "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)
 
-(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)))))
 
 (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 "“")
-                          (search-backward "‘`" (- (point) 2) t))
-                     (replace-match "“")
-                     (when (and electric-pair-mode
-                                (eq (cdr-safe
-                                     (assq ?‘ electric-pair-text-pairs))
-                                    (char-after)))
-                       (delete-char 1))
-                     (setq last-command-event ?“))
-                    ((and (electric--insertable-p "‘")
-                          (search-backward "`" (1- (point)) t))
-                     (replace-match "‘")
-                     (setq last-command-event ?‘)))
-            (cond ((and (electric--insertable-p "”")
-                        (search-backward "’'" (- (point) 2) t))
-                   (replace-match "”")
-                   (setq last-command-event ?”))
-                  ((and (electric--insertable-p "’")
-                        (search-backward "'" (1- (point)) t))
-                   (replace-match "’")
-                   (setq last-command-event ?’)))))))))
+      (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-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 "‘electric-quote-chars’ must contain exactly 4 characters."))))))
 
 (put 'electric-quote-post-self-insert-function 'priority 10)
 
@@ -497,6 +510,9 @@ electric-quote-mode
 `electric-quote-comment', `electric-quote-string', and
 `electric-quote-paragraph'.
 
+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
-- 
2.7.4


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-electric-quote-chars-fixups.patch --]
[-- Type: text/x-diff; name="0002-electric-quote-chars-fixups.patch", Size: 5846 bytes --]

From b3467c27c31ca2034f67f56438cfc8576c8f38b2 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
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=UTF-8
Content-Transfer-Encoding: 8bit

* lisp/electric.el (electric-quote-chars): Check types and safety
more carefully.
(electric--insertable-p): Don’t bother with string argument, as
that is no longer used.  Don’t call ‘string’ unless 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
 
 (defcustom electric-quote-chars '(?‘ ?’ ?“ ?”)
   "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)
 
 (defcustom electric-quote-paragraph t
   "Non-nil means to use electric quoting in text paragraphs."
   :version "25.1"
   :type 'boolean :safe 'booleanp :group 'electricity)
 
-(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)))))
+(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)))))
 
 (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-pairs))
+                                        (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 "‘electric-quote-chars’ must contain exactly 4 characters."))))))
+                      (replace-match (string r))
+                      (setq last-command-event r)))))))))))
 
 (put 'electric-quote-post-self-insert-function 'priority 10)
 
@@ -510,8 +512,8 @@ electric-quote-mode
 `electric-quote-comment', `electric-quote-string', and
 `electric-quote-paragraph'.
 
-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.
 
 This is a global minor mode.  To toggle the mode in a single buffer,
 use `electric-quote-local-mode'."
-- 
2.7.4


  reply	other threads:[~2016-10-10  3:57 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-27 14:22 [PATCH] Enable customisation for electric-quote-mode chars Göktuğ Kayaalp
2016-08-27 14:38 ` Eli Zaretskii
2016-08-27 15:23   ` Göktuğ Kayaalp
2016-08-27 19:16     ` Paul Eggert
2016-08-28  1:00       ` Göktuğ Kayaalp
2016-08-29  1:55         ` Paul Eggert
2016-08-29  5:28           ` Göktuğ Kayaalp
2016-08-29  6:14             ` Paul Eggert
2016-10-05 18:53               ` Göktuğ Kayaalp
2016-10-05 19:06                 ` Paul Eggert
2016-10-06  6:40                   ` Eli Zaretskii
2016-10-06 21:31                     ` Paul Eggert
2016-10-07 18:33                       ` Göktuğ Kayaalp
2016-10-10  3:57                         ` Paul Eggert [this message]
2016-10-13 18:28                           ` Göktuğ Kayaalp
2016-10-13 18:35                             ` Paul Eggert
2016-10-22 14:00                               ` Göktuğ Kayaalp
2016-10-23 10:25                                 ` Paul Eggert
2016-10-23 15:09                                   ` Göktuğ Kayaalp
2016-10-27 15:12                                     ` Paul Eggert
2016-10-27 17:21                                       ` Göktuğ Kayaalp
2016-08-29 15:08             ` Eli Zaretskii
2016-08-29 15:54               ` Yuri Khan
2016-08-29 16:23                 ` Eli Zaretskii
2016-08-29 16:27               ` Göktuğ Kayaalp
2016-08-29 16:39                 ` Eli Zaretskii
2016-08-29 17:19                   ` Göktuğ Kayaalp
2016-08-29 17:30                 ` Paul Eggert
2016-08-29 17:44                   ` Eli Zaretskii
2016-08-29 18:43                     ` Paul Eggert
2016-08-29 19:30                       ` Eli Zaretskii
2016-08-30 17:38                         ` Paul Eggert
2016-08-30 17:49                           ` Eli Zaretskii
2016-08-31 11:08                             ` Richard Stallman
2016-09-01 18:56                         ` Göktuğ Kayaalp
2016-09-01 19:15                           ` Paul Eggert
2016-09-01 21:13                             ` Göktuğ Kayaalp
2016-09-01 21:30                               ` Paul Eggert
2016-09-02  5:06                                 ` Yuri Khan
2016-09-02  7:30                                   ` Eli Zaretskii
2016-09-02 10:37                                     ` Yuri Khan
2016-09-02 13:24                                       ` Göktuğ Kayaalp
2016-08-29 16:15           ` tarball builds (was: [PATCH] Enable customisation for electric-quote-mode chars) Stefan Monnier
2016-08-30 15:14             ` Eli Zaretskii
2016-08-30 15:53               ` tarball builds Stefan Monnier
2016-08-30 15:59             ` Paul Eggert
2016-08-30 17:00               ` Stefan Monnier
2016-08-30 17:58                 ` Paul Eggert
2016-08-29  2:33         ` [PATCH] Enable customisation for electric-quote-mode chars Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7103c4cf-1f1d-23f4-d421-1090c30fcde3@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=emacs-devel@gnu.org \
    --cc=self@gkayaalp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.