diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2013-04-01 09:28:19 -0400 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2013-04-01 09:28:19 -0400 |
commit | 15c579f08c3e298b1ab102a131456a0be7d7603f (patch) | |
tree | 58a47599c2fbce30ebe941ede3baca04439c150b /lisp | |
parent | 925d7ec008b91681033326a710c87be7c3da4625 (diff) | |
download | emacs-15c579f08c3e298b1ab102a131456a0be7d7603f.tar.gz |
* lisp/electric.el (electric-pair-inhibit-predicate): New var.
(electric-pair-post-self-insert-function): Use it.
(electric-pair-default-inhibit): New function, extracted from
electric-pair-post-self-insert-function.
Fixes: debbugs:14000
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/ChangeLog | 7 | ||||
-rw-r--r-- | lisp/electric.el | 27 |
2 files changed, 28 insertions, 6 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 1f7c2e4de83..b0df2f36d51 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,10 @@ +2013-04-01 Stefan Monnier <monnier@iro.umontreal.ca> + + * electric.el (electric-pair-inhibit-predicate): New var (bug#14000). + (electric-pair-post-self-insert-function): Use it. + (electric-pair-default-inhibit): New function, extracted from + electric-pair-post-self-insert-function. + 2013-03-31 Roland Winkler <winkler@gnu.org> * emacs-lisp/crm.el (completing-read-multiple): Doc fix. diff --git a/lisp/electric.el b/lisp/electric.el index 58b8e10cb71..7dab2da2b7d 100644 --- a/lisp/electric.el +++ b/lisp/electric.el @@ -302,6 +302,26 @@ This can be convenient for people who find it easier to hit ) than C-f." :version "24.1" :type 'boolean) +(defcustom electric-pair-inhibit-predicate + #'electric-pair-default-inhibit + "Predicate to prevent insertion of a matching pair. +The function is called with a single char (the opening char just inserted). +If it returns non-nil, then `electric-pair-mode' will not insert a matching +closer." + :type '(choice + (const :tag "Default" electric-pair-default-inhibit) + (const :tag "Always pair" ignore) + function)) + +(defun electric-pair-default-inhibit (char) + (or + ;; I find it more often preferable not to pair when the + ;; same char is next. + (eq char (char-after)) + (eq char (char-before (1- (point)))) + ;; I also find it often preferable not to pair next to a word. + (eq (char-syntax (following-char)) ?w))) + (defun electric-pair-syntax (command-event) (and electric-pair-mode (let ((x (assq command-event electric-pair-pairs))) @@ -351,12 +371,7 @@ This can be convenient for people who find it easier to hit ) than C-f." ;; Insert matching pair. ((not (or (not (memq syntax `(?\( ?\" ?\$))) overwrite-mode - ;; I find it more often preferable not to pair when the - ;; same char is next. - (eq last-command-event (char-after)) - (eq last-command-event (char-before (1- (point)))) - ;; I also find it often preferable not to pair next to a word. - (eq (char-syntax (following-char)) ?w))) + (funcall electric-pair-inhibit-predicate last-command-event))) (save-excursion (insert closer)))))) (defun electric-pair-will-use-region () |