From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Kangas Newsgroups: gmane.emacs.bugs Subject: bug#66155: 'electric-pair-inhibit-if-helps-balance' has side-effects Date: Sun, 1 Oct 2023 01:09:49 -0700 Message-ID: References: <878r8ye884.fsf@disroot.org> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22282"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Daniel Mendler , 66155@debbugs.gnu.org To: Akib Azmain Turja Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Oct 01 10:11:15 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qmrXm-0005Te-57 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 01 Oct 2023 10:11:14 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qmrXN-0008TU-1o; Sun, 01 Oct 2023 04:10:49 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qmrXK-0008TF-Eg for bug-gnu-emacs@gnu.org; Sun, 01 Oct 2023 04:10:47 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qmrXK-0007dW-3L for bug-gnu-emacs@gnu.org; Sun, 01 Oct 2023 04:10:46 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qmrXZ-0002RY-Tq for bug-gnu-emacs@gnu.org; Sun, 01 Oct 2023 04:11:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Kangas Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 01 Oct 2023 08:11:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66155 X-GNU-PR-Package: emacs Original-Received: via spool by 66155-submit@debbugs.gnu.org id=B66155.16961478149313 (code B ref 66155); Sun, 01 Oct 2023 08:11:01 +0000 Original-Received: (at 66155) by debbugs.gnu.org; 1 Oct 2023 08:10:14 +0000 Original-Received: from localhost ([127.0.0.1]:60456 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qmrWn-0002Q9-Lm for submit@debbugs.gnu.org; Sun, 01 Oct 2023 04:10:14 -0400 Original-Received: from mail-lf1-x132.google.com ([2a00:1450:4864:20::132]:56515) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qmrWl-0002Ps-Th for 66155@debbugs.gnu.org; Sun, 01 Oct 2023 04:10:12 -0400 Original-Received: by mail-lf1-x132.google.com with SMTP id 2adb3069b0e04-5041335fb9cso23971567e87.0 for <66155@debbugs.gnu.org>; Sun, 01 Oct 2023 01:09:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696147790; x=1696752590; darn=debbugs.gnu.org; h=cc:to:subject:message-id:date:mime-version:references:in-reply-to :from:from:to:cc:subject:date:message-id:reply-to; bh=yAAAJ9xOlM6ea37d+/ur1U2JdFB981GXSIwQBKeuRxk=; b=kNtQwt3as1PBd/wVPs4CjUqiqNhDfeB3Gygzt7H5bW0xXYmgD9BJ5R7ma4oK6NMtr2 lvVTzLmkn38ZqaWZT7hqzP1PL08crke2oMq5IirkyyjztGaIR+el6wrVTiE8jqrSvWjR 3iSjdGtszlbxJz0t2YzZx2wE8wGVk/zxeqI5+LKmgKkMV1WQslbnj+5xJuxIA7nw7jHB pJawsXPKm0ooHSLK2bAAUT04tiVdWqrP2cZJENF3J+HZLXRYTZTc6DQozbnFwMoLIddF CREltPWHGu6zCVDPO+nJH7Jvuky7Is6WGBkcBUZDUeic7CVZcBiOAhu84LF5S1YbM3Ot uoxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696147790; x=1696752590; h=cc:to:subject:message-id:date:mime-version:references:in-reply-to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yAAAJ9xOlM6ea37d+/ur1U2JdFB981GXSIwQBKeuRxk=; b=dbVrC6vl6igpMZLa6hGPIU+Iaj94XsaU5fKSsIZw6GNimRP7FyOgtiIJr3EPvDTr8o F/CMIPkWP7KqplIBjICozRhllLiXC0oYrlyWnrcVPBX9A4f97rbMte35fNMR8VPVOVtR 0U3HBekTE+d+mzCP5KtY74rGwmm91yu0PSCdakauMyo0Ly25mTp067Z+DAt8V/1SgL5T GB/mWdpSPS8IOzoCwXmrHSP/+llFgHnPaVQqdBBp3vItOKuxvKIIlkv9hY89KU6/mSlm slZzX6H150oIRbiukhOa00cuHurLOtJMf1Nw8WH/JPNCKgXPgy1O9of5eO3a+8tSBazA Ukww== X-Gm-Message-State: AOJu0Yyd0f8wCHKhr3bYbQnowS47tC48yTLWGtaLRSV1KJju1NhOCnAf fV6gdmQwPVpnwR9i68GTsWJ4cYybG5bl5lxFrNk4EHwW X-Google-Smtp-Source: AGHT+IHQBpSED6WwLlsfwI9p3oiJ6Zl42VntgRp8IkLCPvbVKnfZAu3pMxm0X88nhcftYZZj1ASB+x3TToJk7Px366E= X-Received: by 2002:ac2:4c4e:0:b0:503:3281:2ffd with SMTP id o14-20020ac24c4e000000b0050332812ffdmr9212059lfk.41.1696147790019; Sun, 01 Oct 2023 01:09:50 -0700 (PDT) Original-Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Sun, 1 Oct 2023 01:09:49 -0700 In-Reply-To: <878r8ye884.fsf@disroot.org> (Akib Azmain Turja's message of "Fri, 22 Sep 2023 17:51:55 +0600") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:271595 Archived-At: Akib Azmain Turja writes: > With the default configuration (which uses > 'electric-pair-inhibit-if-helps-balance'), inserting parens at the end > of a Tempel field doesn't extend the field. > > I think the modify+undo magic in electric-pair-inhibit-if-helps-balance > moves markers. > > The following is the solution that works for me atleast; it uses insert > to insert back the character, and let-bind buffer-undo-list to not > clobber the undo list. > > (defun *electric-pair-inhibit-if-helps-balance (char) > "Return non-nil if auto-pairing of CHAR would hurt parens' balance. > > Works by first removing the character from the buffer, then doing > some list calculations, finally restoring the situation as if nothing > happened." > (pcase (electric-pair-syntax-info char) > (`(,syntax ,pair ,_ ,s-or-c) > (let ((buffer-undo-list t)) > ;; Don't use `delete-char'; that may modify the head of the > ;; undo list. > (delete-region (point) (1- (point))) > (let ((ret > (cond > ((eq ?\( syntax) > (let* ((pair-data > (electric-pair--balance-info 1 s-or-c)) > (outermost (cdr pair-data))) > (cond ((car outermost) > nil) > (t > (eq (cdr outermost) pair))))) > ((eq syntax ?\") > (electric-pair--unbalanced-strings-p char))))) > (insert (string char)) > ret))))) Could you please send the patch as an attachment instead? We prefer that patches are created with a command like `git format-patch -1'. Please also include: - The bug number of this bug in the commit message, like so: Bug#66155 - A ChangeLog entry, as described in the file CONTRIBUTE. That would make it easier for us to review and hopefully install this patch. Thanks in advance.