emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Enable customisation for electric-quote-mode chars


From: Göktuğ Kayaalp
Subject: Re: [PATCH] Enable customisation for electric-quote-mode chars
Date: Sun, 28 Aug 2016 04:00:48 +0300

On  Sat, 27 Aug 2016 17:38:24 +0300, Eli Zaretskii <address@hidden> wrote:
> Thanks, but please include in the patch the necessary changes for
> etc/NEWS and for the user manual.

On Cts, Ağu 27 2016 at 12:16:39 PM, Paul Eggert <address@hidden> wrote:
> Göktuğ 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 
> string 
> 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.  ‘electric--insertable-p’ 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).
‘doc/emacs/docstyle.texi’ 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".

-- 
İ. Göktuğ Kayaalp.
http://gkayaalp.com/

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
address@hidden 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 @@
 address@hidden, and in programming-language strings if
 @code{electric-quote-string} is address@hidden  The default is
 @code{nil} for @code{electric-quote-string} and @code{t} for the other
-variables.
+variables.
+
address@hidden 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.
 
   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
 
 +++
+** 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.
 
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)
 
+(defcustom electric-quote-chars '(?‘ ?’ ?“ ?”)
+  "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)
 
-(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'.
 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 "“")
+              (cond ((and (electric--insertable-p q3)
                           (search-backward "‘`" (- (point) 2) t))
-                     (replace-match "“")
+                     (replace-match (string q3))
                      (when (and electric-pair-mode
                                 (eq (cdr-safe
-                                     (assq ?‘ electric-pair-text-pairs))
+                                     (assq q1 electric-pair-text-pairs))
                                     (char-after)))
                        (delete-char 1))
-                     (setq last-command-event ?“))
-                    ((and (electric--insertable-p "‘")
+                     (setq last-command-event q3))
+                    ((and (electric--insertable-p q1)
                           (search-backward "`" (1- (point)) t))
-                     (replace-match "‘")
-                     (setq last-command-event ?‘)))
-            (cond ((and (electric--insertable-p "”")
+                     (replace-match (string q1))
+                     (setq last-command-event q1)))
+            (cond ((and (electric--insertable-p q4)
                         (search-backward "’'" (- (point) 2) t))
-                   (replace-match "”")
-                   (setq last-command-event ?”))
-                  ((and (electric--insertable-p "’")
+                   (replace-match (string q4))
+                   (setq last-command-event q4))
+                  ((and (electric--insertable-p q2)
                         (search-backward "'" (1- (point)) t))
-                   (replace-match "’")
-                   (setq last-command-event ?’)))))))))
+                   (replace-match (string q2))
+                   (setq last-command-event q2)))))))))
 
 (put 'electric-quote-post-self-insert-function 'priority 10)
 
@@ -497,6 +512,9 @@
 `electric-quote-comment', `electric-quote-string', and
 `electric-quote-paragraph'.
 
+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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]