summaryrefslogtreecommitdiff
path: root/lisp/electric.el
diff options
context:
space:
mode:
authorPhilipp Stephani <phst@google.com>2017-07-23 21:58:49 +0200
committerPhilipp Stephani <phst@google.com>2017-10-01 00:20:36 +0200
commitd247e1d30abcb77665f829ca98a5bdef69ff4bc3 (patch)
treedb9c7b1127eaa1860fbc586c8eace53ea4e3c4f2 /lisp/electric.el
parentd88a0f6554888643854ddb2c1f49b77b0bf8904c (diff)
downloademacs-d247e1d30abcb77665f829ca98a5bdef69ff4bc3.tar.gz
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. * test/lisp/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 (Quotation Marks): Document 'electric-quote-replace-double'.
Diffstat (limited to 'lisp/electric.el')
-rw-r--r--lisp/electric.el25
1 files changed, 21 insertions, 4 deletions
diff --git a/lisp/electric.el b/lisp/electric.el
index d7929945db2..65e36b7a63f 100644
--- a/lisp/electric.el
+++ b/lisp/electric.el
@@ -451,6 +451,14 @@ whitespace, opening parenthesis, or quote and leaves \\=` alone."
: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 @@ This requotes when a quoting key is typed."
(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 @@ This requotes when a quoting key is typed."
(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 @@ This requotes when a quoting key is typed."
(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)