unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#24710: 26.0.50; Feature request: Replace double quotes in electric-quote-mode
@ 2016-10-16 17:24 Philipp Stephani
  2017-07-14 12:48 ` Paul Eggert
  0 siblings, 1 reply; 10+ messages in thread
From: Philipp Stephani @ 2016-10-16 17:24 UTC (permalink / raw)
  To: 24710


Currently electric-quote-mode only replaces ' and `.  I propose that
it also replace " with a left double quote after spaces, newlines, and
open parentheses, and with a right double quote after alphanumerics and
other punctuation.


In GNU Emacs 26.0.50.4 (x86_64-apple-darwin16.0.0, NS appkit-1504.00 Version 10.12 (Build 16A323))
 of 2016-10-16 built on p
Repository revision: cf566b46a6cf85c6d54d0b0db80e32ed6ae8d1ca
Windowing system distributor 'Apple', version 10.3.1504
Recent messages:
Mark set
Setting ‘send-mail-function’ temporarily since "emacs -q" would overwrite customizations
Sending...
Mark set [2 times]
Sending via mail...
Setting ‘smtpmail-smtp-server’ temporarily since "emacs -q" would overwrite customizations
Setting ‘smtpmail-smtp-service’ temporarily since "emacs -q" would overwrite customizations
Sending email 
Sending email done
Sending...done

Configured using:
 'configure --with-modules --enable-checking
 --enable-check-lisp-object-type --without-xml2'

Configured features:
RSVG IMAGEMAGICK DBUS NOTIFY ACL GNUTLS ZLIB TOOLKIT_SCROLL_BARS NS
MODULES

Important settings:
  value of $LANG: de_DE.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(network-stream nsm starttls tls gnutls mailalias smtpmail auth-source
cl-seq eieio eieio-core cl-macs eieio-loaddefs cus-edit cus-start
cus-load wid-edit pp shadow sort mail-extr emacsbug message subr-x puny
seq byte-opt gv bytecomp byte-compile cl-extra help-mode cconv
cl-loaddefs pcase cl-lib dired dired-loaddefs format-spec rfc822 mml
easymenu mml-sec password-cache epa derived epg epg-config gnus-util
rmail rmail-loaddefs mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums
mm-util mail-prsvr mail-utils time-date mule-util tooltip eldoc electric
uniquify ediff-hook vc-hooks lisp-float-type mwheel term/ns-win ns-win
ucs-normalize term/common-win tool-bar dnd fontset image regexp-opt
fringe tabulated-list newcomment elisp-mode lisp-mode prog-mode register
page menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock
font-lock syntax facemenu font-core term/tty-colors frame cl-generic
cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese charscript case-table epa-hook
jka-cmpr-hook help simple abbrev obarray minibuffer cl-preloaded nadvice
loaddefs button faces cus-face macroexp files text-properties overlay
sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote dbusbind kqueue cocoa ns multi-tty
make-network-process emacs)

Memory information:
((conses 16 235881 14695)
 (symbols 48 22643 6)
 (miscs 40 66 361)
 (strings 32 24312 6843)
 (string-bytes 1 751015)
 (vectors 16 37279)
 (vector-slots 8 708029 5877)
 (floats 8 225 337)
 (intervals 56 511 28)
 (buffers 976 15))





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

* bug#24710: 26.0.50; Feature request: Replace double quotes in electric-quote-mode
  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
  0 siblings, 1 reply; 10+ messages in thread
From: Paul Eggert @ 2017-07-14 12:48 UTC (permalink / raw)
  To: Philipp Stephani; +Cc: 24710

> Currently electric-quote-mode only replaces ' and `.  I propose that
> it also replace " with a left double quote after spaces, newlines, and
> open parentheses, and with a right double quote after alphanumerics and
> other punctuation.

This sounds reasonable, though I suppose it should be controlled by an option, 
since some people may prefer the current behavior where `` and '' are the only 
convenient ways to get curved double quotes.

Also, shouldn't it always replace " with a curved quote of one flavor of the 
other? I'm puzzled as to why one would want " to stay straight, when the option 
is enabled.





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

* bug#24710: 26.0.50; Feature request: Replace double quotes in electric-quote-mode
  2017-07-14 12:48 ` Paul Eggert
@ 2017-07-23 20:01   ` Philipp Stephani
  2017-07-24  7:55     ` Paul Eggert
  0 siblings, 1 reply; 10+ messages in thread
From: Philipp Stephani @ 2017-07-23 20:01 UTC (permalink / raw)
  To: Paul Eggert; +Cc: 24710


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

Paul Eggert <eggert@cs.ucla.edu> schrieb am Fr., 14. Juli 2017 um 14:49 Uhr:

> > Currently electric-quote-mode only replaces ' and `.  I propose that
> > it also replace " with a left double quote after spaces, newlines, and
> > open parentheses, and with a right double quote after alphanumerics and
> > other punctuation.
>
> This sounds reasonable, though I suppose it should be controlled by an
> option,
> since some people may prefer the current behavior where `` and '' are the
> only
> convenient ways to get curved double quotes.
>
> Also, shouldn't it always replace " with a curved quote of one flavor of
> the
> other? I'm puzzled as to why one would want " to stay straight, when the
> option
> is enabled.
>
>
>
OK, here's a patch.

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

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

