aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2016-10-27 08:05:24 -0700
committerPaul Eggert2016-10-27 08:11:25 -0700
commit354c4a9885db314a4bd8a11cd6f11badef7b07f3 (patch)
tree6db18f4230c0fefa794f233678b8a46e5dad587d
parent11d380a029640eeb99badfa31976e9c47f53b002 (diff)
downloademacs-354c4a9885db314a4bd8a11cd6f11badef7b07f3.tar.gz
emacs-354c4a9885db314a4bd8a11cd6f11badef7b07f3.zip
electric-quote-chars fixups
* lisp/electric.el (electric-quote-chars): Check types and safety more carefully. (electric-quote-post-self-insert-function): Use more-mnemonic locals. Omit no-longer-necessary runtime error diagnostic.
-rw-r--r--lisp/electric.el43
1 files changed, 24 insertions, 19 deletions
diff --git a/lisp/electric.el b/lisp/electric.el
index 19cded25dfb..3e48737e3ac 100644
--- a/lisp/electric.el
+++ b/lisp/electric.el
@@ -427,10 +427,16 @@ The variable `electric-layout-rules' says when and how to insert newlines."
427 427
428(defcustom electric-quote-chars '(?‘ ?’ ?“ ?”) 428(defcustom electric-quote-chars '(?‘ ?’ ?“ ?”)
429 "Curved quote characters for `electric-quote-mode'. 429 "Curved quote characters for `electric-quote-mode'.
430The items correspond to the left single quote, the right single 430This list's members correspond to left single quote, right single
431quote, the left double quote, and the right double quote, respectively." 431quote, left double quote, and right double quote, respectively."
432 :version "25.1" 432 :version "26.1"
433 :type 'list :safe 'listp :group 'electricity) 433 :type '(list character character character character)
434 :safe #'(lambda (x)
435 (pcase x
436 (`(,(pred characterp) ,(pred characterp)
437 ,(pred characterp) ,(pred characterp))
438 t)))
439 :group 'electricity)
434 440
435(defcustom electric-quote-paragraph t 441(defcustom electric-quote-paragraph t
436 "Non-nil means to use electric quoting in text paragraphs." 442 "Non-nil means to use electric quoting in text paragraphs."
@@ -459,28 +465,27 @@ This requotes when a quoting key is typed."
459 (or (eq last-command-event ?\`) 465 (or (eq last-command-event ?\`)
460 (save-excursion (backward-paragraph) (point))))))) 466 (save-excursion (backward-paragraph) (point)))))))
461 (pcase electric-quote-chars 467 (pcase electric-quote-chars
462 (`(,q1 ,q2 ,q3 ,q4) 468 (`(,q< ,q> ,q<< ,q>>)
463 (when start 469 (when start
464 (save-excursion 470 (save-excursion
465 (if (eq last-command-event ?\`) 471 (if (eq last-command-event ?\`)
466 (cond ((search-backward (string q1 ?`) (- (point) 2) t) 472 (cond ((search-backward (string q< ?`) (- (point) 2) t)
467 (replace-match (string q3)) 473 (replace-match (string q<<))
468 (when (and electric-pair-mode 474 (when (and electric-pair-mode
469 (eq (cdr-safe 475 (eq (cdr-safe
470 (assq q1 electric-pair-text-pairs)) 476 (assq q< electric-pair-text-pairs))
471 (char-after))) 477 (char-after)))
472 (delete-char 1)) 478 (delete-char 1))
473 (setq last-command-event q3)) 479 (setq last-command-event q<<))
474 ((search-backward "`" (1- (point)) t) 480 ((search-backward "`" (1- (point)) t)
475 (replace-match (string q1)) 481 (replace-match (string q<))
476 (setq last-command-event q1))) 482 (setq last-command-event q<)))
477 (cond ((search-backward (string q2 ?') (- (point) 2) t) 483 (cond ((search-backward (string q> ?') (- (point) 2) t)
478 (replace-match (string q4)) 484 (replace-match (string q>>))
479 (setq last-command-event q4)) 485 (setq last-command-event q>>))
480 ((search-backward "'" (1- (point)) t) 486 ((search-backward "'" (1- (point)) t)
481 (replace-match (string q2)) 487 (replace-match (string q>))
482 (setq last-command-event q2))))))) 488 (setq last-command-event q>)))))))))))
483 (_ (error "‘electric-quote-chars’ must contain exactly 4 characters."))))))
484 489
485(put 'electric-quote-post-self-insert-function 'priority 10) 490(put 'electric-quote-post-self-insert-function 'priority 10)
486 491
@@ -497,8 +502,8 @@ and text paragraphs, and these are selectively controlled with
497`electric-quote-comment', `electric-quote-string', and 502`electric-quote-comment', `electric-quote-string', and
498`electric-quote-paragraph'. 503`electric-quote-paragraph'.
499 504
500Customize `electric-quote-chars' in order to use quote chars 505Customize `electric-quote-chars' to use characters other than the
501other than the ones listed here. 506ones listed here.
502 507
503This is a global minor mode. To toggle the mode in a single buffer, 508This is a global minor mode. To toggle the mode in a single buffer,
504use `electric-quote-local-mode'." 509use `electric-quote-local-mode'."