emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r112208: * lisp/electric.el (electric


From: Stefan Monnier
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r112208: * lisp/electric.el (electric-pair-inhibit-predicate): New var.
Date: Mon, 01 Apr 2013 09:28:19 -0400
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 112208
fixes bug: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=14000
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Mon 2013-04-01 09:28:19 -0400
message:
  * 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.
modified:
  lisp/ChangeLog
  lisp/electric.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2013-04-01 07:58:04 +0000
+++ b/lisp/ChangeLog    2013-04-01 13:28:19 +0000
@@ -1,3 +1,10 @@
+2013-04-01  Stefan Monnier  <address@hidden>
+
+       * 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  <address@hidden>
 
        * emacs-lisp/crm.el (completing-read-multiple): Doc fix.

=== modified file 'lisp/electric.el'
--- a/lisp/electric.el  2013-01-01 09:11:05 +0000
+++ b/lisp/electric.el  2013-04-01 13:28:19 +0000
@@ -302,6 +302,26 @@
   :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 @@
      ;; 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 ()


reply via email to

[Prev in Thread] Current Thread [Next in Thread]