unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] Enable customisation for electric-quote-mode chars
@ 2016-08-27 14:22 Göktuğ Kayaalp
  2016-08-27 14:38 ` Eli Zaretskii
  0 siblings, 1 reply; 49+ messages in thread
From: Göktuğ Kayaalp @ 2016-08-27 14:22 UTC (permalink / raw)
  To: emacs-devel; +Cc: self

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

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/


[-- Attachment #2: [PATCH] Enable customisation for electric-quote-mode chars --]
[-- Type: text/x-diff, Size: 3936 bytes --]

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

^ permalink raw reply related	[flat|nested] 49+ messages in thread

end of thread, other threads:[~2016-10-27 17:21 UTC | newest]

Thread overview: 49+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).