bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#14000: 24.3.50; electric-pair-post-self-insert-function does not han


From: Stefan Monnier
Subject: bug#14000: 24.3.50; electric-pair-post-self-insert-function does not handle nested parentheses
Date: Mon, 01 Apr 2013 09:28:56 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

> OK, I maybe should have suggested adding a preference.
> But if you live in a world of paired parentheses (and I thought
> Emacs-Lispers were!) you want to add them in pairs, always.

I installed the patch below,


        Stefan


=== modified file 'lisp/electric.el'
--- lisp/electric.el    2013-01-01 09:11:05 +0000
+++ lisp/electric.el    2013-04-01 13:27:16 +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]