From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Akib Azmain Turja via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#66155: 'electric-pair-inhibit-if-helps-balance' has side-effects Date: Fri, 22 Sep 2023 17:51:55 +0600 Message-ID: <878r8ye884.fsf@disroot.org> Reply-To: Akib Azmain Turja Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16555"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Daniel Mendler To: 66155@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Sep 22 13:53:13 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 1qjeie-00045b-JL for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 22 Sep 2023 13:53:13 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qjeiL-0003os-Pu; Fri, 22 Sep 2023 07:52:53 -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 1qjeiK-0003oe-1u for bug-gnu-emacs@gnu.org; Fri, 22 Sep 2023 07:52:52 -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 1qjeiJ-0001dO-K5 for bug-gnu-emacs@gnu.org; Fri, 22 Sep 2023 07:52:51 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qjeiT-0001MS-UJ for bug-gnu-emacs@gnu.org; Fri, 22 Sep 2023 07:53:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Akib Azmain Turja Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 22 Sep 2023 11:53:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 66155 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs Original-Received: via spool by submit@debbugs.gnu.org id=B.16953835715213 (code B ref -1); Fri, 22 Sep 2023 11:53:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 22 Sep 2023 11:52:51 +0000 Original-Received: from localhost ([127.0.0.1]:35455 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qjeiI-0001M1-Hc for submit@debbugs.gnu.org; Fri, 22 Sep 2023 07:52:50 -0400 Original-Received: from lists.gnu.org ([2001:470:142::17]:46494) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qjeiF-0001Ln-K6 for submit@debbugs.gnu.org; Fri, 22 Sep 2023 07:52:48 -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 1qjehz-0003kl-E7 for bug-gnu-emacs@gnu.org; Fri, 22 Sep 2023 07:52:31 -0400 Original-Received: from layka.disroot.org ([178.21.23.139]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qjehx-0001T5-Af for bug-gnu-emacs@gnu.org; Fri, 22 Sep 2023 07:52:31 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 76C42419F5; Fri, 22 Sep 2023 13:52:25 +0200 (CEST) X-Virus-Scanned: SPAM Filter at disroot.org Original-Received: from layka.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 44KvHDcsUNMB; Fri, 22 Sep 2023 13:52:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1695383544; bh=gMifL5b4EevuAmY8ABJkz5R4TWmyDsT4l82vF3T8Pb0=; h=From:To:Cc:Subject:Date; b=Qg2ijt1NI5UF/Km5CHIzOYUntdtD7vDw7Trd7X1Q3NTMyAkLozMCNZ0wceCOPvIRU LCl2PS7N1ewoSc2RFBd76t7VxnGRCKCNXV9iKHfUV7rsubiEnNoacgY9IPVDLg/fhL RWSkYl1drZrkn9wVmOw04lrbzRWOTiH1Y9hyfQMY8ph1qDJL8qcECTVI+DMWb/Fbjs cdnvbF6JRxYhs6d5why0JYbLnguA/SR11SqYcInD567mpX0wh8ryKQu7AVDz6v9VRK i48YyqAImLfV65F61ejhp05CPgg1+HsiHxLbw3PiDKs7ubXz6M5TwWACNWzNNAqzRY Id/JHiSywojwQ== Received-SPF: pass client-ip=178.21.23.139; envelope-from=akib@disroot.org; helo=layka.disroot.org X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:271075 Archived-At: --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable 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. =2D-8<---------------cut here---------------start------------->8--- (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))))) =2D-8<---------------cut here---------------end--------------->8--- =2D-=20 Akib Azmain Turja, GPG key: 70018CE5819F17A3BBA666AFE74F0EFA922AE7F5 Fediverse: akib@hostux.social Codeberg: akib emailselfdefense.fsf.org | "Nothing can be secure without encryption." --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEyVTKmrtL6kNBe3FRVTX89U2IYWsFAmUNf9wACgkQVTX89U2I YWtUBBAAq4tjyT8nLnQm5Pm8YYmplYCqQa1ByRGJP4WB2pwtlRqHwjIQo8N5rhoU RHL8UmdA9ofkEHs3trU95z45yLhQT7T6XbwOQlBJL/jc9qnFhcVAkm2VJbh2WKEC H2RsJN8ADYNv0MW1+a5b6RTH3c8oN9SQaMG+qeucysv5rqfkLDstOjeGwiKi9xhF NNIx9UBSNgh5Dga1Dpj+7TQEhZFOWRRj7UPlKUjk5Fh+PKYpiSrfYQb41WXkrpvT h3fQLqtDdjByoFAyLvFWqPc27BKzd87mc4271zwO1JLbjircvgf+ON1nRRsNB7Z7 n4rJPZKKgoCnypmdu3ZYbVzrNwtDmOPQbLdAzbkKC9I13GkO1k4mnrNknwXMOFrZ 6ID6eNMGcMzYb1C7i1lzI37YMi+FayQQCEo8qsDIZAWWCHzLyd+2upnVKlUTW5Oi Hptpwwf9hl3WGWjYLDHzEOQGABtiglqPnnSP71sSbRLt8G/++OQ9Ol1uh4kD/MQ/ XowuM5f0j9B1Q57+7eVSsKyeYsJsujZOTxUl4pAc7ZET7lAiew5SPXw56Y8o8c2y Ap19ue30AB9QuJR153uiE641ueEGWRcO3Jp6sjGNiabCz01a4HZxqdCu0AVE+vkd GD9krO6J56//Wumn5y0lxFy4OkEjCDkK5rpeahIcicMuzF1kTlc= =HRFU -----END PGP SIGNATURE----- --=-=-=--