From: Philipp Stephani <p.stephani2@gmail.com>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: 24710@debbugs.gnu.org
Subject: bug#24710: 26.0.50; Feature request: Replace double quotes in electric-quote-mode
Date: Sun, 23 Jul 2017 20:01:05 +0000 [thread overview]
Message-ID: <CAArVCkQ3P8V5_y-TxsENY2U6Ltjjp+iwFZCK9EQEusFGqWKuWA@mail.gmail.com> (raw)
In-Reply-To: <4fc323e0-ed0a-cc36-08df-d337200d1549@cs.ucla.edu>
[-- 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
next prev parent reply other threads:[~2017-07-23 20:01 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 [this message]
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
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAArVCkQ3P8V5_y-TxsENY2U6Ltjjp+iwFZCK9EQEusFGqWKuWA@mail.gmail.com \
--to=p.stephani2@gmail.com \
--cc=24710@debbugs.gnu.org \
--cc=eggert@cs.ucla.edu \
/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 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).