]> git.eshelyaron.com Git - emacs.git/commitdiff
New user variable 'electric-quote-chars'
authorGöktuğ Kayaalp <self@gkayaalp.com>
Thu, 27 Oct 2016 15:05:24 +0000 (08:05 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 27 Oct 2016 15:11:25 +0000 (08:11 -0700)
* 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.

doc/emacs/text.texi
etc/NEWS
lisp/electric.el

index 7fa0804d27053f786895eb1b6f3cae67795a637d..4c6a1ffbdd2d93df62f290ce536ba66343ca5521 100644 (file)
@@ -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,9 +421,15 @@ left and right single or double quotation marks @t{‘like this’} or
 @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{”}.
+@t{``} to @t{“}, and @t{''} to @t{”}.  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
@@ -443,7 +450,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{‘}, @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
index a160f8102341bcaee16f66c91840ccbb93410305..addd05695fb9f5b14f97c3f391cdf0f82aa2cd3b 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -61,6 +61,11 @@ 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.
 Use the new group 'text', which inherits from 'wp', instead.
index f35f8b99db3a2094b2b660f2aa389bc41a04e7f4..19cded25dfbd63600668396ddf900a30b12dc079 100644 (file)
@@ -425,6 +425,13 @@ The variable `electric-layout-rules' says when and how to insert newlines."
   :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"
@@ -451,26 +458,29 @@ 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 ((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 ?“))
-                    ((search-backward "`" (1- (point)) t)
-                     (replace-match "‘")
-                     (setq last-command-event ?‘)))
-            (cond ((search-backward "’'" (- (point) 2) t)
-                   (replace-match "”")
-                   (setq last-command-event ?”))
-                  ((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 ((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))
+                       ((search-backward "`" (1- (point)) t)
+                        (replace-match (string q1))
+                        (setq last-command-event q1)))
+               (cond ((search-backward (string q2 ?') (- (point) 2) t)
+                      (replace-match (string q4))
+                      (setq last-command-event q4))
+                     ((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)
 
@@ -487,6 +497,9 @@ and text paragraphs, and these are selectively controlled with
 `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