diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2015-08-24 23:37:18 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2015-08-24 23:57:21 -0700 |
commit | 68280c5ee9b87d874ffa7c111b3cac7e634cee22 (patch) | |
tree | 955f3f692c7254074cac682c4e7e64b6f1361a35 /lisp | |
parent | 0db4992d2778a2da4dee8ca07cde8c5e206f5250 (diff) | |
download | emacs-68280c5ee9b87d874ffa7c111b3cac7e634cee22.tar.gz |
Treat ' like ’ even when not matching `
This is simpler and easier to explain, and should encourage better
typography. Do this in Electric Quote mode and when translating
quotes in docstrings. Inspired by a suggestion by Dmitry Gutov in:
https://lists.gnu.org/archive/html/emacs-devel/2015-08/msg00806.html
* doc/emacs/text.texi (Quotation Marks):
* doc/lispref/help.texi (Keys in Documentation):
* etc/NEWS:
Document this.
* lisp/electric.el (electric-quote-post-self-insert-function):
* src/doc.c (Fsubstitute_command_keys):
Always treat ' like ’ even when not matched by an open quote.
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/electric.el | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/lisp/electric.el b/lisp/electric.el index 8ca09316bcb..bef5bb9fec7 100644 --- a/lisp/electric.el +++ b/lisp/electric.el @@ -453,7 +453,7 @@ This requotes when a quoting key is typed." (save-excursion (if (eq last-command-event ?\`) (cond ((and (electric--insertable-p "“") - (re-search-backward "[`‘]`" (- (point) 2) t)) + (search-backward "‘`" (- (point) 2) t)) (replace-match "“") (when (and electric-pair-mode (eq (cdr-safe @@ -465,19 +465,14 @@ This requotes when a quoting key is typed." (search-backward "`" (1- (point)) t)) (replace-match "‘") (setq last-command-event ?‘))) - (let ((pos (point))) - (if (memq (char-before (1- (point))) '(?\' ?’)) - (when (and (search-backward "“" start t) - (eq pos (re-search-forward - "“\\(\\([^‘”]\\|‘[^‘’”]*’\\)*\\)['’]'" - pos t))) - (replace-match "“\\1”") - (setq last-command-event ?”)) - (when (and (search-backward "‘" start t) - (eq pos (re-search-forward - "‘\\([^’]*\\)'" pos t))) - (replace-match "‘\\1’") - (setq last-command-event ?’)))))))))) + (cond ((and (electric--insertable-p "”") + (search-backward "’'" (- (point) 2) t)) + (replace-match "”") + (setq last-command-event ?”)) + ((and (electric--insertable-p "’") + (search-backward "'" (1- (point)) t)) + (replace-match "’") + (setq last-command-event ?’))))))))) (put 'electric-quote-post-self-insert-function 'priority 10) @@ -488,11 +483,11 @@ With a prefix argument ARG, enable Electric Quote mode if ARG is positive, and disable it otherwise. If called from Lisp, enable the mode if ARG is omitted or nil. -When enabled, this replaces \\=`foo bar' with \\=‘foo bar\\=’ and replaces -\\=`\\=`foo bar'' with “foo bar” as you type. This occurs only in -comments, strings, and text paragraphs, and these are selectively -controlled with ‘electric-quote-comment’, -‘electric-quote-string’, and ‘electric-quote-paragraph’. +When enabled, as you type this replaces \\=` with \\=‘, \\=' with \\=’, +\\=`\\=` with “, and \\='\\=' with ”. This occurs only in comments, strings, +and text paragraphs, and these are selectively controlled with +‘electric-quote-comment’, ‘electric-quote-string’, and +‘electric-quote-paragraph’. This is a global minor mode. To toggle the mode in a single buffer, use ‘electric-quote-local-mode’." |