unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: Carsten Bormann <cabo@tzi.org>
Cc: 14000-done@debbugs.gnu.org
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	[thread overview]
Message-ID: <jwvvc86z8g6.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <EF5CEB5C-B604-487F-B776-2D2386C9042C@tzi.org> (Carsten Bormann's message of "Tue, 26 Mar 2013 08:27:31 +0100")

> 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 ()






      parent reply	other threads:[~2013-04-01 13:28 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-19 17:59 bug#14000: 24.3.50; electric-pair-post-self-insert-function does not handle nested parentheses Carsten Bormann
2013-03-26  2:41 ` Stefan Monnier
2013-03-26  7:27   ` Carsten Bormann
2013-03-26 13:18     ` bug#14000: 24.3.50; electric-pair-post-self-insert-function does not handle nestedparentheses Drew Adams
2013-03-26 13:32       ` Carsten Bormann
2013-03-26 14:20         ` Drew Adams
2013-03-26 16:48     ` bug#14000: 24.3.50; electric-pair-post-self-insert-function does not handle nested parentheses Stefan Monnier
2013-04-01 13:28     ` Stefan Monnier [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvvc86z8g6.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=14000-done@debbugs.gnu.org \
    --cc=cabo@tzi.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).