all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Philipp Stephani <p.stephani2@gmail.com>
To: Paul Eggert <eggert@cs.ucla.edu>, Eli Zaretskii <eliz@gnu.org>
Cc: 24710@debbugs.gnu.org
Subject: bug#24710: 26.0.50; Feature request: Replace double quotes in electric-quote-mode
Date: Sun, 24 Sep 2017 07:04:07 +0000	[thread overview]
Message-ID: <CAArVCkS2zb3ahK14BwoEwn6cNeqeZ7_mCfQq6RgLD=mgvoLuAg@mail.gmail.com> (raw)
In-Reply-To: <d00c4962-c4c9-2505-fae1-2f0a966bc7af@cs.ucla.edu>


[-- Attachment #1.1: Type: text/plain, Size: 232 bytes --]

Paul Eggert <eggert@cs.ucla.edu> schrieb am So., 24. Sep. 2017 um 07:03 Uhr:

> Eli Zaretskii wrote:
> > Thanks.  How about updating the Emacs manual as well?
>
> Yes, other than that it looks good to me.
>

OK, here's a new patch.

[-- Attachment #1.2: Type: text/html, Size: 522 bytes --]

[-- Attachment #2: 0001-Electric-quote-mode-Conditionally-replace-Bug-24710.txt --]
[-- Type: text/plain, Size: 9025 bytes --]

From 42fcd38800b209fa3c8fc1bb67020749312f78af Mon Sep 17 00:00:00 2001
From: Philipp Stephani <phst@google.com>
Date: Sun, 23 Jul 2017 21:58:49 +0200
Subject: [PATCH] Electric quote mode: Conditionally replace " (Bug#24710)

* lisp/electric.el (electric-quote-replace-double): New user option.
(electric-quote-post-self-insert-function): Use it.

* electric-tests.el (electric-quote-replace-double-disabled)
(electric-quote-replace-double-bob)
(electric-quote-replace-double-bol)
(electric-quote-replace-double-after-space)
(electric-quote-replace-double-after-letter)
(electric-quote-replace-double-after-paren): New unit tests.
---
 doc/emacs/text.texi         |  7 +++++++
 etc/NEWS                    |  5 +++++
 lisp/electric.el            | 25 +++++++++++++++++++++----
 test/lisp/electric-tests.el | 41 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 74 insertions(+), 4 deletions(-)

diff --git a/doc/emacs/text.texi b/doc/emacs/text.texi
index 496b43ce1e..5aa0c77d34 100644
--- a/doc/emacs/text.texi
+++ b/doc/emacs/text.texi
@@ -443,6 +443,13 @@ Quotation Marks
 @code{nil} for @code{electric-quote-string} and @code{t} for the other
 variables.
 
+@vindex electric-quote-replace-double
+  You can also set the option @code{electric-quote-replace-double} to
+a non-@code{nil} value.  Then, typing @t{"} insert an appropriate
+curved double quote depending on context: @t{“} at the beginning of
+the buffer or after a line break, whitespace, opening parenthesis, or
+quote character, and @t{”} otherwise.
+
   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
 @kbd{M-x electric-quote-local-mode}.  To suppress it for a single use,
diff --git a/etc/NEWS b/etc/NEWS
index 0e62a2bbb4..26e3ccb473 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -34,6 +34,11 @@ When you add a new item, use the appropriate mark if you are sure it applies,
 \f
 * Editing Changes in Emacs 27.1
 
++++
+** The new user option 'electric-quote-replace-double' controls
+whether " is also replaced in 'electric-quote-mode'.  If non-nil, " is
+replaced by a double typographic quote.
+
 \f
 * Changes in Specialized Modes and Packages in Emacs 27.1
 
diff --git a/lisp/electric.el b/lisp/electric.el
index d7929945db..65e36b7a63 100644
--- a/lisp/electric.el
+++ b/lisp/electric.el
@@ -451,6 +451,14 @@ electric-quote-context-sensitive
   :version "26.1"
   :type 'boolean :safe #'booleanp :group 'electricity)
 
+(defcustom electric-quote-replace-double nil
+  "Non-nil means to replace \" with an electric double quote.
+Emacs replaces \" with an opening double quote after a line
+break, whitespace, opening parenthesis, or quote, and with a
+closing double quote otherwise."
+  :version "26.1"
+  :type 'boolean :safe #'booleanp :group 'electricity)
+
 (defvar electric-quote-inhibit-functions ()
   "List of functions that should inhibit electric quoting.
 When the variable `electric-quote-mode' is non-nil, Emacs will
@@ -467,7 +475,9 @@ electric-quote-post-self-insert-function
   (when (and electric-quote-mode
              (or (eq last-command-event ?\')
                  (and (not electric-quote-context-sensitive)
-                      (eq last-command-event ?\`)))
+                      (eq last-command-event ?\`))
+                 (and electric-quote-replace-double
+                      (eq last-command-event ?\")))
              (not (run-hook-with-args-until-success
                    'electric-quote-inhibit-functions))
              (if (derived-mode-p 'text-mode)
@@ -488,7 +498,8 @@ electric-quote-post-self-insert-function
        (save-excursion
          (let ((backtick ?\`))
            (if (or (eq last-command-event ?\`)
-                   (and electric-quote-context-sensitive
+                   (and (or electric-quote-context-sensitive
+                            electric-quote-replace-double)
                         (save-excursion
                           (backward-char)
                           (or (bobp) (bolp)
@@ -506,13 +517,19 @@ electric-quote-post-self-insert-function
                       (setq last-command-event q<<))
                      ((search-backward (string backtick) (1- (point)) t)
                       (replace-match (string q<))
-                      (setq last-command-event q<)))
+                      (setq last-command-event q<))
+                     ((search-backward "\"" (1- (point)) t)
+                      (replace-match (string q<<))
+                      (setq last-command-event q<<)))
              (cond ((search-backward (string q> ?') (- (point) 2) t)
                     (replace-match (string q>>))
                     (setq last-command-event q>>))
                    ((search-backward "'" (1- (point)) t)
                     (replace-match (string q>))
-                    (setq last-command-event q>))))))))))
+                    (setq last-command-event q>))
+                   ((search-backward "\"" (1- (point)) t)
+                    (replace-match (string q>>))
+                    (setq last-command-event q>>))))))))))
 
 (put 'electric-quote-post-self-insert-function 'priority 10)
 
diff --git a/test/lisp/electric-tests.el b/test/lisp/electric-tests.el
index fc69919fbe..7df2449b9e 100644
--- a/test/lisp/electric-tests.el
+++ b/test/lisp/electric-tests.el
@@ -617,6 +617,12 @@ electric-quote-closing-double
   :fixture-fn #'electric-quote-local-mode
   :test-in-comments nil :test-in-strings nil)
 
+(define-electric-pair-test electric-quote-replace-double-disabled
+  "" "\"" :expected-string "\"" :expected-point 2
+  :modes '(text-mode)
+  :fixture-fn #'electric-quote-local-mode
+  :test-in-comments nil :test-in-strings nil)
+
 (define-electric-pair-test electric-quote-context-sensitive-backtick
   "" "`" :expected-string "`" :expected-point 2
   :modes '(text-mode)
@@ -638,6 +644,13 @@ electric-quote-context-sensitive-bob-double
   :bindings '((electric-quote-context-sensitive . t))
   :test-in-comments nil :test-in-strings nil)
 
+(define-electric-pair-test electric-quote-replace-double-bob
+  "" "\"" :expected-string "“" :expected-point 2
+  :modes '(text-mode)
+  :fixture-fn #'electric-quote-local-mode
+  :bindings '((electric-quote-replace-double . t))
+  :test-in-comments nil :test-in-strings nil)
+
 (define-electric-pair-test electric-quote-context-sensitive-bol-single
   "a\n" "--'" :expected-string "a\n‘" :expected-point 4
   :modes '(text-mode)
@@ -652,6 +665,13 @@ electric-quote-context-sensitive-bol-double
   :bindings '((electric-quote-context-sensitive . t))
   :test-in-comments nil :test-in-strings nil)
 
+(define-electric-pair-test electric-quote-replace-double-bol
+  "a\n" "--\"" :expected-string "a\n“" :expected-point 4
+  :modes '(text-mode)
+  :fixture-fn #'electric-quote-local-mode
+  :bindings '((electric-quote-replace-double . t))
+  :test-in-comments nil :test-in-strings nil)
+
 (define-electric-pair-test electric-quote-context-sensitive-after-space-single
   " " "-'" :expected-string " ‘" :expected-point 3
   :modes '(text-mode)
@@ -666,6 +686,13 @@ electric-quote-context-sensitive-after-space-double
   :bindings '((electric-quote-context-sensitive . t))
   :test-in-comments nil :test-in-strings nil)
 
+(define-electric-pair-test electric-quote-replace-double-after-space
+  " " "-\"" :expected-string " “" :expected-point 3
+  :modes '(text-mode)
+  :fixture-fn #'electric-quote-local-mode
+  :bindings '((electric-quote-replace-double . t))
+  :test-in-comments nil :test-in-strings nil)
+
 (define-electric-pair-test electric-quote-context-sensitive-after-letter-single
   "a" "-'" :expected-string "a’" :expected-point 3
   :modes '(text-mode)
@@ -680,6 +707,13 @@ electric-quote-context-sensitive-after-letter-double
   :bindings '((electric-quote-context-sensitive . t))
   :test-in-comments nil :test-in-strings nil)
 
+(define-electric-pair-test electric-quote-replace-double-after-letter
+  "a" "-\"" :expected-string "a”" :expected-point 3
+  :modes '(text-mode)
+  :fixture-fn #'electric-quote-local-mode
+  :bindings '((electric-quote-replace-double . t))
+  :test-in-comments nil :test-in-strings nil)
+
 (define-electric-pair-test electric-quote-context-sensitive-after-paren-single
   "(" "-'" :expected-string "(‘" :expected-point 3
   :modes '(text-mode)
@@ -694,6 +728,13 @@ electric-quote-context-sensitive-after-paren-double
   :bindings '((electric-quote-context-sensitive . t))
   :test-in-comments nil :test-in-strings nil)
 
+(define-electric-pair-test electric-quote-replace-double-after-paren
+  "(" "-\"" :expected-string "(“" :expected-point 3
+  :modes '(text-mode)
+  :fixture-fn #'electric-quote-local-mode
+  :bindings '((electric-quote-replace-double . t))
+  :test-in-comments nil :test-in-strings nil)
+
 ;; Simulate ‘markdown-mode’: it sets both ‘comment-start’ and
 ;; ‘comment-use-syntax’, but derives from ‘text-mode’.
 (define-electric-pair-test electric-quote-markdown-in-text
-- 
2.14.1


  reply	other threads:[~2017-09-24  7:04 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-16 17:24 bug#24710: 26.0.50; Feature request: Replace double quotes in electric-quote-mode Philipp Stephani
2017-07-14 12:48 ` Paul Eggert
2017-07-23 20:01   ` Philipp Stephani
2017-07-24  7:55     ` Paul Eggert
2017-09-23 20:22       ` Philipp Stephani
2017-09-24  2:50         ` Eli Zaretskii
2017-09-24  5:03           ` Paul Eggert
2017-09-24  7:04             ` Philipp Stephani [this message]
2017-09-29  7:08               ` Eli Zaretskii
2017-09-30 22:21                 ` Philipp Stephani

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='CAArVCkS2zb3ahK14BwoEwn6cNeqeZ7_mCfQq6RgLD=mgvoLuAg@mail.gmail.com' \
    --to=p.stephani2@gmail.com \
    --cc=24710@debbugs.gnu.org \
    --cc=eggert@cs.ucla.edu \
    --cc=eliz@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.