From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stephen Berman via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#71337: 30.0.50; `electric-pair-mode' and custom keybinding Date: Mon, 03 Jun 2024 15:50:55 +0200 Message-ID: <87frtu9lts.fsf@gmx.net> References: Reply-To: Stephen Berman Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23803"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 71337@debbugs.gnu.org To: Arash Esbati Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jun 03 15:52:10 2024 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 1sE86b-0005yL-IO for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 03 Jun 2024 15:52:09 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sE86J-0005wC-Op; Mon, 03 Jun 2024 09:51:51 -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 1sE86H-0005vn-Kn for bug-gnu-emacs@gnu.org; Mon, 03 Jun 2024 09:51:49 -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 1sE86H-0005sU-Bx for bug-gnu-emacs@gnu.org; Mon, 03 Jun 2024 09:51:49 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sE86T-0004UI-Q3 for bug-gnu-emacs@gnu.org; Mon, 03 Jun 2024 09:52:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stephen Berman Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 03 Jun 2024 13:52:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 71337 X-GNU-PR-Package: emacs Original-Received: via spool by 71337-submit@debbugs.gnu.org id=B71337.171742267917202 (code B ref 71337); Mon, 03 Jun 2024 13:52:01 +0000 Original-Received: (at 71337) by debbugs.gnu.org; 3 Jun 2024 13:51:19 +0000 Original-Received: from localhost ([127.0.0.1]:40769 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sE85m-0004TN-F1 for submit@debbugs.gnu.org; Mon, 03 Jun 2024 09:51:19 -0400 Original-Received: from mout.gmx.net ([212.227.15.15]:38021) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sE85k-0004T8-6b for 71337@debbugs.gnu.org; Mon, 03 Jun 2024 09:51:17 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmx.net; s=s31663417; t=1717422656; x=1718027456; i=stephen.berman@gmx.net; bh=ZU4NPOUpZi+Q/rleARukM1HqqS+4ZEegvgural+/9FU=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References:Date: Message-ID:MIME-Version:Content-Type:cc:content-transfer-encoding: content-type:date:from:message-id:mime-version:reply-to:subject: to; b=sBtDBSBbUKh6OJZXvHsYgu63kmQoQhKiVcaIY8ZB78lUrzktqv7JDVq1XN+JeoDz Bt42x3zeLeZzc1EfR2J2h9Dv6z0lM7FxO4C6YAp4oo/t7oG7av3VxMCrWXvYN9C0+ mBTiXdOBz996rmg4/8gzOJSlGRfg3CFbo1g3GMRfNcAYbaO3gx+6fT4leh3usUy0p iHa0oQ4BOtD9T+zK9WC/KsP+9FJAAN2UkpeLnw7povrcvLGHFnmvpfSMGmuPkHfW6 BKFBFN2P5xug5SUC1WQxvBYtUVSYE5RKthvnseicrVcNXVYI2DUo9NiWkVJFtWRAO Tmj0SScs+Pe6tA1PdA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Original-Received: from strobelfs ([94.134.94.245]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1N63Vi-1sXlW4358C-016R7z; Mon, 03 Jun 2024 15:50:56 +0200 In-Reply-To: (Arash Esbati's message of "Mon, 03 Jun 2024 14:40:47 +0200") X-Provags-ID: V03:K1:LgeGexCAkSNzKOEDSnCLx5UOIZSjtoYUuPSpUE9RlHQRgigwVXP lWxZJxL7tqNqNTpFPyV8gHl/eOjFJEhALtsM6lWJDbs0aV+u/5QsT0cFtB2vCn7IQPbc8xL WJd6zo2vj7Sh3IG9WM4YOUdJ3ta2WCDHiDI05ZoWCgrZl7RfpS9dV8BkX19bWAbyTCwhehC 9aUZavcWlJhdRjpvOqWpw== UI-OutboundReport: notjunk:1;M01:P0:tsUVYm2moas=;FtjLwFbNBxkYRQHC1uAxCGeaEgG kYfezrbBdKwjBHt2W+Ub5sAPpS6h6srtxAL73qqkcC+XcrmnReQzwLvjhtZPXn075dZvF//hn d6z8A9N6Di5EnNomrnAAkzIGQBJ0WKga0lTuxQI4HX7/eNX2aKBdc680azZ1Z8hgr0zf9gOph bnUEOz8r7pv6/kPtDLqOwzNunIt1S1OwP0HOSkzo4PhZyEZKguiQzque6hjV2huXHdHr10+if sMgtlx45sSuJFe175+ZvDcKY1sTkg95Wo4fY3kntpUu7890aDEvsjZ16L/x3tGg4kgjvTqSQu +HaBpo1+Awpo/eiSUv8Pu+az+gm57J+0WA2qHMEkh99hTWZyoBKSX4RKNaAMMzNaJrRua6emb /WnogImWe5RVsfbkLBfSVNfrQyG0aEFeLShKHm21ibbMpecB/ByhXuOtqqsI5wHung8xmjj1L M/XEwFDeC9aROQ3XTMUgE2AC0iNXOP50ELEvOAzvko0obaq24AkugkL2jbWJ/4mGf9nXO+HOn wJ/Yx1XJ24qlDTNopPGPksEh/brxyczrlnj0P6Nd/ykuVLhmhYraCfRoroT/iAgR0ybBwkHMo T4mbjhm4S4JcgxaguYCBfj46FJ7scISmy3BgM8nxjsyhSukUY9iElBKuH6Zv8ZRxGYFlf7OjW p+q8LtwRGhmcJIJBWe2ZZoL8qwq/92FPDjUWpsS4Kv+2SsVqhOS/GJawgtEUxrKfZCJXY+ccJ +SztAn1GIiaA2VM4pZ51StDsFwlkV6NCV8qHDc5RBZHcetBm8PGXnpR1ZYCZzN58GXY8tze8 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:286443 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Mon, 03 Jun 2024 14:40:47 +0200 Arash Esbati wrote: > Hi all, > > I have a custom keybinding "s-=C3=9F" with my German keyboard, but the is= sue > I'm facing is also reproducible like this: > > =E2=80=A2 emacs -Q > =E2=80=A2 In scratch, eval: > > (progn > (setq debug-on-error t) > (electric-pair-mode 1) > (keymap-global-set "s-#" (lambda (arg) > "Insert ARG backslash(es)." > (interactive "*p") > (self-insert-command arg ?\\)))) > > =E2=80=A2 Now hit "s-#" and the debugger says (linebreaks added manually): > > Debugger entered--Lisp error: (wrong-type-argument characterp 8388643) > #f(compiled-function () #)() > electric-pair--with-syntax-1(nil #f(compiled-function () #)) > electric-pair-syntax-info(8388643) > electric-pair-post-self-insert-function() > self-insert-command(1 92) > #f(lambda (arg) [t] "Insert ARG backslash(es)." (interactive "*p") > (self-insert-command arg 92))(1) > funcall-interactively(#f(lambda (arg) [t] "Insert ARG backslash(es)." > (interactive "*p") (self-insert-command arg 92)) 1) > command-execute(#f(lambda (arg) [t] "Insert ARG backslash(es)." > (interactive "*p") (self-insert-command arg 92))) > > Running the exercise with (electric-pair-mode -1) doesn't throw an > error. If the pairing in electric-pair-mode should only be triggered by self-inserting characters (as the current code seems to require), then the attached patch appears to avoid the above problem. Steve Berman --=-=-= Content-Type: text/x-patch Content-Disposition: attachment Content-Description: electric-pair-post-self-insert-function patch Content-Transfer-Encoding: quoted-printable diff --git a/lisp/elec-pair.el b/lisp/elec-pair.el index 40618e9ef38..1b5b6d401a9 100644 =2D-- a/lisp/elec-pair.el +++ b/lisp/elec-pair.el @@ -528,71 +528,72 @@ electric-pair-post-self-insert-function and `electric-pair-skip-whitespace' (which see)." (let* ((pos (and electric-pair-mode (electric--after-char-pos))) (skip-whitespace-info)) - (pcase (electric-pair-syntax-info last-command-event) - (`(,syntax ,pair ,unconditional ,_) - (cond - ((null pos) nil) - ;; Wrap a pair around the active region. - ;; - ((and (memq syntax '(?\( ?\) ?\" ?\$)) (use-region-p)) - ;; FIXME: To do this right, we'd need a post-self-insert-functio= n - ;; so we could add-function around it and insert the closer afte= r - ;; all the rest of the hook has run. - (if (or (eq syntax ?\") - (and (eq syntax ?\)) - (>=3D (point) (mark))) - (and (not (eq syntax ?\))) - (>=3D (mark) (point)))) - (save-excursion - (goto-char (mark)) - (electric-pair--insert pair)) - (delete-region pos (1- pos)) - (electric-pair--insert pair) - (goto-char (mark)) - (electric-pair--insert last-command-event))) - ;; Backslash-escaped: no pairing, no skipping. - ((save-excursion - (goto-char (1- pos)) - (not (zerop (% (skip-syntax-backward "\\") 2)))) - nil) - ;; Skip self. - ((and (memq syntax '(?\) ?\" ?\$)) - (and (or unconditional - (if (functionp electric-pair-skip-self) - (electric-pair--save-literal-point-excursion - (goto-char pos) - (funcall electric-pair-skip-self last-comman= d-event)) - electric-pair-skip-self)) - (save-excursion - (when (and (not (and unconditional - (eq syntax ?\"))) - (setq skip-whitespace-info - (if (and (not (eq electric-pair-ski= p-whitespace 'chomp)) - (functionp electric-pair-s= kip-whitespace)) - (funcall electric-pair-skip-whi= tespace) - electric-pair-skip-whitespace))) - (funcall electric-pair-skip-whitespace-function)) - (eq (char-after) last-command-event)))) - ;; This is too late: rather than insert&delete we'd want to only - ;; skip (or insert in overwrite mode). The difference is in wha= t - ;; goes in the undo-log and in the intermediate state which migh= t - ;; be visible to other post-self-insert-hook. We'll just have t= o - ;; live with it for now. - (when skip-whitespace-info - (funcall electric-pair-skip-whitespace-function)) - (delete-region (1- pos) (if (eq skip-whitespace-info 'chomp) - (point) - pos)) - (forward-char)) - ;; Insert matching pair. - ((and (memq syntax '(?\( ?\" ?\$)) - (not overwrite-mode) - (or unconditional - (not (electric-pair--save-literal-point-excursion - (goto-char pos) - (funcall electric-pair-inhibit-predicate - last-command-event))))) - (save-excursion (electric-pair--insert pair)))))))) + (when (characterp last-command-event) + (pcase (electric-pair-syntax-info last-command-event) + (`(,syntax ,pair ,unconditional ,_) + (cond + ((null pos) nil) + ;; Wrap a pair around the active region. + ;; + ((and (memq syntax '(?\( ?\) ?\" ?\$)) (use-region-p)) + ;; FIXME: To do this right, we'd need a post-self-insert-funct= ion + ;; so we could add-function around it and insert the closer af= ter + ;; all the rest of the hook has run. + (if (or (eq syntax ?\") + (and (eq syntax ?\)) + (>=3D (point) (mark))) + (and (not (eq syntax ?\))) + (>=3D (mark) (point)))) + (save-excursion + (goto-char (mark)) + (electric-pair--insert pair)) + (delete-region pos (1- pos)) + (electric-pair--insert pair) + (goto-char (mark)) + (electric-pair--insert last-command-event))) + ;; Backslash-escaped: no pairing, no skipping. + ((save-excursion + (goto-char (1- pos)) + (not (zerop (% (skip-syntax-backward "\\") 2)))) + nil) + ;; Skip self. + ((and (memq syntax '(?\) ?\" ?\$)) + (and (or unconditional + (if (functionp electric-pair-skip-self) + (electric-pair--save-literal-point-excursion + (goto-char pos) + (funcall electric-pair-skip-self last-comma= nd-event)) + electric-pair-skip-self)) + (save-excursion + (when (and (not (and unconditional + (eq syntax ?\"))) + (setq skip-whitespace-info + (if (and (not (eq electric-pair-s= kip-whitespace 'chomp)) + (functionp electric-pair= -skip-whitespace)) + (funcall electric-pair-skip-w= hitespace) + electric-pair-skip-whitespace))= ) + (funcall electric-pair-skip-whitespace-function)= ) + (eq (char-after) last-command-event)))) + ;; This is too late: rather than insert&delete we'd want to on= ly + ;; skip (or insert in overwrite mode). The difference is in w= hat + ;; goes in the undo-log and in the intermediate state which mi= ght + ;; be visible to other post-self-insert-hook. We'll just have= to + ;; live with it for now. + (when skip-whitespace-info + (funcall electric-pair-skip-whitespace-function)) + (delete-region (1- pos) (if (eq skip-whitespace-info 'chomp) + (point) + pos)) + (forward-char)) + ;; Insert matching pair. + ((and (memq syntax '(?\( ?\" ?\$)) + (not overwrite-mode) + (or unconditional + (not (electric-pair--save-literal-point-excursion + (goto-char pos) + (funcall electric-pair-inhibit-predicate + last-command-event))))) + (save-excursion (electric-pair--insert pair))))))))) (defun electric-pair-open-newline-between-pairs-psif () "Honor `electric-pair-open-newline-between-pairs'. --=-=-=--