all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Göktuğ Kayaalp" <self@gkayaalp.com>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: eliz@gnu.org, emacs-devel@gnu.org
Subject: Re: [PATCH] Enable customisation for electric-quote-mode chars
Date: Sun, 28 Aug 2016 04:00:48 +0300	[thread overview]
Message-ID: <87twe57lmn.fsf@xi.bootis> (raw)
In-Reply-To: <01484c2f-9094-998e-e60c-d0bb95450b0b@cs.ucla.edu> (message from Paul Eggert on Sat, 27 Aug 2016 12:16:39 -0700)

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


On  Sat, 27 Aug 2016 17:38:24 +0300, Eli Zaretskii <eliz@gnu.org> 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 <eggert@cs.ucla.edu> 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/


[-- Attachment #2: updated patch --]
[-- Type: text/x-diff, Size: 6211 bytes --]

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
+@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
@@ -436,7 +437,15 @@
 non-@code{nil}, and in programming-language strings if
 @code{electric-quote-string} is non-@code{nil}.  The default is
 @code{nil} for @code{electric-quote-string} and @code{t} for the other
-variables.
+variables.
+
+@vindex 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	other threads:[~2016-08-28  1:00 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 [this message]
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

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=87twe57lmn.fsf@xi.bootis \
    --to=self@gkayaalp.com \
    --cc=eggert@cs.ucla.edu \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    /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.