diff options
| author | Paul Eggert | 2015-08-24 23:37:18 -0700 |
|---|---|---|
| committer | Paul Eggert | 2015-08-24 23:57:21 -0700 |
| commit | 68280c5ee9b87d874ffa7c111b3cac7e634cee22 (patch) | |
| tree | 955f3f692c7254074cac682c4e7e64b6f1361a35 /lisp | |
| parent | 0db4992d2778a2da4dee8ca07cde8c5e206f5250 (diff) | |
| download | emacs-68280c5ee9b87d874ffa7c111b3cac7e634cee22.tar.gz emacs-68280c5ee9b87d874ffa7c111b3cac7e634cee22.zip | |
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." | |||
| 453 | (save-excursion | 453 | (save-excursion |
| 454 | (if (eq last-command-event ?\`) | 454 | (if (eq last-command-event ?\`) |
| 455 | (cond ((and (electric--insertable-p "“") | 455 | (cond ((and (electric--insertable-p "“") |
| 456 | (re-search-backward "[`‘]`" (- (point) 2) t)) | 456 | (search-backward "‘`" (- (point) 2) t)) |
| 457 | (replace-match "“") | 457 | (replace-match "“") |
| 458 | (when (and electric-pair-mode | 458 | (when (and electric-pair-mode |
| 459 | (eq (cdr-safe | 459 | (eq (cdr-safe |
| @@ -465,19 +465,14 @@ This requotes when a quoting key is typed." | |||
| 465 | (search-backward "`" (1- (point)) t)) | 465 | (search-backward "`" (1- (point)) t)) |
| 466 | (replace-match "‘") | 466 | (replace-match "‘") |
| 467 | (setq last-command-event ?‘))) | 467 | (setq last-command-event ?‘))) |
| 468 | (let ((pos (point))) | 468 | (cond ((and (electric--insertable-p "”") |
| 469 | (if (memq (char-before (1- (point))) '(?\' ?’)) | 469 | (search-backward "’'" (- (point) 2) t)) |
| 470 | (when (and (search-backward "“" start t) | 470 | (replace-match "”") |
| 471 | (eq pos (re-search-forward | 471 | (setq last-command-event ?”)) |
| 472 | "“\\(\\([^‘”]\\|‘[^‘’”]*’\\)*\\)['’]'" | 472 | ((and (electric--insertable-p "’") |
| 473 | pos t))) | 473 | (search-backward "'" (1- (point)) t)) |
| 474 | (replace-match "“\\1”") | 474 | (replace-match "’") |
| 475 | (setq last-command-event ?”)) | 475 | (setq last-command-event ?’))))))))) |
| 476 | (when (and (search-backward "‘" start t) | ||
| 477 | (eq pos (re-search-forward | ||
| 478 | "‘\\([^’]*\\)'" pos t))) | ||
| 479 | (replace-match "‘\\1’") | ||
| 480 | (setq last-command-event ?’)))))))))) | ||
| 481 | 476 | ||
| 482 | (put 'electric-quote-post-self-insert-function 'priority 10) | 477 | (put 'electric-quote-post-self-insert-function 'priority 10) |
| 483 | 478 | ||
| @@ -488,11 +483,11 @@ With a prefix argument ARG, enable Electric Quote mode if | |||
| 488 | ARG is positive, and disable it otherwise. If called from Lisp, | 483 | ARG is positive, and disable it otherwise. If called from Lisp, |
| 489 | enable the mode if ARG is omitted or nil. | 484 | enable the mode if ARG is omitted or nil. |
| 490 | 485 | ||
| 491 | When enabled, this replaces \\=`foo bar' with \\=‘foo bar\\=’ and replaces | 486 | When enabled, as you type this replaces \\=` with \\=‘, \\=' with \\=’, |
| 492 | \\=`\\=`foo bar'' with “foo bar” as you type. This occurs only in | 487 | \\=`\\=` with “, and \\='\\=' with ”. This occurs only in comments, strings, |
| 493 | comments, strings, and text paragraphs, and these are selectively | 488 | and text paragraphs, and these are selectively controlled with |
| 494 | controlled with ‘electric-quote-comment’, | 489 | ‘electric-quote-comment’, ‘electric-quote-string’, and |
| 495 | ‘electric-quote-string’, and ‘electric-quote-paragraph’. | 490 | ‘electric-quote-paragraph’. |
| 496 | 491 | ||
| 497 | This is a global minor mode. To toggle the mode in a single buffer, | 492 | This is a global minor mode. To toggle the mode in a single buffer, |
| 498 | use ‘electric-quote-local-mode’." | 493 | use ‘electric-quote-local-mode’." |