From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs 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 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1364823029 12789 80.91.229.3 (1 Apr 2013 13:30:29 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 1 Apr 2013 13:30:29 +0000 (UTC) Cc: 14000-done@debbugs.gnu.org To: Carsten Bormann Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Apr 01 15:30:56 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UMep3-00056c-9e for geb-bug-gnu-emacs@m.gmane.org; Mon, 01 Apr 2013 15:30:53 +0200 Original-Received: from localhost ([::1]:47229 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMeoe-0008Ow-Ou for geb-bug-gnu-emacs@m.gmane.org; Mon, 01 Apr 2013 09:30:28 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:48822) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMeoZ-0008Oo-GP for bug-gnu-emacs@gnu.org; Mon, 01 Apr 2013 09:30:25 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UMeoR-0003Bd-DZ for bug-gnu-emacs@gnu.org; Mon, 01 Apr 2013 09:30:23 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:51602) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMeoR-0003BZ-9n for bug-gnu-emacs@gnu.org; Mon, 01 Apr 2013 09:30:15 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1UMerD-0003uv-7z for bug-gnu-emacs@gnu.org; Mon, 01 Apr 2013 09:33:07 -0400 Resent-From: Stefan Monnier Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: bug-gnu-emacs@gnu.org Resent-Date: Mon, 01 Apr 2013 13:33:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 14000 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Mail-Followup-To: 14000@debbugs.gnu.org, monnier@IRO.UMontreal.CA, cabo@tzi.org Original-Received: via spool by 14000-done@debbugs.gnu.org id=D14000.136482313714962 (code D ref 14000); Mon, 01 Apr 2013 13:33:03 +0000 Original-Received: (at 14000-done) by debbugs.gnu.org; 1 Apr 2013 13:32:17 +0000 Original-Received: from localhost ([127.0.0.1]:55708 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UMeqK-0003tD-Ie for submit@debbugs.gnu.org; Mon, 01 Apr 2013 09:32:13 -0400 Original-Received: from chene.dit.umontreal.ca ([132.204.246.20]:36885) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UMepz-0003se-EL for 14000-done@debbugs.gnu.org; Mon, 01 Apr 2013 09:32:04 -0400 Original-Received: from fmsmemgm.homelinux.net (lechon.iro.umontreal.ca [132.204.27.242]) by chene.dit.umontreal.ca (8.14.1/8.14.1) with ESMTP id r31DSuWa012886; Mon, 1 Apr 2013 09:28:57 -0400 Original-Received: by fmsmemgm.homelinux.net (Postfix, from userid 20848) id A2D0FAE334; Mon, 1 Apr 2013 09:28:56 -0400 (EDT) In-Reply-To: (Carsten Bormann's message of "Tue, 26 Mar 2013 08:27:31 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-NAI-Spam-Flag: NO X-NAI-Spam-Threshold: 5 X-NAI-Spam-Score: 0 X-NAI-Spam-Rules: 1 Rules triggered RV4535=0 X-NAI-Spam-Version: 2.3.0.9362 : core <4535> : streams <931938> : uri <1381536> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:73065 Archived-At: > 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 ()