From 905cb83dec024e9691ca888b006566c3b3042e72 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-enabled)
(electric-quote-context-sensitive-bob-replace-double)
(electric-quote-context-sensitive-bol-replace-double)
(electric-quote-context-sensitive-after-space-replace-double)
(electric-quote-context-sensitive-after-letter-replace-double)
(electric-quote-context-sensitive-after-paren-replace-double): New
unit tests.
---
 etc/NEWS                    |  5 ++++
 lisp/electric.el            | 24 ++++++++++++++++---
 test/lisp/electric-tests.el | 56 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 82 insertions(+), 3 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 4cb02bf518..25b9b7eb03 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -157,6 +157,11 @@ line, after a whitespace character, and after an opening parenthesis;
 and it will replace the apostrophe by a closing quote character in all
 other cases.
 
+** The new users option 'electric-quote-replace-double' controls
+whether a double quote is also replaced in 'electric-quote-mode'.  If
+non-nil, a double ASCII quote is replaced by a double typographic
+quote.
+
 ** The new variable 'electric-quote-inhibit-functions' controls when
 to disable electric quoting based on context.  Major modes can add
 functions to this list; Emacs will temporarily disable
diff --git a/lisp/electric.el b/lisp/electric.el
index a71e79ff78..0ad6b284e4 100644
--- a/lisp/electric.el
+++ b/lisp/electric.el
@@ -451,6 +451,16 @@ 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.
+If `electric-quote-context-sensitive' is nil, Emacs replaces \"
+with a closing double quote.  Otherwise, it 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 +477,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)
@@ -506,13 +518,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 c6ffccc079..5b4b98b802 100644
--- a/test/lisp/electric-tests.el
+++ b/test/lisp/electric-tests.el
@@ -617,6 +617,19 @@ 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-replace-double-enabled
+  "" "\"" :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-backtick
   "" "`" :expected-string "`" :expected-point 2
   :modes '(text-mode)
@@ -638,6 +651,14 @@ 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-context-sensitive-bob-replace-double
+  "" "\"" :expected-string "“" :expected-point 2
+  :modes '(text-mode)
+  :fixture-fn #'electric-quote-local-mode
+  :bindings '((electric-quote-context-sensitive . t)
+              (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 +673,14 @@ 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-context-sensitive-bol-replace-double
+  "a\n" "--\"" :expected-string "a\n“" :expected-point 4
+  :modes '(text-mode)
+  :fixture-fn #'electric-quote-local-mode
+  :bindings '((electric-quote-context-sensitive . t)
+              (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 +695,15 @@ 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-context-sensitive-after-space-replace-double
+  " " "-\"" :expected-string " “" :expected-point 3
+  :modes '(text-mode)
+  :fixture-fn #'electric-quote-local-mode
+  :bindings '((electric-quote-context-sensitive . t)
+              (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 +718,15 @@ 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-context-sensitive-after-letter-replace-double
+  "a" "-\"" :expected-string "a”" :expected-point 3
+  :modes '(text-mode)
+  :fixture-fn #'electric-quote-local-mode
+  :bindings '((electric-quote-context-sensitive . t)
+              (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 +741,15 @@ 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-context-sensitive-after-paren-replace-double
+  "(" "-\"" :expected-string "(“" :expected-point 3
+  :modes '(text-mode)
+  :fixture-fn #'electric-quote-local-mode
+  :bindings '((electric-quote-context-sensitive . t)
+              (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.13.3


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

* bug#24710: 26.0.50; Feature request: Replace double quotes in electric-quote-mode
  2017-07-23 20:01   ` Philipp Stephani
@ 2017-07-24  7:55     ` Paul Eggert
  2017-09-23 20:22       ` Philipp Stephani
  0 siblings, 1 reply; 10+ messages in thread
From: Paul Eggert @ 2017-07-24  7:55 UTC (permalink / raw)
  To: Philipp Stephani; +Cc: 24710

Philipp Stephani wrote:

> OK, here's a patch.

Thanks. I don’t see the point of the non-context-sensitive version. That is, if 
‘"’ is supposed to be replaced by a curved double-quote, then I don’t see the 
point of having a mode where ‘"’ is always replaced by closing double quote. 
That does not seem useful for English, anyway.

In the NEWS item, just say ‘"’ instead of ‘double quote’ or ‘double ASCII quote’.





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

