diff options
| author | Philipp Stephani | 2017-07-23 21:58:49 +0200 |
|---|---|---|
| committer | Philipp Stephani | 2017-10-01 00:20:36 +0200 |
| commit | d247e1d30abcb77665f829ca98a5bdef69ff4bc3 (patch) | |
| tree | db9c7b1127eaa1860fbc586c8eace53ea4e3c4f2 /lisp | |
| parent | d88a0f6554888643854ddb2c1f49b77b0bf8904c (diff) | |
| download | emacs-d247e1d30abcb77665f829ca98a5bdef69ff4bc3.tar.gz emacs-d247e1d30abcb77665f829ca98a5bdef69ff4bc3.zip | |
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')
| -rw-r--r-- | lisp/electric.el | 25 |
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." | |||
| 451 | :version "26.1" | 451 | :version "26.1" |
| 452 | :type 'boolean :safe #'booleanp :group 'electricity) | 452 | :type 'boolean :safe #'booleanp :group 'electricity) |
| 453 | 453 | ||
| 454 | (defcustom electric-quote-replace-double nil | ||
| 455 | "Non-nil means to replace \" with an electric double quote. | ||
| 456 | Emacs replaces \" with an opening double quote after a line | ||
| 457 | break, whitespace, opening parenthesis, or quote, and with a | ||
| 458 | closing double quote otherwise." | ||
| 459 | :version "26.1" | ||
| 460 | :type 'boolean :safe #'booleanp :group 'electricity) | ||
| 461 | |||
| 454 | (defvar electric-quote-inhibit-functions () | 462 | (defvar electric-quote-inhibit-functions () |
| 455 | "List of functions that should inhibit electric quoting. | 463 | "List of functions that should inhibit electric quoting. |
| 456 | When the variable `electric-quote-mode' is non-nil, Emacs will | 464 | When the variable `electric-quote-mode' is non-nil, Emacs will |
| @@ -467,7 +475,9 @@ This requotes when a quoting key is typed." | |||
| 467 | (when (and electric-quote-mode | 475 | (when (and electric-quote-mode |
| 468 | (or (eq last-command-event ?\') | 476 | (or (eq last-command-event ?\') |
| 469 | (and (not electric-quote-context-sensitive) | 477 | (and (not electric-quote-context-sensitive) |
| 470 | (eq last-command-event ?\`))) | 478 | (eq last-command-event ?\`)) |
| 479 | (and electric-quote-replace-double | ||
| 480 | (eq last-command-event ?\"))) | ||
| 471 | (not (run-hook-with-args-until-success | 481 | (not (run-hook-with-args-until-success |
| 472 | 'electric-quote-inhibit-functions)) | 482 | 'electric-quote-inhibit-functions)) |
| 473 | (if (derived-mode-p 'text-mode) | 483 | (if (derived-mode-p 'text-mode) |
| @@ -488,7 +498,8 @@ This requotes when a quoting key is typed." | |||
| 488 | (save-excursion | 498 | (save-excursion |
| 489 | (let ((backtick ?\`)) | 499 | (let ((backtick ?\`)) |
| 490 | (if (or (eq last-command-event ?\`) | 500 | (if (or (eq last-command-event ?\`) |
| 491 | (and electric-quote-context-sensitive | 501 | (and (or electric-quote-context-sensitive |
| 502 | electric-quote-replace-double) | ||
| 492 | (save-excursion | 503 | (save-excursion |
| 493 | (backward-char) | 504 | (backward-char) |
| 494 | (or (bobp) (bolp) | 505 | (or (bobp) (bolp) |
| @@ -506,13 +517,19 @@ This requotes when a quoting key is typed." | |||
| 506 | (setq last-command-event q<<)) | 517 | (setq last-command-event q<<)) |
| 507 | ((search-backward (string backtick) (1- (point)) t) | 518 | ((search-backward (string backtick) (1- (point)) t) |
| 508 | (replace-match (string q<)) | 519 | (replace-match (string q<)) |
| 509 | (setq last-command-event q<))) | 520 | (setq last-command-event q<)) |
| 521 | ((search-backward "\"" (1- (point)) t) | ||
| 522 | (replace-match (string q<<)) | ||
| 523 | (setq last-command-event q<<))) | ||
| 510 | (cond ((search-backward (string q> ?') (- (point) 2) t) | 524 | (cond ((search-backward (string q> ?') (- (point) 2) t) |
| 511 | (replace-match (string q>>)) | 525 | (replace-match (string q>>)) |
| 512 | (setq last-command-event q>>)) | 526 | (setq last-command-event q>>)) |
| 513 | ((search-backward "'" (1- (point)) t) | 527 | ((search-backward "'" (1- (point)) t) |
| 514 | (replace-match (string q>)) | 528 | (replace-match (string q>)) |
| 515 | (setq last-command-event q>)))))))))) | 529 | (setq last-command-event q>)) |
| 530 | ((search-backward "\"" (1- (point)) t) | ||
| 531 | (replace-match (string q>>)) | ||
| 532 | (setq last-command-event q>>)))))))))) | ||
| 516 | 533 | ||
| 517 | (put 'electric-quote-post-self-insert-function 'priority 10) | 534 | (put 'electric-quote-post-self-insert-function 'priority 10) |
| 518 | 535 | ||