emacs-devel
[Top][All Lists]
Advanced

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

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


From: Göktuğ Kayaalp
Subject: [PATCH] Enable customisation for electric-quote-mode chars
Date: Sat, 27 Aug 2016 17:22:31 +0300

This patch enables the user to decide which quote characters to use for
curved quotes.  Styles change from script to script and from language to
language, so it's nicer not to impose any one of the options (for
example in Italy and France ‘guillemets’ are used, which are («) and
(»), and in German speaking world („) and (“)).

I'm not subscribed to the -devel list, so please keep me in the CC;
thanks in advance.

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

diff --git a/lisp/electric.el b/lisp/electric.el
index e289601..f748c55 100644
--- a/lisp/electric.el
+++ b/lisp/electric.el
@@ -425,6 +425,14 @@ 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 '(?‘ ?’ ?“ ?”)
+  "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"
@@ -441,7 +449,11 @@ The variable `electric-layout-rules' says when and how to 
insert newlines."
 This requotes when a quoting key is typed."
   (when (and electric-quote-mode
              (memq last-command-event '(?\' ?\`)))
-    (let ((start
+    (let ((q1 (car electric-quote-chars))
+          (q2 (cadr electric-quote-chars))
+          (q3 (caddr electric-quote-chars))
+          (q4 (cadddr 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 +472,27 @@ This requotes when a quoting key is typed."
       (when start
         (save-excursion
           (if (eq last-command-event ?\`)
-              (cond ((and (electric--insertable-p "“")
+              (cond ((and (electric--insertable-p (string 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 (string 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 (string 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 (string 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 +509,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 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]