* bug#24710: 26.0.50; Feature request: Replace double quotes in electric-quote-mode
  2017-07-24  7:55     ` Paul Eggert
@ 2017-09-23 20:22       ` Philipp Stephani
  2017-09-24  2:50         ` Eli Zaretskii
  0 siblings, 1 reply; 10+ messages in thread
From: Philipp Stephani @ 2017-09-23 20:22 UTC (permalink / raw)
  To: Paul Eggert; +Cc: 24710


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

Paul Eggert <eggert@cs.ucla.edu> schrieb am Mo., 24. Juli 2017 um 09:55 Uhr:

> Philipp Stephani wrote:
>
> > OK, here's a patch.
>
> Thanks. I don’t see the point of the non-context-sensitive version. That
> is, if
> ‘"’ is supposed to be replaced by a curved double-quote, then I don’t see
> the
> point of having a mode where ‘"’ is always replaced by closing double
> quote.
> That does not seem useful for English, anyway.
>
> In the NEWS item, just say ‘"’ instead of ‘double quote’ or ‘double ASCII
> quote’.
>

OK, here's an updated patch.

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

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

From 46ff297c6af561e1e8ed75163a3c0209cb06a54b 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.
---
 etc/NEWS                    |  4 ++++
 lisp/electric.el            | 25 +++++++++++++++++++++----
 test/lisp/electric-tests.el | 41 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 66 insertions(+), 4 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 0e62a2bbb4..bbaeb4570f 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -34,6 +34,10 @@ 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


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

* bug#24710: 26.0.50; Feature request: Replace double quotes in electric-quote-mode
  2017-09-23 20:22       ` Philipp Stephani
@ 2017-09-24  2:50         ` Eli Zaretskii
  2017-09-24  5:03           ` Paul Eggert
  0 siblings, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2017-09-24  2:50 UTC (permalink / raw)
  To: Philipp Stephani; +Cc: 24710, eggert

> From: Philipp Stephani <p.stephani2@gmail.com>
> Date: Sat, 23 Sep 2017 20:22:02 +0000
> Cc: 24710@debbugs.gnu.org
> 
>  In the NEWS item, just say ‘"’ instead of ‘double quote’ or ‘double ASCII quote’.
> 
> OK, here's an updated patch. 

Thanks.  How about updating the Emacs manual as well?





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

* bug#24710: 26.0.50; Feature request: Replace double quotes in electric-quote-mode
  2017-09-24  2:50         ` Eli Zaretskii
@ 2017-09-24  5:03           ` Paul Eggert
  2017-09-24  7:04             ` Philipp Stephani
  0 siblings, 1 reply; 10+ messages in thread
From: Paul Eggert @ 2017-09-24  5:03 UTC (permalink / raw)
  To: Eli Zaretskii, Philipp Stephani; +Cc: 24710

Eli Zaretskii wrote:
> Thanks.  How about updating the Emacs manual as well?

Yes, other than that it looks good to me.





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

* bug#24710: 26.0.50; Feature request: Replace double quotes in electric-quote-mode
  2017-09-24  5:03           ` Paul Eggert
@ 2017-09-24  7:04             ` Philipp Stephani
  2017-09-29  7:08               ` Eli Zaretskii
  0 siblings, 1 reply; 10+ messages in thread
From: Philipp Stephani @ 2017-09-24  7:04 UTC (permalink / raw)
  To: Paul Eggert, Eli Zaretskii; +Cc: 24710


[-- 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


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

* bug#24710: 26.0.50; Feature request: Replace double quotes in electric-quote-mode
  2017-09-24  7:04             ` Philipp Stephani
@ 2017-09-29  7:08               ` Eli Zaretskii
  2017-09-30 22:21                 ` Philipp Stephani
  0 siblings, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2017-09-29  7:08 UTC (permalink / raw)
  To: Philipp Stephani; +Cc: 24710, eggert

> From: Philipp Stephani <p.stephani2@gmail.com>
> Date: Sun, 24 Sep 2017 07:04:07 +0000
> Cc: 24710@debbugs.gnu.org
> 
>  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. 

Thanks, this LGTM.

> 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.

Please add the log entries for the documentation here, when you push.





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

* bug#24710: 26.0.50; Feature request: Replace double quotes in electric-quote-mode
  2017-09-29  7:08               ` Eli Zaretskii
@ 2017-09-30 22:21                 ` Philipp Stephani
  0 siblings, 0 replies; 10+ messages in thread
From: Philipp Stephani @ 2017-09-30 22:21 UTC (permalink / raw)
  To: Eli Zaretskii, 24710-done; +Cc: eggert

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

Eli Zaretskii <eliz@gnu.org> schrieb am Fr., 29. Sep. 2017 um 09:09 Uhr:

> > From: Philipp Stephani <p.stephani2@gmail.com>
> > Date: Sun, 24 Sep 2017 07:04:07 +0000
> > Cc: 24710@debbugs.gnu.org
> >
> >  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.
>
> Thanks, this LGTM.
>
> > 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.
>
> Please add the log entries for the documentation here, when you push.
>

Pushed as d247e1d30a to master.

[-- Attachment #2: Type: text/html, Size: 1584 bytes --]

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

end of thread, other threads:[~2017-09-30 22:21 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2017-09-29  7:08               ` Eli Zaretskii
2017-09-30 22:21                 ` Philipp Stephani

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).