From debbugs-submit-bounces@debbugs.gnu.org Sat Aug 03 03:13:05 2024 Received: (at submit) by debbugs.gnu.org; 3 Aug 2024 07:13:05 +0000 Received: from localhost ([127.0.0.1]:54017 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sa8wr-0003iu-0Z for submit@debbugs.gnu.org; Sat, 03 Aug 2024 03:13:05 -0400 Received: from lists.gnu.org ([209.51.188.17]:43132) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sa8wm-0003iT-Li for submit@debbugs.gnu.org; Sat, 03 Aug 2024 03:13:03 -0400 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 1sa8wT-0006z5-31 for bug-gnu-emacs@gnu.org; Sat, 03 Aug 2024 03:12:41 -0400 Received: from out-185.mta0.migadu.com ([91.218.175.185]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sa8wR-0001vg-Gl for bug-gnu-emacs@gnu.org; Sat, 03 Aug 2024 03:12:40 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=breatheoutbreathe.in; s=key1; t=1722669157; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=EFtWRyxE9YUKFnuZRIEhNoZShIlnKKcV5sfJegPHGf4=; b=nXrxRgtTtNYHKNh+wZ8Ussrp0UDXUU3OyCBAZYfVggK9sxQeZshMlLo63WuklRr4+nHT/I u8gSdFu8Zb75rsluXt1mJPiwOm6apLpLtPeUXBbUea8Omz97bSqeycRlEFs6AqzIkL3PXa IWtgJFya9W0rUYvp9cP4VYoI4TwNPTU= From: Joseph Turner To: bug-gnu-emacs@gnu.org Subject: Unexpected behavior when inserting with prefix arg in electric-pair-mode X-Debbugs-Cc: eliz@gnu.org Date: Sat, 03 Aug 2024 00:12:33 -0700 Message-ID: <87le1edqqm.fsf@breatheoutbreathe.in> MIME-Version: 1.0 Content-Type: text/plain X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=91.218.175.185; envelope-from=joseph@breatheoutbreathe.in; helo=out-185.mta0.migadu.com 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, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.4 (-) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.4 (--) Migrated from this thread on the devel mailing list: https://yhetil.org/emacs-devel/86ikwiumza.fsf@gnu.org/T/#t On Emacs 29.4, with emacs -Q Turn on electric-pair-mode (electric-pair-mode +1) Then press "C-2 (" Expected result: Either (()) or ()() Actual result: (() I noticed the unexpected behavior when attempting to surround some text with multiple braces in order to create Anki flashcards. More or less, I wanted to go from "foo" to "{{foo}}", and I thought perhaps that with the whole word selected, pressing "C-2 {" would DTRT. In general, I'm not sure whether "{}{}" or "{{}}"is more useful or expected, but I suspect both are better than "{{}". Thank you! Joseph From debbugs-submit-bounces@debbugs.gnu.org Sat Aug 03 05:12:40 2024 Received: (at 72437) by debbugs.gnu.org; 3 Aug 2024 09:12:40 +0000 Received: from localhost ([127.0.0.1]:54078 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1saAoZ-0006qC-MP for submit@debbugs.gnu.org; Sat, 03 Aug 2024 05:12:40 -0400 Received: from eggs.gnu.org ([209.51.188.92]:36264) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1saAoW-0006px-59 for 72437@debbugs.gnu.org; Sat, 03 Aug 2024 05:12:37 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1saAo6-0002EU-Sr; Sat, 03 Aug 2024 05:12:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=MDAjoUKdz9k5FARzGIFs22rLS32Nu2Non5O0GlrJcX4=; b=CIQXcDzvf1ss vnQPwU/VnGZunyE6OGY9+Z505HXlPJeJm4BHrloeEk7TpUN5iX5WlqY66LhylgIS0yV5AzpWz44wk /mekndjO2KDeuAZ440+f8XE2YSXOwEphR+YmbEN4gD6tEcxWSwYhvsW4TGkN2Rw+QyGnzVPZZLbcW U3SsX//+sB4pkOABriuqAZHqmMRBkmrLrLVRV1kaoW9YTuIJWg6KVPfwQ2JbCnQ29EKWOCCZhH2BN NrLcLp3jIshJV3rKIZffMTGOhqiDuri8AYP7E4c/1CvpHiyi8cV2FZIHKOSeVAovmE+SLaAJ6bcU/ mRAzBJs88gboj89HW+E93w==; Date: Sat, 03 Aug 2024 12:12:06 +0300 Message-Id: <86h6c2ug0p.fsf@gnu.org> From: Eli Zaretskii To: Joseph Turner , Stefan Monnier In-Reply-To: <87le1edqqm.fsf@breatheoutbreathe.in> (message from Joseph Turner on Sat, 03 Aug 2024 00:12:33 -0700) Subject: Re: bug#72437: Unexpected behavior when inserting with prefix arg in electric-pair-mode References: <87le1edqqm.fsf@breatheoutbreathe.in> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 72437 Cc: 72437@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > Cc: eliz@gnu.org > From: Joseph Turner > Date: Sat, 03 Aug 2024 00:12:33 -0700 > > Migrated from this thread on the devel mailing list: > > https://yhetil.org/emacs-devel/86ikwiumza.fsf@gnu.org/T/#t > > > On Emacs 29.4, with emacs -Q > > Turn on electric-pair-mode > > (electric-pair-mode +1) > > Then press "C-2 (" > > Expected result: > > Either (()) or ()() > > Actual result: > > (() > > > I noticed the unexpected behavior when attempting to surround some text > with multiple braces in order to create Anki flashcards. > > More or less, I wanted to go from "foo" to "{{foo}}", and I thought > perhaps that with the whole word selected, pressing "C-2 {" would DTRT. > > In general, I'm not sure whether "{}{}" or "{{}}"is more useful or > expected, but I suspect both are better than "{{}". Making it produce "{}{}" is relatively easy: we just need to call the post-self-insert-hook for each of the ARG inserted characters. OTOH, to produce "{{}}" we'd probably need to rewrite the electric-pair-mode's hook function, but I have no idea how to rewrite it to do that. Stefan, any suggestions? From debbugs-submit-bounces@debbugs.gnu.org Sat Aug 03 07:05:25 2024 Received: (at 72437) by debbugs.gnu.org; 3 Aug 2024 11:05:26 +0000 Received: from localhost ([127.0.0.1]:54123 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1saCZh-0001Jx-A1 for submit@debbugs.gnu.org; Sat, 03 Aug 2024 07:05:25 -0400 Received: from mail.eshelyaron.com ([107.175.124.16]:40784 helo=eshelyaron.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1saCZd-0001Jo-Ng for 72437@debbugs.gnu.org; Sat, 03 Aug 2024 07:05:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eshelyaron.com; s=mail; t=1722683101; bh=GBoOm2QGLfYOZDq7ccKxIRUjqXrcGJFKcekUXvifFr4=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=m1T24mT08z6JWk4CjDlETx+3cbE6hUhEQygFpe47MiMrklLXm0wlelvaMVmEFmCQd 2x8Ot7zXm7WdHcm+x1vwiOvJrup1LAHI094MlvebTtuRLI0H/nS8ZGlK//FhKhWilr Qzz0hILFZDEptnrwY9EjiZZ+CjTfb3IUxDs0IirB5w27/PwLHRUturjukss0O51j7z CJmWKsVZM8roBV65cU3FOj0x03IKt5vQUX++lmo+Psv5DaMG/kdSKsH/GH1F28LLCy 1IydnZdXbZF019HCzP1PrIxW2tyxmde8fbuRuq7gkB9Fvy1K4Xfgnrd0s5toV5pb9B VqBu0f0xgGZ5Q== From: Eshel Yaron To: Eli Zaretskii Subject: Re: bug#72437: Unexpected behavior when inserting with prefix arg in electric-pair-mode In-Reply-To: <86h6c2ug0p.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 03 Aug 2024 12:12:06 +0300") References: <87le1edqqm.fsf@breatheoutbreathe.in> <86h6c2ug0p.fsf@gnu.org> Date: Sat, 03 Aug 2024 13:04:58 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 72437 Cc: 72437@debbugs.gnu.org, Stefan Monnier , Joseph Turner X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Eli Zaretskii writes: >> Cc: eliz@gnu.org >> From: Joseph Turner >> Date: Sat, 03 Aug 2024 00:12:33 -0700 >> >> Migrated from this thread on the devel mailing list: >> >> https://yhetil.org/emacs-devel/86ikwiumza.fsf@gnu.org/T/#t >> >> >> On Emacs 29.4, with emacs -Q >> >> Turn on electric-pair-mode >> >> (electric-pair-mode +1) >> >> Then press "C-2 (" >> >> Expected result: >> >> Either (()) or ()() >> >> Actual result: >> >> (() >> >> >> I noticed the unexpected behavior when attempting to surround some text >> with multiple braces in order to create Anki flashcards. >> >> More or less, I wanted to go from "foo" to "{{foo}}", and I thought >> perhaps that with the whole word selected, pressing "C-2 {" would DTRT. >> >> In general, I'm not sure whether "{}{}" or "{{}}"is more useful or >> expected, but I suspect both are better than "{{}". > > Making it produce "{}{}" is relatively easy: we just need to call the > post-self-insert-hook for each of the ARG inserted characters. OTOH, > to produce "{{}}" we'd probably need to rewrite the > electric-pair-mode's hook function, but I have no idea how to rewrite > it to do that. > > Stefan, any suggestions? I'm no Stefan, but I took a quick stab at it. The following diff teaches electric-pair-mode about numeric prefix arguments: diff --git a/lisp/elec-pair.el b/lisp/elec-pair.el index 40618e9ef38..1fae0ba6ba4 100644 --- a/lisp/elec-pair.el +++ b/lisp/elec-pair.el @@ -260,7 +260,7 @@ electric-pair-syntax-info (list ?\( (cdr direct) t string-or-comment))) (reverse (list ?\) (car reverse) t string-or-comment))))) -(defun electric-pair--insert (char) +(defun electric-pair--insert (char times) (let ((last-command-event char) (blink-matching-paren nil) (electric-pair-mode nil) @@ -271,7 +271,7 @@ electric-pair--insert ;; us to add these newlines, and is probably about to kick in ;; again after we add the closer. (electric-layout-allow-duplicate-newlines t)) - (self-insert-command 1))) + (self-insert-command times))) (defun electric-pair--syntax-ppss (&optional pos where) "Like `syntax-ppss', but sometimes fallback to `parse-partial-sexp'. @@ -455,7 +455,8 @@ electric-pair-inhibit-if-helps-balance (atomic-change-group ;; Don't use `delete-char'; that may modify the head of the ;; undo list. - (delete-region (point) (1- (point))) + (delete-region (- (point) (prefix-numeric-value current-prefix-arg)) + (point)) (throw 'done (cond ((eq ?\( syntax) @@ -474,25 +475,26 @@ electric-pair-skip-if-helps-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) - (unwind-protect - (progn - (delete-char -1) - (cond ((eq syntax ?\)) - (let* ((pair-data - (electric-pair--balance-info - -1 s-or-c)) - (innermost (car pair-data)) - (outermost (cdr pair-data))) - (and - (cond ((car outermost) - (car innermost)) - ((car innermost) - (not (eq (cdr outermost) pair))))))) - ((eq syntax ?\") - (electric-pair--inside-string-p char)))) - (insert char))))) + (let ((num (prefix-numeric-value current-prefix-arg))) + (pcase (electric-pair-syntax-info char) + (`(,syntax ,pair ,_ ,s-or-c) + (unwind-protect + (progn + (delete-char (- num)) + (cond ((eq syntax ?\)) + (let* ((pair-data + (electric-pair--balance-info + (- num) s-or-c)) + (innermost (car pair-data)) + (outermost (cdr pair-data))) + (and + (cond ((car outermost) + (car innermost)) + ((car innermost) + (not (eq (cdr outermost) pair))))))) + ((eq syntax ?\") + (electric-pair--inside-string-p char)))) + (insert (make-string num char))))))) (defun electric-pair-default-skip-self (char) (if electric-pair-preserve-balance @@ -527,11 +529,14 @@ electric-pair-post-self-insert-function `electric-pair-inhibit-predicate', `electric-pair-skip-self' and `electric-pair-skip-whitespace' (which see)." (let* ((pos (and electric-pair-mode (electric--after-char-pos))) + (num (when pos (prefix-numeric-value current-prefix-arg))) + (beg (when num (- pos num))) (skip-whitespace-info)) (pcase (electric-pair-syntax-info last-command-event) (`(,syntax ,pair ,unconditional ,_) (cond ((null pos) nil) + ((zerop num) nil) ;; Wrap a pair around the active region. ;; ((and (memq syntax '(?\( ?\) ?\" ?\$)) (use-region-p)) @@ -545,23 +550,24 @@ electric-pair-post-self-insert-function (>= (mark) (point)))) (save-excursion (goto-char (mark)) - (electric-pair--insert pair)) - (delete-region pos (1- pos)) - (electric-pair--insert pair) + (electric-pair--insert pair num)) + (delete-region beg pos) + (electric-pair--insert pair num) (goto-char (mark)) - (electric-pair--insert last-command-event))) + (electric-pair--insert last-command-event num))) ;; Backslash-escaped: no pairing, no skipping. ((save-excursion - (goto-char (1- pos)) + (goto-char beg) (not (zerop (% (skip-syntax-backward "\\") 2)))) - nil) + (let ((current-prefix-arg (1- num))) + (electric-pair-post-self-insert-function))) ;; 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-command-event)) + (goto-char pos) + (funcall electric-pair-skip-self last-command-event)) electric-pair-skip-self)) (save-excursion (when (and (not (and unconditional @@ -580,19 +586,19 @@ electric-pair-post-self-insert-function ;; 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)) + (delete-region beg (if (eq skip-whitespace-info 'chomp) + (point) + pos)) + (forward-char num)) ;; 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)))))))) + (goto-char pos) + (funcall electric-pair-inhibit-predicate + last-command-event))))) + (save-excursion (electric-pair--insert pair num)))))))) (defun electric-pair-open-newline-between-pairs-psif () "Honor `electric-pair-open-newline-between-pairs'. @@ -604,7 +610,8 @@ electric-pair-open-newline-between-pairs-psif (< (1+ (point-min)) (point) (point-max)) (eq (save-excursion (skip-chars-backward "\t\s") - (char-before (1- (point)))) + (char-before (- (point) + (prefix-numeric-value current-prefix-arg)))) (matching-paren (char-after)))) (save-excursion (newline 1 t)))) @@ -618,7 +625,7 @@ electric-pair-delete-pair ARG and KILLP are passed directly to `backward-delete-char-untabify', which see." (interactive "*p\nP") - (delete-char 1) + (delete-char arg) (backward-delete-char-untabify arg killp)) (defvar electric-pair-mode-map From debbugs-submit-bounces@debbugs.gnu.org Sat Aug 03 11:41:10 2024 Received: (at 72437) by debbugs.gnu.org; 3 Aug 2024 15:41:10 +0000 Received: from localhost ([127.0.0.1]:54706 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1saGsY-00006e-BO for submit@debbugs.gnu.org; Sat, 03 Aug 2024 11:41:10 -0400 Received: from eggs.gnu.org ([209.51.188.92]:55536) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1saGsV-00006O-4s for 72437@debbugs.gnu.org; Sat, 03 Aug 2024 11:41:08 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1saGs5-0002BU-7L; Sat, 03 Aug 2024 11:40:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=xApMHYpTPtx6PMb1G9AvOwnirLnvxdVx0yPuI6YytNA=; b=BxMHuJCXmFvY 2o5vxQGzYTk1Y4+wExwaTyt0N00x+d8AbnPVm609delBS/Hbp8vX55ELhV9Yfla1iVGQpBWKcCx1Z aOMpO/oXTqUvJhEL1lVvJau/ylpAOmXTKyy+wFz4bpgnEmy8guUGLwxJtpiwU+lKE5Rn7TgwKhapp 2kPK5IXQ+tQ2NC3p7ettKqcCduEThYJ44bJzb4m8FnyPVohJmCv0ktqCDcHAfbVvP2lMOZD4a/15w YGm0wYh9G9Cry2wH2gpWsMDN1N5jXO2h2sD5hWg5l3HfT9epky7krTR7TbCWhgFhjPCjNd5WuDXBX GQ2ZC79uQV3xbXu/QLKaPA==; Date: Sat, 03 Aug 2024 18:40:37 +0300 Message-Id: <86a5htvclm.fsf@gnu.org> From: Eli Zaretskii To: Eshel Yaron In-Reply-To: (message from Eshel Yaron on Sat, 03 Aug 2024 13:04:58 +0200) Subject: Re: bug#72437: Unexpected behavior when inserting with prefix arg in electric-pair-mode References: <87le1edqqm.fsf@breatheoutbreathe.in> <86h6c2ug0p.fsf@gnu.org> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 72437 Cc: 72437@debbugs.gnu.org, monnier@iro.umontreal.ca, joseph@breatheoutbreathe.in X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Eshel Yaron > Cc: Joseph Turner , Stefan Monnier > , 72437@debbugs.gnu.org > Date: Sat, 03 Aug 2024 13:04:58 +0200 > > Eli Zaretskii writes: > > > post-self-insert-hook for each of the ARG inserted characters. OTOH, > > to produce "{{}}" we'd probably need to rewrite the > > electric-pair-mode's hook function, but I have no idea how to rewrite > > it to do that. > > > > Stefan, any suggestions? > > I'm no Stefan, but I took a quick stab at it. The following diff > teaches electric-pair-mode about numeric prefix arguments: Thanks, but isn't it cleaner if we simply call the hook from cmds.c the same number of times as we insert a character? From debbugs-submit-bounces@debbugs.gnu.org Sat Aug 03 14:18:34 2024 Received: (at 72437) by debbugs.gnu.org; 3 Aug 2024 18:18:34 +0000 Received: from localhost ([127.0.0.1]:54779 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1saJKr-0007Lg-Q0 for submit@debbugs.gnu.org; Sat, 03 Aug 2024 14:18:34 -0400 Received: from mail.eshelyaron.com ([107.175.124.16]:48274 helo=eshelyaron.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1saJKo-0007LL-1C for 72437@debbugs.gnu.org; Sat, 03 Aug 2024 14:18:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eshelyaron.com; s=mail; t=1722709089; bh=LwlKPkBzqqhFHHYjjGUWMM+/b35JW1KSw7Mfr5wdAI0=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=k0NpXtJxv/Qg9Ktd/tsd0Aew8l+32YblVMZjtJuJSllOne8pvHxxqCAanQUtzIGwf ybMRovhrxAtI5OqN2cUJXkMYS4KnX7Xv5g7LU+b+nNAmOtJWwA51EkwypxYbjdfFgX yc1kkyz08ov1kKuuI5RjvMh7nJgdmw6E9k8x5jIYGtzvmHeng+kCs4N9+Cqa1RKfvE 3/ZTsi1hNumw5UbHDZAoiqB6FEpxI4F/XCWZidAnMXZYqMMFuDXEkem8+OdzYfbWey xTtP0Lp8vPygFGS+tfk/Q3sDLblfq+1qOXmpH6XJSLxC49AaRKOIBDdJXmjEziJd2u rtg1jFBy6ByBQ== From: Eshel Yaron To: Eli Zaretskii Subject: Re: bug#72437: Unexpected behavior when inserting with prefix arg in electric-pair-mode In-Reply-To: <86a5htvclm.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 03 Aug 2024 18:40:37 +0300") References: <87le1edqqm.fsf@breatheoutbreathe.in> <86h6c2ug0p.fsf@gnu.org> <86a5htvclm.fsf@gnu.org> Date: Sat, 03 Aug 2024 20:18:06 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 72437 Cc: 72437@debbugs.gnu.org, monnier@iro.umontreal.ca, joseph@breatheoutbreathe.in X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Hi Eli, Eli Zaretskii writes: >> From: Eshel Yaron >> Cc: Joseph Turner , Stefan Monnier >> , 72437@debbugs.gnu.org >> Date: Sat, 03 Aug 2024 13:04:58 +0200 >> >> Eli Zaretskii writes: >> >> > post-self-insert-hook for each of the ARG inserted characters. OTOH, >> > to produce "{{}}" we'd probably need to rewrite the >> > electric-pair-mode's hook function, but I have no idea how to rewrite >> > it to do that. >> > >> > Stefan, any suggestions? >> >> I'm no Stefan, but I took a quick stab at it. The following diff >> teaches electric-pair-mode about numeric prefix arguments: > > Thanks, but isn't it cleaner if we simply call the hook from cmds.c > the same number of times as we insert a character? Interesting, it might work for electric-pair-mode, though I suspect that not all functions that people put on post-self-insert-hook are prepared to be invoked repeatedly following a single self-insert-command. From debbugs-submit-bounces@debbugs.gnu.org Sat Aug 03 14:46:54 2024 Received: (at 72437) by debbugs.gnu.org; 3 Aug 2024 18:46:54 +0000 Received: from localhost ([127.0.0.1]:54803 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1saJmI-0000Hf-4U for submit@debbugs.gnu.org; Sat, 03 Aug 2024 14:46:54 -0400 Received: from eggs.gnu.org ([209.51.188.92]:46664) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1saJmG-0000HP-3x for 72437@debbugs.gnu.org; Sat, 03 Aug 2024 14:46:53 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1saJlq-0000A9-5G; Sat, 03 Aug 2024 14:46:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=d+7+qpgEgVGeZkahdTB4hUfhocS9CkTSKs9tDn/Zxgg=; b=SoNhynSfa8AW OTLKU5W69tq1RwP2mlIDPwEqQee7dfCECb9PX5D3n4nmaCHp4PpYJv5UOIQFrM/D/xi+gq9KFN7/1 QSMHQ4DqkIEbRf+dNuuN3uIjNkxNB/wApo7twOUqURPwzvQWFpmLWnuR0zpRWatziAtJnZPTU6qi2 lDaBRcMVwXlV1uC7QwCG+N/MGRwxkOSFdpAcFSaL5l/pD/ehEjJdj92mai1ALrP5iGY5AZYqE4qve ksrF41IIzChCvBiZDU/61Io8vj03VlBPRbjvt7iT26A4V4MEGM900IUzIWhGbn2hawYnyNOf+5wvV TC75sdJZ1jpPIzF0mbErDw==; Date: Sat, 03 Aug 2024 21:46:22 +0300 Message-Id: <86zfpttpfl.fsf@gnu.org> From: Eli Zaretskii To: Eshel Yaron In-Reply-To: (message from Eshel Yaron on Sat, 03 Aug 2024 20:18:06 +0200) Subject: Re: bug#72437: Unexpected behavior when inserting with prefix arg in electric-pair-mode References: <87le1edqqm.fsf@breatheoutbreathe.in> <86h6c2ug0p.fsf@gnu.org> <86a5htvclm.fsf@gnu.org> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 72437 Cc: 72437@debbugs.gnu.org, monnier@iro.umontreal.ca, joseph@breatheoutbreathe.in X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Eshel Yaron > Cc: joseph@breatheoutbreathe.in, monnier@iro.umontreal.ca, > 72437@debbugs.gnu.org > Date: Sat, 03 Aug 2024 20:18:06 +0200 > > >> I'm no Stefan, but I took a quick stab at it. The following diff > >> teaches electric-pair-mode about numeric prefix arguments: > > > > Thanks, but isn't it cleaner if we simply call the hook from cmds.c > > the same number of times as we insert a character? > > Interesting, it might work for electric-pair-mode, though I suspect that > not all functions that people put on post-self-insert-hook are prepared > to be invoked repeatedly following a single self-insert-command. It isn't a single self-insert-command, since it inserts N characters. So it is natural to expect the hook to be invoked those same N times. I think. Let's hear what Stefan thinks (and anyone else who has an opinion or some case other than electric-pair-mode). From debbugs-submit-bounces@debbugs.gnu.org Tue Aug 13 20:58:33 2024 Received: (at 72437) by debbugs.gnu.org; 14 Aug 2024 00:58:33 +0000 Received: from localhost ([127.0.0.1]:45742 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1se2LQ-0000eF-Ui for submit@debbugs.gnu.org; Tue, 13 Aug 2024 20:58:33 -0400 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:64211) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1se2LP-0000e1-8q for 72437@debbugs.gnu.org; Tue, 13 Aug 2024 20:58:32 -0400 Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id B98D4100061; Tue, 13 Aug 2024 20:57:51 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1723597070; bh=WnMYu9OH4qUAA7KFIpnP4eZfZq2U6DGp1xWKXajXS7Q=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=XMPgpGRPXAxAUV7JaLGOFFkT4ytwuutVH9/VdWqWpp1tq8wgAAGwu6WUOBYiL12Wo BGngREeHzxtBidqAqHMoauwkFlfweoZz/km9n6drs6RmS9BtJwwXqOjaGcD6YW+8Hh Kg6RWy4duoBzIooIZmdFNjWNvAfS9NGGPwUEYbhA/t+nH9iH7B1n/NGscEhO5SXrTP 4/3YVw0ixjLWQVEPeynZRDpJ2+Nr63H9FYCCF6wq5Gg+Yg+CLSDQoQJg3ti85JVSiM sHx5d2p8f+wGw4DSg+orlhHg8FYSuGouS4xxXCuIw0QM1fnH5KOCj9PVuLpbsM4Dw0 Tl/hqv/p1DMOQ== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 33D8910002E; Tue, 13 Aug 2024 20:57:50 -0400 (EDT) Received: from pastel (unknown [216.154.9.87]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 06A481201A6; Tue, 13 Aug 2024 20:57:50 -0400 (EDT) From: Stefan Monnier To: =?windows-1252?B?Sm/jbyBU4XZvcmE=?= Subject: Re: bug#72437: Unexpected behavior when inserting with prefix arg in electric-pair-mode In-Reply-To: <86h6c2ug0p.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 03 Aug 2024 12:12:06 +0300") Message-ID: References: <87le1edqqm.fsf@breatheoutbreathe.in> <86h6c2ug0p.fsf@gnu.org> Date: Tue, 13 Aug 2024 20:57:44 -0400 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL -0.028 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain T_SCC_BODY_TEXT_LINE -0.01 - X-SPAM-LEVEL: X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 72437 Cc: 72437@debbugs.gnu.org, Joseph Turner X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) Hi Jo=E3o, Do you have a good idea of how to make C-M-SPC C-2 { wrap the selected word within two braces? Stefan Eli Zaretskii [2024-08-03 12:12:06] wrote: >> Cc: eliz@gnu.org >> From: Joseph Turner >> Date: Sat, 03 Aug 2024 00:12:33 -0700 >>=20 >> Migrated from this thread on the devel mailing list: >>=20 >> https://yhetil.org/emacs-devel/86ikwiumza.fsf@gnu.org/T/#t >>=20 >>=20 >> On Emacs 29.4, with emacs -Q >>=20 >> Turn on electric-pair-mode >>=20 >> (electric-pair-mode +1) >>=20 >> Then press "C-2 (" >>=20 >> Expected result: >>=20 >> Either (()) or ()() >>=20 >> Actual result: >>=20 >> (() >>=20 >>=20 >> I noticed the unexpected behavior when attempting to surround some text >> with multiple braces in order to create Anki flashcards. >>=20 >> More or less, I wanted to go from "foo" to "{{foo}}", and I thought >> perhaps that with the whole word selected, pressing "C-2 {" would DTRT. >>=20 >> In general, I'm not sure whether "{}{}" or "{{}}"is more useful or >> expected, but I suspect both are better than "{{}". > > Making it produce "{}{}" is relatively easy: we just need to call the > post-self-insert-hook for each of the ARG inserted characters. OTOH, > to produce "{{}}" we'd probably need to rewrite the > electric-pair-mode's hook function, but I have no idea how to rewrite > it to do that. > > Stefan, any suggestions? From debbugs-submit-bounces@debbugs.gnu.org Tue Aug 13 21:01:03 2024 Received: (at 72437) by debbugs.gnu.org; 14 Aug 2024 01:01:04 +0000 Received: from localhost ([127.0.0.1]:45747 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1se2Nr-0000lI-Je for submit@debbugs.gnu.org; Tue, 13 Aug 2024 21:01:03 -0400 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:25325) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1se2Np-0000kc-JL for 72437@debbugs.gnu.org; Tue, 13 Aug 2024 21:01:02 -0400 Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 11A62808A4; Tue, 13 Aug 2024 21:00:22 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1723597220; bh=WkgVo36r7MSoYDRZja1rr0Tf0kAzqRAmzM9IjEo7v5w=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=dwaGFpUSuSFy8YLoOATz0EB3q3cUogBgq13OIMYgkrAdeVXcK6EJ/wN552SLS2BbN CdhuRdkwri1f8k13Jkzmkg8+MVRVEC7I7xQEqkDPkuOK8igZ5eG3S68H+Vz1iHrkTg 2t1eUoSmfEpOdX6qP1hV2DfR46JwDezaBlpu6fbjmnCvCLnMA9JLq/6gvffQgC0ez4 5v5/s9D3b3GSDPzelXpV6de6Vr52jEGbuQWXWjS44gcU3Ut4jmgusGqUFOD2B4LPT/ fguw4wmQQ6Y5sht/kbCpj1WkmrnmvOCbREbY14mtl0i1E1tyvhv6meyOwkZLRP4FOm kqUP9bSLH3pLw== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 9BAE180672; Tue, 13 Aug 2024 21:00:20 -0400 (EDT) Received: from pastel (unknown [216.154.9.87]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 3A5DA1206B0; Tue, 13 Aug 2024 21:00:20 -0400 (EDT) From: Stefan Monnier To: Eli Zaretskii Subject: Re: bug#72437: Unexpected behavior when inserting with prefix arg in electric-pair-mode In-Reply-To: <86zfpttpfl.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 03 Aug 2024 21:46:22 +0300") Message-ID: References: <87le1edqqm.fsf@breatheoutbreathe.in> <86h6c2ug0p.fsf@gnu.org> <86a5htvclm.fsf@gnu.org> <86zfpttpfl.fsf@gnu.org> Date: Tue, 13 Aug 2024 21:00:19 -0400 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL -0.147 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain T_SCC_BODY_TEXT_LINE -0.01 - X-SPAM-LEVEL: X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 72437 Cc: 72437@debbugs.gnu.org, Eshel Yaron , joseph@breatheoutbreathe.in X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > It isn't a single self-insert-command, since it inserts N characters. > So it is natural to expect the hook to be invoked those same N times. > I think. Let's hear what Stefan thinks (and anyone else who has an > opinion or some case other than electric-pair-mode). I think the requested behavior makes a lot of sense, but I lost touch with the way elec-pair works and interacts with other electric modes, so I'm not sure how to make it work without breaking other things. Stefan From debbugs-submit-bounces@debbugs.gnu.org Wed Aug 14 01:08:07 2024 Received: (at submit) by debbugs.gnu.org; 14 Aug 2024 05:08:07 +0000 Received: from localhost ([127.0.0.1]:45826 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1se6Ex-0007mc-B3 for submit@debbugs.gnu.org; Wed, 14 Aug 2024 01:08:07 -0400 Received: from lists.gnu.org ([209.51.188.17]:48544) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1se6Eu-0007mU-OC for submit@debbugs.gnu.org; Wed, 14 Aug 2024 01:08:05 -0400 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 1se6EM-0003cL-1d for bug-gnu-emacs@gnu.org; Wed, 14 Aug 2024 01:07:30 -0400 Received: from mail.eshelyaron.com ([107.175.124.16] helo=eshelyaron.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1se6EK-0006pZ-Ig; Wed, 14 Aug 2024 01:07:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eshelyaron.com; s=mail; t=1723612045; bh=gIWY/mkkSiwaHvJt6nHI6gLzggVlmkW6V5o8ayTvzoY=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=BntsP28kkcjHo83APA8xhd0lJ3PtV2VSFYisw/wGXaxPJJGfQxNCpJGEd0UUWKXXX KAn6kMe6ejYn2czzJ/AK00jvCKP2ADwIdOWavHgXNvSt2moY0i4TLtItmv2SDjmCEW 75yab1hZsYFInkYdUfafFBQZj9et7ewShRZkG0+p57bInFyJzi9HRGsGqovMepBZwm 5aRlCGtENYpQ1WAN80Koz9TtSu5F1V1oiEdKoWgWavPhCpdpWNYBaI0QnMwKPCjmkV BHJfVx1u7xc5YZL8m4htLjiO4lSuTuQ8s2WgwAJFNAQU+hsTFBtQ4VmybByUF0IIaC L2lgfYEP7jVsA== From: Eshel Yaron To: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Subject: Re: bug#72437: Unexpected behavior when inserting with prefix arg in electric-pair-mode In-Reply-To: (Stefan Monnier via's message of "Tue, 13 Aug 2024 21:00:19 -0400") References: <87le1edqqm.fsf@breatheoutbreathe.in> <86h6c2ug0p.fsf@gnu.org> <86a5htvclm.fsf@gnu.org> <86zfpttpfl.fsf@gnu.org> Date: Wed, 14 Aug 2024 07:07:23 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=107.175.124.16; envelope-from=me@eshelyaron.com; helo=eshelyaron.com 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_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.4 (-) X-Debbugs-Envelope-To: submit Cc: 72437@debbugs.gnu.org, Eli Zaretskii , Stefan Monnier , joseph@breatheoutbreathe.in X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.4 (--) Hi Stefan, Stefan Monnier writes: >> Let's hear what Stefan thinks (and anyone else who has an >> opinion or some case other than electric-pair-mode). > > I think the requested behavior makes a lot of sense, but I lost touch > with the way elec-pair works and interacts with other electric modes, so > I'm not sure how to make it work without breaking other things. In case you missed it, the patch I shared upthread might give you some ideas. It implements the requested behavior, safely, I think. So I would just ask Joseph to try it out for a while and see if it works as expected and if any other issues crop up :) Cheers, Eshel From debbugs-submit-bounces@debbugs.gnu.org Wed Aug 14 07:40:12 2024 Received: (at 72437) by debbugs.gnu.org; 14 Aug 2024 11:40:12 +0000 Received: from localhost ([127.0.0.1]:46342 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1seCMN-0001Bs-UU for submit@debbugs.gnu.org; Wed, 14 Aug 2024 07:40:12 -0400 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:35530) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1seCMM-0001Bd-JC for 72437@debbugs.gnu.org; Wed, 14 Aug 2024 07:40:10 -0400 Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 7944B10005D; Wed, 14 Aug 2024 07:39:30 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1723635569; bh=9Cn61FRob82rg+7Xyo66SS38EXL1sh3jniSQVj4wnGE=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=ektEJIVZQVywM276fF94fwKQuyDQd99MVt7W3yyYO5Me/LRgWDnhtVVV74taDx9XG il07cjU/SufBCh3VaR1RW6RmlYuX6lvDmLLbI8v6ZaUcu6TXt7fYkyns240JkV06yQ keM2HnkunsGeo3cuZFFKj4GzyFgT6aPM58FxRM3Ezt4brhEBU3xeWJKNEivY2BmmpC q7K0vG5v8ldWyHBbj9tkbtvsrKNU03QpOTF6g23MAs3YHNzDsGMSyd5q63yTJEFxuy TKacm0wyZNjVUj1HVStsam10NNs5SdNmRa3esOejNRapEw5OeI8n9oLYQY3KFCseTH 3OVD11lIquxSg== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 693A5100042; Wed, 14 Aug 2024 07:39:29 -0400 (EDT) Received: from pastel (unknown [216.154.9.87]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 362A212065C; Wed, 14 Aug 2024 07:39:29 -0400 (EDT) From: Stefan Monnier To: Eshel Yaron Subject: Re: bug#72437: Unexpected behavior when inserting with prefix arg in electric-pair-mode In-Reply-To: (Eshel Yaron's message of "Wed, 14 Aug 2024 07:07:23 +0200") Message-ID: References: <87le1edqqm.fsf@breatheoutbreathe.in> <86h6c2ug0p.fsf@gnu.org> <86a5htvclm.fsf@gnu.org> <86zfpttpfl.fsf@gnu.org> Date: Wed, 14 Aug 2024 07:39:27 -0400 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL -0.024 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain T_SCC_BODY_TEXT_LINE -0.01 - X-SPAM-LEVEL: X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 72437 Cc: 72437@debbugs.gnu.org, Eli Zaretskii , joseph@breatheoutbreathe.in X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > In case you missed it, the patch I shared upthread might give you > some ideas. It implements the requested behavior, safely, I think. > So I would just ask Joseph to try it out for a while and see if it > works as expected and if any other issues crop up :) I missed that, indeed, sorry. Then maybe we should just push it to `master` (with appropriate regression test(s)). Stefan From debbugs-submit-bounces@debbugs.gnu.org Fri Aug 16 17:24:29 2024 Received: (at 72437) by debbugs.gnu.org; 16 Aug 2024 21:24:29 +0000 Received: from localhost ([127.0.0.1]:53033 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sf4Qv-0007oz-2v for submit@debbugs.gnu.org; Fri, 16 Aug 2024 17:24:29 -0400 Received: from mail-oo1-f46.google.com ([209.85.161.46]:56470) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sf4Qs-0007oi-Sx for 72437@debbugs.gnu.org; Fri, 16 Aug 2024 17:24:27 -0400 Received: by mail-oo1-f46.google.com with SMTP id 006d021491bc7-5d5c7f23f22so1448667eaf.0 for <72437@debbugs.gnu.org>; Fri, 16 Aug 2024 14:23:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723843363; x=1724448163; darn=debbugs.gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=V8pXj+2nftqThDfYupGDF5DzZ/lP/qIgsxg5gB+UHb8=; b=R5X72uzsXxbZdu/bOmptsGVUfrozX7E3bHHxV2r1MFEleLKZgll0CtYog1FjgRhYTy +aK3rsCvoPx66hwZ44o6eERdgp6m91+Fl0ynvoa/U+TkwVRRW4psy1PiM36rEQ0O4tWe 7BvMuAp6jZtZH/VyUIEDtVsgxOb6zA7a0KXxHpnJBbKQCn8YT30sFbjKohBALvKJj7DO qewfLdiYo9UL7Ok6Pfs375WbqYYZ7AAvYPrpgeNDNpcSGf7kC7jYVDTWCP//sHJNmm7L khCJo8Dabl9cu/CnvpCN72GPS88wt6MEkliwL2+KOY8P/UsLl0rRIGgyUpDEPvR/H6Rz 6xkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723843363; x=1724448163; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=V8pXj+2nftqThDfYupGDF5DzZ/lP/qIgsxg5gB+UHb8=; b=CPJqnlXBhtdvcwnwdIMV63Dt2xIsLDaLV/O+Gaf0ujs7VX8ySXzBn12ztuVv9oOGaH xWGnH2c29GyaNGtsM/wQHqf5wNy8xhKpnRWwkKAWCbgEZeieDTwPYHaRh1xT4lelHBEa ibggq9dIOf6/Z+cv1Q3FfSa1QwLJtykF5flevf7hzDI7RHG9mx+aUXC+Hjf0aat85RjU MvJhY0ywULEH8YC0Dn9Ao7WQRwawvRlBa+YYHIjT8aMHhvzG8khiURzQ57DQ6qMHOkQs sUKCPwXopRRPzQrkV9p+xzYmIKSuJFP89+r7oTwWFbWLIoW+1uWdYCIXVtSGP48LFU+4 r9nQ== X-Forwarded-Encrypted: i=1; AJvYcCX9A2Rz8nugF+NHghiyngHt/FiFPU65KAuPXAXwefbvUTPJFBnKBMxmwUL85zMwxYO2vhRtVbMiBeDXSfukz7zq8nontuI= X-Gm-Message-State: AOJu0YzSi6lG2BlcIsdB9PmMpZ/+M+3RDh2AvcLlB3Gfmw9eyVVQEKMz nhoXBslok2yc1ikVIsyjvBKaPA3Ie3LcZTIbsAiZyAnjGmoZiHOxJhdzDQarMNvvA6Dj3m8oI8W GBKxTknFrqViFlmtgNrMiFXAk3MKVpw== X-Google-Smtp-Source: AGHT+IEVyK3Lt5B3BYC6ny3D3AmdUc/ubN1lWtr8XK2HMg8pnk2NCI+o0hKmE8VUFhjA9m+SxS8KGg+V7Xu17AUa4vc= X-Received: by 2002:a05:6820:222a:b0:5da:9204:671b with SMTP id 006d021491bc7-5da98026b3fmr5859341eaf.7.1723843363090; Fri, 16 Aug 2024 14:22:43 -0700 (PDT) MIME-Version: 1.0 References: <87le1edqqm.fsf@breatheoutbreathe.in> <86h6c2ug0p.fsf@gnu.org> In-Reply-To: From: =?UTF-8?B?Sm/Do28gVMOhdm9yYQ==?= Date: Fri, 16 Aug 2024 22:22:29 +0100 Message-ID: Subject: Re: bug#72437: Unexpected behavior when inserting with prefix arg in electric-pair-mode To: Stefan Monnier Content-Type: multipart/alternative; boundary="0000000000004e377e061fd38f6e" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 72437 Cc: 72437@debbugs.gnu.org, Joseph Turner X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --0000000000004e377e061fd38f6e Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Aug 14, 2024, 01:57 Stefan Monnier wrote= : > Hi Jo=C3=A3o, > > Do you have a good idea of how to make > > C-M-SPC C-2 { > > wrap the selected word within two braces? > No great ideas no. Does it even work in the non-wrapping case? The intended result is as if the command was run twice, no? So maybe try somehow that the whole thing is run twice/thrice/etc... Jo=C3=A3o --0000000000004e377e061fd38f6e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Wed, Aug 14, 2024, 01:57 Stefan Monnier <monnier@iro.umontreal.ca> wrote= :
Hi Jo=C3=A3o,<= br>
Do you have a good idea of how to make

=C2=A0 =C2=A0C-M-SPC C-2 {

wrap the selected word within two braces?

No great ideas no. Does it even wo= rk in the non-wrapping case? The intended result is as if the command was r= un twice, no? So maybe try somehow that the whole thing is run twice/thrice= /etc...

Jo=C3=A3o
<= div dir=3D"auto">
=C2=A0
--0000000000004e377e061fd38f6e-- From debbugs-submit-bounces@debbugs.gnu.org Sat Aug 17 02:09:42 2024 Received: (at 72437) by debbugs.gnu.org; 17 Aug 2024 06:09:42 +0000 Received: from localhost ([127.0.0.1]:53265 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sfCdB-0005H0-UC for submit@debbugs.gnu.org; Sat, 17 Aug 2024 02:09:42 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48328) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sfCd9-0005Gm-5N for 72437@debbugs.gnu.org; Sat, 17 Aug 2024 02:09:40 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sfCcP-0002Dx-0T; Sat, 17 Aug 2024 02:08:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=84zwA8IReLRZDJR/x2jwDDQ7dCiIXp9GNaUsSf26e/k=; b=o35auqc+h7Dp3MRITEC+ ZbQqJNddiu5okBEFMvLdN0sjebpvj0t/LSEyvN0zMlt1pAvx8rmY0FbORlj8LdPMXgWeHWSAkdDk3 /P6YQfR0HUB8J7HLpQojtVXEAOH1EdtUFag8Nx6xXv1gTnOPMKvg89NsNHDl78Y8qbb3QJOJFJXIB dY2sPLL0s+FJFqFlJhri9SOrhYfXODJuvZt0DMKP6xlHR5AImwCaDZ6H73Q/oD0c7xg9I8ZMJ+Xzr pMz6Oi6r8mSNd9UX32sXQrKPfGpTZbhvIunGosjWqBpb+Uhl9/rW5qh3jFs3LDPNafihAJdjDD7To PgQLN5u71C2JbA==; Date: Sat, 17 Aug 2024 09:08:50 +0300 Message-Id: <868qwv65ql.fsf@gnu.org> From: Eli Zaretskii To: =?utf-8?B?Sm/Do28gVMOhdm9yYQ==?= In-Reply-To: (message from =?utf-8?B?Sm/Do28gVMOhdm9yYQ==?= on Fri, 16 Aug 2024 22:22:29 +0100) Subject: Re: bug#72437: Unexpected behavior when inserting with prefix arg in electric-pair-mode References: <87le1edqqm.fsf@breatheoutbreathe.in> <86h6c2ug0p.fsf@gnu.org> MIME-version: 1.0 Content-type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 72437 Cc: 72437@debbugs.gnu.org, monnier@iro.umontreal.ca, joseph@breatheoutbreathe.in X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > Cc: 72437@debbugs.gnu.org, Joseph Turner > From: João Távora > Date: Fri, 16 Aug 2024 22:22:29 +0100 > > On Wed, Aug 14, 2024, 01:57 Stefan Monnier wrote: > > Hi João, > > Do you have a good idea of how to make > > C-M-SPC C-2 { > > wrap the selected word within two braces? > > No great ideas no. Does it even work in the non-wrapping case? The intended result is as if the command was > run twice, no? So maybe try somehow that the whole thing is run twice/thrice/etc... That's what I suggested, but the result is "{}{}{}{}...", which is not what was requested. IOW, what is being requested is NOT what happens when running this command N times, it should be a special handling of the numerical argument. From debbugs-submit-bounces@debbugs.gnu.org Sat Aug 17 02:29:26 2024 Received: (at 72437) by debbugs.gnu.org; 17 Aug 2024 06:29:26 +0000 Received: from localhost ([127.0.0.1]:53277 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sfCwI-0005lQ-BK for submit@debbugs.gnu.org; Sat, 17 Aug 2024 02:29:26 -0400 Received: from out-180.mta1.migadu.com ([95.215.58.180]:45259) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sfCwF-0005l6-VG for 72437@debbugs.gnu.org; Sat, 17 Aug 2024 02:29:24 -0400 Date: Fri, 16 Aug 2024 23:28:32 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=breatheoutbreathe.in; s=key1; t=1723876117; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/4kmGX3TKJ7X7v9oxIuQANthJFb2lT13U7K/oL5szXE=; b=I28V1H3biURkIUuzf0YQMq0fYHtoFzOP9un0knHYyzb0H4E+fTJr8TKYsjT9qpFaIGwaq2 Wsya0eXbQ0D+QBLVn2xbwrTzuXS3yEIpZguIyzLCa9PSQAvgny0wsnbmDssCrhlPHAyMsk loD3373MpofCX9PpUMcE8YrQYZ8b70U= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Joseph Turner To: Eshel Yaron , "Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors" Subject: =?US-ASCII?Q?Re=3A_bug=2372437=3A_Unexpected_behavior_when_ins?= =?US-ASCII?Q?erting_with_prefix_arg_in_electric-pair-mode?= In-Reply-To: References: <87le1edqqm.fsf@breatheoutbreathe.in> <86h6c2ug0p.fsf@gnu.org> <86a5htvclm.fsf@gnu.org> <86zfpttpfl.fsf@gnu.org> Message-ID: <20F64DCD-929F-4B4C-BF85-ABE26FC7C995@breatheoutbreathe.in> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 72437 Cc: 72437@debbugs.gnu.org, Eli Zaretskii , Stefan Monnier X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) On August 13, 2024 10:07:23 PM PDT, Eshel Yaron wrot= e: >Hi Stefan, > >Stefan Monnier writes: > >>> Let's hear what Stefan thinks (and anyone else who has an >>> opinion or some case other than electric-pair-mode)=2E >> >> I think the requested behavior makes a lot of sense, but I lost touch >> with the way elec-pair works and interacts with other electric modes, s= o >> I'm not sure how to make it work without breaking other things=2E > >In case you missed it, the patch I shared upthread might give you >some ideas=2E It implements the requested behavior, safely, I think=2E >So I would just ask Joseph to try it out for a while and see if it >works as expected and if any other issues crop up :) Thanks for this patch! I am testing it in my daily config=2E So far so g= ood, and I'll report back after a few weeks of usage=2E Warmly, Joseph From debbugs-submit-bounces@debbugs.gnu.org Sat Aug 17 05:32:15 2024 Received: (at 72437) by debbugs.gnu.org; 17 Aug 2024 09:32:15 +0000 Received: from localhost ([127.0.0.1]:53511 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sfFnC-0002fd-Op for submit@debbugs.gnu.org; Sat, 17 Aug 2024 05:32:15 -0400 Received: from mail-oa1-f52.google.com ([209.85.160.52]:59619) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sfFnB-0002fQ-G1 for 72437@debbugs.gnu.org; Sat, 17 Aug 2024 05:32:14 -0400 Received: by mail-oa1-f52.google.com with SMTP id 586e51a60fabf-27026393c12so864290fac.2 for <72437@debbugs.gnu.org>; Sat, 17 Aug 2024 02:31:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723887029; x=1724491829; darn=debbugs.gnu.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=67rHkIdi0DlsDkPn/pQlvts49/Ao6S/wbarCSWSU68o=; b=QjSz+W3Y1RnkvoThbMVNBetAwFFaJZPKc+dLAY4urWzLLnDx0Hap3oKIZZuDA5NSLR /WWZsKoN7dFnVAQJAeynBJs3aMdhk0nScTcyds4/HHfjq00/NtOjhrKJFCs5/FK9eHsP 3Pj5mRStUl0pzXQpq6H4gIfY0+q9MFl3KTWXykTKC9eQsL/xBjRIYqe4rddQt+GcIL9D sHfyEKIZ4HrbDDOJXnf0nURuMwfb3rh+YXYiLGiv0uIous0N94D3HsBadw0z/yjSIqPe K28yk7EE9YTZZyx1RWtmYFKJAAXnf9JQJRv63UlJcLyeG5V+VaWNGzr0NKXPUc9FbqdN GHKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723887029; x=1724491829; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=67rHkIdi0DlsDkPn/pQlvts49/Ao6S/wbarCSWSU68o=; b=s3xXLQ2RV+rw8fIvWalgSK72oc78Z+dRa/jCxlVMSZcj9PBmWjTQbmWKUJj2laDCju QcFu1SLCHkcsDabzMmu9KRLu+9MzlDwM9Bu9cLjntKKoyyeEGwbtbOCoqipaRKByqK+R r/NGK4k6Y/rhWox8MQBLN30VRdN/94Ns/9okM+5rPY8/lQalx1m6xGrighHts3Cl8dq+ 0MPsWaZJ6IhrnhpKTCIeGUwZezK59U/oCetvG4Ui/sG5W9SDf+kefzNb5QbO0avQphn1 txf+OrKdytKF39l5lsON4Ccmeh94FbqC5RD7HSTz8si4OlX8kZhCijnSaXLs3ZGpBWfH CpDg== X-Forwarded-Encrypted: i=1; AJvYcCVom06VapDAV7ppKj4goJMa5qBzKPlmqClUZtAMkIXIuv5R1++n+tvOfPVxxO4eVXa5ARRHO9vRkn7ppysRo/btuHMUy4Y= X-Gm-Message-State: AOJu0YwXVYUJLkoiv0k+BQUuNm9J3na+u3EAFbpSVMz/VUEZsubR4kfC 7zCRtwMF/r6pJYkptwY94tW07IiBC4Qt6/0cJK9lgF1jAtqkzJ0DcLXqLKGWWs7hqLVGVx+jcX5 TOmA5e2Xb5hotb2UV6SKLRHfTZr8= X-Google-Smtp-Source: AGHT+IHsMPjAgBIvFaBCmPl5q1LeEj94hL1hmycx+TBRWom4VHNEpT+SxhQXEhuQ554rtGpXACzIFOEzooKbz+zGm/4= X-Received: by 2002:a05:6870:3320:b0:260:fbc0:96ec with SMTP id 586e51a60fabf-2701c55a28bmr6504866fac.38.1723887029069; Sat, 17 Aug 2024 02:30:29 -0700 (PDT) MIME-Version: 1.0 References: <87le1edqqm.fsf@breatheoutbreathe.in> <86h6c2ug0p.fsf@gnu.org> <868qwv65ql.fsf@gnu.org> In-Reply-To: <868qwv65ql.fsf@gnu.org> From: =?UTF-8?B?Sm/Do28gVMOhdm9yYQ==?= Date: Sat, 17 Aug 2024 10:30:18 +0100 Message-ID: Subject: Re: bug#72437: Unexpected behavior when inserting with prefix arg in electric-pair-mode To: Eli Zaretskii Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 72437 Cc: 72437@debbugs.gnu.org, monnier@iro.umontreal.ca, joseph@breatheoutbreathe.in X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) On Sat, Aug 17, 2024 at 7:08=E2=80=AFAM Eli Zaretskii wrote: > That's what I suggested, but the result is "{}{}{}{}...", which is not > what was requested. If the preconditions are that a word is selected before each command, I don't see how that can be. At the very least it would be {word}{}{}{} or something like that. But if you arrange for word to stay selected and point before it, I don't see why {{{{word}}}} can't be achieved. Doesn't have to be word at all, could be an arbitrary sexp, IIRC. Anyway, that's all I have. From debbugs-submit-bounces@debbugs.gnu.org Sat Aug 17 10:04:06 2024 Received: (at 72437) by debbugs.gnu.org; 17 Aug 2024 14:04:06 +0000 Received: from localhost ([127.0.0.1]:54789 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sfK2I-0001yq-8m for submit@debbugs.gnu.org; Sat, 17 Aug 2024 10:04:06 -0400 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:39273) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sfK2F-0001yI-TJ for 72437@debbugs.gnu.org; Sat, 17 Aug 2024 10:04:04 -0400 Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id EC006100044; Sat, 17 Aug 2024 10:03:17 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1723903397; bh=ySaRU1Pg2L8KRvtQrpBgE1F9JA0BwDLpCC3VigmxzR8=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=iSfWCCZaF9geu1JObmU0CUHgwNNJNnxusgtp0FmbqCfrrSV9KJo49yPct0Irj8a5W Y5g9M9Azs66oOqe1dIQuuk/r4QDaiUEUdm9tDAoFvjXT9nZTEXpiDcevgWecnSbg/2 FrApHU+FxuVch0d6CjcR9om9n4WshBLjAI0dtERNXTBDMIs+tpWjwvYECme90kYuaR /2F+1XL76KkxQV/XkIfIwByFy+LzFJD+7pbU3Z4epQeu5FhuYq6icRDV07+AYCpYoD Y6SrRlVV1UWsf+oX0vv0lOguHpfoZmF97nZnu4a4qHgfXwVzpKsBT2pLsk1iLFJIp+ 3hY0XIIt2Diug== Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id E9E25100035; Sat, 17 Aug 2024 10:03:16 -0400 (EDT) Received: from alfajor (unknown [216.154.9.87]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id B75EF120480; Sat, 17 Aug 2024 10:03:16 -0400 (EDT) From: Stefan Monnier To: Eli Zaretskii Subject: Re: bug#72437: Unexpected behavior when inserting with prefix arg in electric-pair-mode In-Reply-To: <868qwv65ql.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 17 Aug 2024 09:08:50 +0300") Message-ID: References: <87le1edqqm.fsf@breatheoutbreathe.in> <86h6c2ug0p.fsf@gnu.org> <868qwv65ql.fsf@gnu.org> Date: Sat, 17 Aug 2024 10:03:38 -0400 User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL -0.020 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain T_SCC_BODY_TEXT_LINE -0.01 - X-SPAM-LEVEL: X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 72437 Cc: 72437@debbugs.gnu.org, =?windows-1252?B?Sm/jbyBU4XZvcmE=?= , joseph@breatheoutbreathe.in X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > That's what I suggested, but the result is "{}{}{}{}...", which is not For me `C-u 2 (` results in `(()`. Stefan From debbugs-submit-bounces@debbugs.gnu.org Sat Aug 17 10:22:36 2024 Received: (at 72437) by debbugs.gnu.org; 17 Aug 2024 14:22:36 +0000 Received: from localhost ([127.0.0.1]:54816 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sfKKB-0002Y8-OV for submit@debbugs.gnu.org; Sat, 17 Aug 2024 10:22:36 -0400 Received: from eggs.gnu.org ([209.51.188.92]:54702) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sfKK9-0002Xv-0H for 72437@debbugs.gnu.org; Sat, 17 Aug 2024 10:22:33 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sfKJQ-0003F4-7d; Sat, 17 Aug 2024 10:21:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=ZckE3e0FFjIKL0axgBJPlRHC8aF68Ftk/cQxFmsiy+0=; b=Nglg3jDhC4h/fA6WQi9w CVWT2yB0uw08mCd80XV5oimJUp/7LX/zish/IgKRuU3sO6E45LSAOOY8Q4OBx9KeXnKlwtDLsfRmR ny2M8lLDURn63hNo8Mu3/kHwLrsRlYLPD2wviQzP0MVfwWdL/4gAMJO8+8Mh7Y/J9mWTqZRGXgEP3 rNz79BbKgA7LxixPMDT3xeVEHOgPXmrGsV7Chf0kBzWyQW75Dpa1pfRO/w4xMLnjj1T4sZudG7Dd6 I8dMxdH2i+za27prtmw3Fqk541N8GuFsKsjtsFneETXw84MRNlBHUWnPf6U/KX9iShbNGjcDaxY2i VRbl+sZ3ppk3lQ==; Date: Sat, 17 Aug 2024 17:21:07 +0300 Message-Id: <86plq71b8s.fsf@gnu.org> From: Eli Zaretskii To: Stefan Monnier In-Reply-To: (message from Stefan Monnier on Sat, 17 Aug 2024 10:03:38 -0400) Subject: Re: bug#72437: Unexpected behavior when inserting with prefix arg in electric-pair-mode References: <87le1edqqm.fsf@breatheoutbreathe.in> <86h6c2ug0p.fsf@gnu.org> <868qwv65ql.fsf@gnu.org> MIME-version: 1.0 Content-type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 72437 Cc: 72437@debbugs.gnu.org, joaotavora@gmail.com, joseph@breatheoutbreathe.in X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Stefan Monnier > Cc: João Távora , > 72437@debbugs.gnu.org, > joseph@breatheoutbreathe.in > Date: Sat, 17 Aug 2024 10:03:38 -0400 > > > That's what I suggested, but the result is "{}{}{}{}...", which is not > > For me `C-u 2 (` results in `(()`. I suggested a change which would yield ()(). Without the change, you shouldn't expect getting anything useful, because the hook is called just once, not ARG times. From debbugs-submit-bounces@debbugs.gnu.org Thu Sep 19 01:15:21 2024 Received: (at submit) by debbugs.gnu.org; 19 Sep 2024 05:15:22 +0000 Received: from localhost ([127.0.0.1]:59599 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sr9Vh-0005Pd-F8 for submit@debbugs.gnu.org; Thu, 19 Sep 2024 01:15:21 -0400 Received: from lists.gnu.org ([209.51.188.17]:45996) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sr9Ve-0005NU-Ja for submit@debbugs.gnu.org; Thu, 19 Sep 2024 01:15:20 -0400 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 1sr9VN-0000pl-B2 for bug-gnu-emacs@gnu.org; Thu, 19 Sep 2024 01:15:01 -0400 Received: from out-186.mta0.migadu.com ([2001:41d0:1004:224b::ba]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sr9VK-0002C5-Vx for bug-gnu-emacs@gnu.org; Thu, 19 Sep 2024 01:15:00 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=breatheoutbreathe.in; s=key1; t=1726722895; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=n+9u7AccSXl4dvbrm1wMF2aXSF4SXkpmS8B9sKBOehc=; b=iSrI9rBSSwkzt2odGJH6I7eR5pw2yox1B0ZRbNz0VG7HMN3I9ZQJawzO7O8aWeFBypW0di bTiaBnZyrhZys4AXbfRLeSbzkyue2TdpQh+C2gUILkFm6Roksc8OS8W8a1IgMk1z4afd2P 7RLnH9nhy7YDVbjPsJdQov6r6eXLML4= From: Joseph Turner To: Eshel Yaron Subject: Re: bug#72437: Unexpected behavior when inserting with prefix arg in electric-pair-mode In-Reply-To: <20F64DCD-929F-4B4C-BF85-ABE26FC7C995@breatheoutbreathe.in> (Joseph Turner's message of "Fri, 16 Aug 2024 23:28:32 -0700") References: <87le1edqqm.fsf@breatheoutbreathe.in> <86h6c2ug0p.fsf@gnu.org> <86a5htvclm.fsf@gnu.org> <86zfpttpfl.fsf@gnu.org> <20F64DCD-929F-4B4C-BF85-ABE26FC7C995@breatheoutbreathe.in> Date: Wed, 18 Sep 2024 22:14:48 -0700 Message-ID: <87plp0w7g7.fsf@breatheoutbreathe.in> MIME-Version: 1.0 Content-Type: text/plain X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=2001:41d0:1004:224b::ba; envelope-from=joseph@breatheoutbreathe.in; helo=out-186.mta0.migadu.com 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_PASS=-0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.4 (-) X-Debbugs-Envelope-To: submit Cc: 72437@debbugs.gnu.org, "Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors" , Eli Zaretskii , Stefan Monnier X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.4 (--) Joseph Turner writes: > On August 13, 2024 10:07:23 PM PDT, Eshel Yaron wrote: >>Hi Stefan, >> >>Stefan Monnier writes: >> >>>> Let's hear what Stefan thinks (and anyone else who has an >>>> opinion or some case other than electric-pair-mode). >>> >>> I think the requested behavior makes a lot of sense, but I lost touch >>> with the way elec-pair works and interacts with other electric modes, so >>> I'm not sure how to make it work without breaking other things. >> >>In case you missed it, the patch I shared upthread might give you >>some ideas. It implements the requested behavior, safely, I think. >>So I would just ask Joseph to try it out for a while and see if it >>works as expected and if any other issues crop up :) > > Thanks for this patch! I am testing it in my daily config. So far so good, and I'll report back after a few weeks of usage. I have been running this patch for over a month with no issue. I vote to merge it! Thank you! Joseph From debbugs-submit-bounces@debbugs.gnu.org Sat Sep 21 06:24:25 2024 Received: (at submit) by debbugs.gnu.org; 21 Sep 2024 10:24:25 +0000 Received: from localhost ([127.0.0.1]:37271 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1srxHs-0005lJ-HX for submit@debbugs.gnu.org; Sat, 21 Sep 2024 06:24:25 -0400 Received: from lists.gnu.org ([209.51.188.17]:44186) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1srxHr-0005lC-60 for submit@debbugs.gnu.org; Sat, 21 Sep 2024 06:24:23 -0400 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 1srxHW-0008SH-PI for bug-gnu-emacs@gnu.org; Sat, 21 Sep 2024 06:24:02 -0400 Received: from mail.eshelyaron.com ([107.175.124.16] helo=eshelyaron.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1srxHU-0004NU-PV; Sat, 21 Sep 2024 06:24:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eshelyaron.com; s=mail; t=1726914238; bh=ssc4kCf3kiM5BK6rN2Qnogf4vLDs5MTJqNfmvWPgixA=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=Ble6x4DfXLid9SMJ+8mvHJ1x3HrpepyFmcKb3Tq4ATbnl0+C+rWGiBhVOzFdvPsdu kVcQexvQrqZNUuUTkkvTl8oUYebc9xsnVG0hYSX1CI/gdCOfc6QBOdJmwd63zqQKqz hB6Sgqt+NuODkT6xDjuhS9fIW+Q0fcQz8nlvKtiWebwL4RtUhvI9M3vTSn30Ii3hUo NubHDzC4faXz+D0C1maUXwpphjVJSdCkfM8LHqZi36HfCWiTN+3osQRfDUNKooxU1M 0fDRp/RB9e81DvrTOy6p0YZCufd0x0a6OxFk0Vu82bSWWwc0BKddhCkqx4I4YyTl/V +BMgwxMM++qLA== From: Eshel Yaron To: Joseph Turner Subject: Re: bug#72437: Unexpected behavior when inserting with prefix arg in electric-pair-mode In-Reply-To: <87plp0w7g7.fsf@breatheoutbreathe.in> (Joseph Turner's message of "Wed, 18 Sep 2024 22:14:48 -0700") References: <87le1edqqm.fsf@breatheoutbreathe.in> <86h6c2ug0p.fsf@gnu.org> <86a5htvclm.fsf@gnu.org> <86zfpttpfl.fsf@gnu.org> <20F64DCD-929F-4B4C-BF85-ABE26FC7C995@breatheoutbreathe.in> <87plp0w7g7.fsf@breatheoutbreathe.in> Date: Sat, 21 Sep 2024 12:23:55 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=107.175.124.16; envelope-from=me@eshelyaron.com; helo=eshelyaron.com 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_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.4 (-) X-Debbugs-Envelope-To: submit Cc: 72437@debbugs.gnu.org, "Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors" , Eli Zaretskii , Stefan Monnier X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.4 (--) --=-=-= Content-Type: text/plain Joseph Turner writes: > Joseph Turner writes: > >> On August 13, 2024 10:07:23 PM PDT, Eshel Yaron wrote: >>>Hi Stefan, >>> >>>Stefan Monnier writes: >>> >>>>> Let's hear what Stefan thinks (and anyone else who has an >>>>> opinion or some case other than electric-pair-mode). >>>> >>>> I think the requested behavior makes a lot of sense, but I lost touch >>>> with the way elec-pair works and interacts with other electric modes, so >>>> I'm not sure how to make it work without breaking other things. >>> >>>In case you missed it, the patch I shared upthread might give you >>>some ideas. It implements the requested behavior, safely, I think. >>>So I would just ask Joseph to try it out for a while and see if it >>>works as expected and if any other issues crop up :) >> >> Thanks for this patch! I am testing it in my daily config. So far >> so good, and I'll report back after a few weeks of usage. > > I have been running this patch for over a month with no issue. That's great, thanks for testing it and for reporting back! > I vote to merge it! Agreed. Here's a full patch with tests, doc updates and a NEWS entry: --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Teach-Electric-Pair-mode-about-prefix-arguments.patch >From 8e732a6db9cc2855c2b0f307129555bb2551ff96 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Sat, 21 Sep 2024 12:15:16 +0200 Subject: [PATCH] Teach Electric Pair mode about prefix arguments * lisp/elec-pair.el (electric-pair--insert): New arg TIMES. (electric-pair-inhibit-if-helps-balance) (electric-pair-post-self-insert-function) (electric-pair-open-newline-between-pairs-psif) (electric-pair-skip-if-helps-balance): Respect prefix arg. (electric-pair-delete-pair): Delete ARG chars, not just 1. * test/lisp/electric-tests.el (autowrapping-multi-1) (autowrapping-multi-2): New tests. * doc/emacs/programs.texi (Matching): Mention prefix arg support in Electric Pair mode documentation. * etc/NEWS: Announce it. --- doc/emacs/programs.texi | 4 +- etc/NEWS | 6 +++ lisp/elec-pair.el | 87 ++++++++++++++++++++----------------- test/lisp/electric-tests.el | 16 +++++++ 4 files changed, 72 insertions(+), 41 deletions(-) diff --git a/doc/emacs/programs.texi b/doc/emacs/programs.texi index 42b57143bf1..948f4128acf 100644 --- a/doc/emacs/programs.texi +++ b/doc/emacs/programs.texi @@ -1061,7 +1061,9 @@ Matching over. If the region is active (@pxref{Mark}), insertion of a delimiter operates on the region: the characters in the region are enclosed in a pair of matching delimiters, leaving point after the -delimiter you typed. +delimiter you typed. If you provide a prefix argument when inserting +a delimiter, the numeric value of that prefix argument specifies the +number of pairs to insert. These variables control additional features of Electric Pair mode: diff --git a/etc/NEWS b/etc/NEWS index b902aaf7ead..f22215851a6 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -147,6 +147,12 @@ instead of raising an error. Note that if you have disabled Transient Mark mode you might prefer to use 'unix-word-rubout', as this feature relies on there being an active region. ++++ +** Electric Pair mode can now pair multiple delimiters at once. +You can now insert or wrap text with multiple sets of parentheses and +other matching delimiters at once with Electric Pair mode, by providing +a prefix argument when inserting one of the delimiters. + * Changes in Specialized Modes and Packages in Emacs 31.1 diff --git a/lisp/elec-pair.el b/lisp/elec-pair.el index 40618e9ef38..1fae0ba6ba4 100644 --- a/lisp/elec-pair.el +++ b/lisp/elec-pair.el @@ -260,7 +260,7 @@ electric-pair-syntax-info (list ?\( (cdr direct) t string-or-comment))) (reverse (list ?\) (car reverse) t string-or-comment))))) -(defun electric-pair--insert (char) +(defun electric-pair--insert (char times) (let ((last-command-event char) (blink-matching-paren nil) (electric-pair-mode nil) @@ -271,7 +271,7 @@ electric-pair--insert ;; us to add these newlines, and is probably about to kick in ;; again after we add the closer. (electric-layout-allow-duplicate-newlines t)) - (self-insert-command 1))) + (self-insert-command times))) (defun electric-pair--syntax-ppss (&optional pos where) "Like `syntax-ppss', but sometimes fallback to `parse-partial-sexp'. @@ -455,7 +455,8 @@ electric-pair-inhibit-if-helps-balance (atomic-change-group ;; Don't use `delete-char'; that may modify the head of the ;; undo list. - (delete-region (point) (1- (point))) + (delete-region (- (point) (prefix-numeric-value current-prefix-arg)) + (point)) (throw 'done (cond ((eq ?\( syntax) @@ -474,25 +475,26 @@ electric-pair-skip-if-helps-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) - (unwind-protect - (progn - (delete-char -1) - (cond ((eq syntax ?\)) - (let* ((pair-data - (electric-pair--balance-info - -1 s-or-c)) - (innermost (car pair-data)) - (outermost (cdr pair-data))) - (and - (cond ((car outermost) - (car innermost)) - ((car innermost) - (not (eq (cdr outermost) pair))))))) - ((eq syntax ?\") - (electric-pair--inside-string-p char)))) - (insert char))))) + (let ((num (prefix-numeric-value current-prefix-arg))) + (pcase (electric-pair-syntax-info char) + (`(,syntax ,pair ,_ ,s-or-c) + (unwind-protect + (progn + (delete-char (- num)) + (cond ((eq syntax ?\)) + (let* ((pair-data + (electric-pair--balance-info + (- num) s-or-c)) + (innermost (car pair-data)) + (outermost (cdr pair-data))) + (and + (cond ((car outermost) + (car innermost)) + ((car innermost) + (not (eq (cdr outermost) pair))))))) + ((eq syntax ?\") + (electric-pair--inside-string-p char)))) + (insert (make-string num char))))))) (defun electric-pair-default-skip-self (char) (if electric-pair-preserve-balance @@ -527,11 +529,14 @@ electric-pair-post-self-insert-function `electric-pair-inhibit-predicate', `electric-pair-skip-self' and `electric-pair-skip-whitespace' (which see)." (let* ((pos (and electric-pair-mode (electric--after-char-pos))) + (num (when pos (prefix-numeric-value current-prefix-arg))) + (beg (when num (- pos num))) (skip-whitespace-info)) (pcase (electric-pair-syntax-info last-command-event) (`(,syntax ,pair ,unconditional ,_) (cond ((null pos) nil) + ((zerop num) nil) ;; Wrap a pair around the active region. ;; ((and (memq syntax '(?\( ?\) ?\" ?\$)) (use-region-p)) @@ -545,23 +550,24 @@ electric-pair-post-self-insert-function (>= (mark) (point)))) (save-excursion (goto-char (mark)) - (electric-pair--insert pair)) - (delete-region pos (1- pos)) - (electric-pair--insert pair) + (electric-pair--insert pair num)) + (delete-region beg pos) + (electric-pair--insert pair num) (goto-char (mark)) - (electric-pair--insert last-command-event))) + (electric-pair--insert last-command-event num))) ;; Backslash-escaped: no pairing, no skipping. ((save-excursion - (goto-char (1- pos)) + (goto-char beg) (not (zerop (% (skip-syntax-backward "\\") 2)))) - nil) + (let ((current-prefix-arg (1- num))) + (electric-pair-post-self-insert-function))) ;; 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-command-event)) + (goto-char pos) + (funcall electric-pair-skip-self last-command-event)) electric-pair-skip-self)) (save-excursion (when (and (not (and unconditional @@ -580,19 +586,19 @@ electric-pair-post-self-insert-function ;; 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)) + (delete-region beg (if (eq skip-whitespace-info 'chomp) + (point) + pos)) + (forward-char num)) ;; 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)))))))) + (goto-char pos) + (funcall electric-pair-inhibit-predicate + last-command-event))))) + (save-excursion (electric-pair--insert pair num)))))))) (defun electric-pair-open-newline-between-pairs-psif () "Honor `electric-pair-open-newline-between-pairs'. @@ -604,7 +610,8 @@ electric-pair-open-newline-between-pairs-psif (< (1+ (point-min)) (point) (point-max)) (eq (save-excursion (skip-chars-backward "\t\s") - (char-before (1- (point)))) + (char-before (- (point) + (prefix-numeric-value current-prefix-arg)))) (matching-paren (char-after)))) (save-excursion (newline 1 t)))) @@ -618,7 +625,7 @@ electric-pair-delete-pair ARG and KILLP are passed directly to `backward-delete-char-untabify', which see." (interactive "*p\nP") - (delete-char 1) + (delete-char arg) (backward-delete-char-untabify arg killp)) (defvar electric-pair-mode-map diff --git a/test/lisp/electric-tests.el b/test/lisp/electric-tests.el index 720313511a6..76c18594b26 100644 --- a/test/lisp/electric-tests.el +++ b/test/lisp/electric-tests.el @@ -653,6 +653,22 @@ autowrapping-7 (skip-chars-backward "\"") (mark-sexp -1))) +(define-electric-pair-test autowrapping-multi-1 + "foo" "(" :expected-string "(((((foo)))))" :expected-point 6 + :bindings '((current-prefix-arg . 5)) + :fixture-fn (lambda () + (electric-pair-mode 1) + (mark-sexp 1))) + +(define-electric-pair-test autowrapping-multi-2 + "foo" ")" :expected-string "(((((foo)))))" :expected-point 14 + :bindings '((current-prefix-arg . 5)) + :fixture-fn (lambda () + (electric-pair-mode 1) + (goto-char (point-max)) + (skip-chars-backward "\"") + (mark-sexp -1))) + ;;; Electric quotes (define-electric-pair-test electric-quote-string -- 2.46.0 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sat Sep 21 13:25:34 2024 Received: (at submit) by debbugs.gnu.org; 21 Sep 2024 17:25:34 +0000 Received: from localhost ([127.0.0.1]:40289 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ss3rS-0004fr-12 for submit@debbugs.gnu.org; Sat, 21 Sep 2024 13:25:34 -0400 Received: from lists.gnu.org ([209.51.188.17]:32868) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ss3rP-0004fc-Fj for submit@debbugs.gnu.org; Sat, 21 Sep 2024 13:25:32 -0400 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 1ss3r4-0001EH-Dn for bug-gnu-emacs@gnu.org; Sat, 21 Sep 2024 13:25:10 -0400 Received: from out-174.mta0.migadu.com ([2001:41d0:1004:224b::ae]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ss3r2-0005FP-1T for bug-gnu-emacs@gnu.org; Sat, 21 Sep 2024 13:25:10 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=breatheoutbreathe.in; s=key1; t=1726939503; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=y6Pw7wR1zVt+awK7/mCHQgBWj8cK0yuVEwwErHHSe78=; b=KdBZVoGZ4l9Z35DxrplZ0TH4XnH4SiPbTRMHnGHVUMqTNBCtGpQ9+cAH5uvvQpJeveiEdy abtfcFAPZ5RtcSWXx1oTLyc4G+6PFpN5N9AkzfAQNx/LMFGq/pcSiVGMXnG/vIaTNxv+bx zajfPISDAY274oNUz0tH6bKwNbLoXJE= From: Joseph Turner To: Eshel Yaron Subject: Re: bug#72437: Unexpected behavior when inserting with prefix arg in electric-pair-mode In-Reply-To: (Eshel Yaron's message of "Sat, 21 Sep 2024 12:23:55 +0200") References: <87le1edqqm.fsf@breatheoutbreathe.in> <86h6c2ug0p.fsf@gnu.org> <86a5htvclm.fsf@gnu.org> <86zfpttpfl.fsf@gnu.org> <20F64DCD-929F-4B4C-BF85-ABE26FC7C995@breatheoutbreathe.in> <87plp0w7g7.fsf@breatheoutbreathe.in> Date: Sat, 21 Sep 2024 10:24:57 -0700 Message-ID: <87o74gsyvq.fsf@breatheoutbreathe.in> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Migadu-Flow: FLOW_OUT Received-SPF: pass client-ip=2001:41d0:1004:224b::ae; envelope-from=joseph@breatheoutbreathe.in; helo=out-174.mta0.migadu.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.4 (-) X-Debbugs-Envelope-To: submit Cc: 72437@debbugs.gnu.org, "Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors" , Eli Zaretskii , Stefan Monnier X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.4 (--) --=-=-= Content-Type: text/plain Eshel Yaron writes: > Joseph Turner writes: > >> Joseph Turner writes: >> >>> On August 13, 2024 10:07:23 PM PDT, Eshel Yaron wrote: >>>>Hi Stefan, >>>> >>>>Stefan Monnier writes: >>>> >>>>>> Let's hear what Stefan thinks (and anyone else who has an >>>>>> opinion or some case other than electric-pair-mode). >>>>> >>>>> I think the requested behavior makes a lot of sense, but I lost touch >>>>> with the way elec-pair works and interacts with other electric modes, so >>>>> I'm not sure how to make it work without breaking other things. >>>> >>>>In case you missed it, the patch I shared upthread might give you >>>>some ideas. It implements the requested behavior, safely, I think. >>>>So I would just ask Joseph to try it out for a while and see if it >>>>works as expected and if any other issues crop up :) >>> >>> Thanks for this patch! I am testing it in my daily config. So far >>> so good, and I'll report back after a few weeks of usage. >> >> I have been running this patch for over a month with no issue. > > That's great, thanks for testing it and for reporting back! > >> I vote to merge it! > > Agreed. Here's a full patch with tests, doc updates and a NEWS entry: Nice! How about also adding a test like the attached patch? --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Test-behavior-with-prefix-argument.patch >From 414a4b1fa09b0b976e74144430871b1b5a9ddbbe Mon Sep 17 00:00:00 2001 From: Joseph Turner Date: Sat, 21 Sep 2024 10:23:07 -0700 Subject: [PATCH] Test behavior with prefix argument * test/lisp/electric-tests.el (electric-pair-backspace-2) --- test/lisp/electric-tests.el | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/lisp/electric-tests.el b/test/lisp/electric-tests.el index 720313511a6..f1742fe3f0b 100644 --- a/test/lisp/electric-tests.el +++ b/test/lisp/electric-tests.el @@ -562,6 +562,14 @@ electric-pair-backspace-1 (electric-pair-delete-pair 1) (should (equal "" (buffer-string)))))) +(ert-deftest electric-pair-backspace-2 () + (save-electric-modes + (with-temp-buffer + (insert "((()))") + (goto-char 4) + (electric-pair-delete-pair 2) + (should (equal "()" (buffer-string)))))) + ;;; Undoing (ert-deftest electric-pair-undo-unrelated-state () -- 2.46.0 --=-=-=-- From debbugs-submit-bounces@debbugs.gnu.org Sun Sep 22 04:21:41 2024 Received: (at 72437) by debbugs.gnu.org; 22 Sep 2024 08:21:41 +0000 Received: from localhost ([127.0.0.1]:40841 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ssHqf-0002nq-Ea for submit@debbugs.gnu.org; Sun, 22 Sep 2024 04:21:41 -0400 Received: from mail.eshelyaron.com ([107.175.124.16]:39626 helo=eshelyaron.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ssHqc-0002nb-6b; Sun, 22 Sep 2024 04:21:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eshelyaron.com; s=mail; t=1726993276; bh=sKUA7DlbK8u82dIh2M5l8qRX12Z1dZxGfj/PuFH98kQ=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=tRRz4tyrbRZcKuazUcmP678AOwIEfVWvTTXYuzaMwPaaNCbBzThf33TlWS+CK1+lo U3mRZNk0jRqBN1SKk36f6kgJiLWz1/9bdiGmsjcvpoQoMKnWmYWwo+vsngKTxlReob hL7XOsJetigkfG2qqg4/iao1trADjE5QpYisO/xwOq1XddIq/Bi8pYINiw+txU7Ki8 4tqNqH/O7N2LnKxmkLhk/Ew7mZB7Kzeuai7bRXezU8Ae5j6oXK9WiT77lt4kOLFy3o pfv2gme99aAF+JFxDVAN9UXaTaOlVelGZpCwmpx4ILxtqj0Kgc55Ct/WOVDDwFYAum TZh/Z5R/89S+w== From: Eshel Yaron To: Joseph Turner Subject: Re: bug#72437: Unexpected behavior when inserting with prefix arg in electric-pair-mode In-Reply-To: <87o74gsyvq.fsf@breatheoutbreathe.in> (Joseph Turner's message of "Sat, 21 Sep 2024 10:24:57 -0700") References: <87le1edqqm.fsf@breatheoutbreathe.in> <86h6c2ug0p.fsf@gnu.org> <86a5htvclm.fsf@gnu.org> <86zfpttpfl.fsf@gnu.org> <20F64DCD-929F-4B4C-BF85-ABE26FC7C995@breatheoutbreathe.in> <87plp0w7g7.fsf@breatheoutbreathe.in> <87o74gsyvq.fsf@breatheoutbreathe.in> Date: Sun, 22 Sep 2024 10:21:13 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 72437 Cc: 72437@debbugs.gnu.org, Eli Zaretskii , Stefan Monnier X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) close 72437 31.1 quit Joseph Turner writes: > Eshel Yaron writes: > >> Joseph Turner writes: >> >>> Joseph Turner writes: >>> >>>> On August 13, 2024 10:07:23 PM PDT, Eshel Yaron wrote: >>>>>Hi Stefan, >>>>> >>>>>Stefan Monnier writes: >>>>> >>>>>>> Let's hear what Stefan thinks (and anyone else who has an >>>>>>> opinion or some case other than electric-pair-mode). >>>>>> >>>>>> I think the requested behavior makes a lot of sense, but I lost touch >>>>>> with the way elec-pair works and interacts with other electric modes, so >>>>>> I'm not sure how to make it work without breaking other things. >>>>> >>>>>In case you missed it, the patch I shared upthread might give you >>>>>some ideas. It implements the requested behavior, safely, I think. >>>>>So I would just ask Joseph to try it out for a while and see if it >>>>>works as expected and if any other issues crop up :) >>>> >>>> Thanks for this patch! I am testing it in my daily config. So far >>>> so good, and I'll report back after a few weeks of usage. >>> >>> I have been running this patch for over a month with no issue. >> >> That's great, thanks for testing it and for reporting back! >> >>> I vote to merge it! >> >> Agreed. Here's a full patch with tests, doc updates and a NEWS entry: > > Nice! How about also adding a test like the attached patch? Looks good :) I've now pushed my patch to master as a7192fd7b73 followed by your test addition as 0f4c09d2678. And with that, I'm closing this bug. Best, Eshel From debbugs-submit-bounces@debbugs.gnu.org Sun Sep 22 15:33:53 2024 Received: (at 72437) by debbugs.gnu.org; 22 Sep 2024 19:33:53 +0000 Received: from localhost ([127.0.0.1]:42783 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ssSLB-0005sw-77 for submit@debbugs.gnu.org; Sun, 22 Sep 2024 15:33:53 -0400 Received: from out-170.mta1.migadu.com ([95.215.58.170]:27313) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ssSL8-0005sg-BA for 72437@debbugs.gnu.org; Sun, 22 Sep 2024 15:33:51 -0400 Date: Sun, 22 Sep 2024 12:32:37 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=breatheoutbreathe.in; s=key1; t=1727033571; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HZPF2gu5cjlCyI+xOSQmfegnF/tI4ozJahNV0cr1gAE=; b=ngywU7TV0BdOx3BIEZrInAY3hhUJsWX2lMmcG23F9VNhdlSEIL8kJpaW/x857QCY6XSkTz dNHAsid3A7vehAYclRnQWr2jyrxty7fxxDWc5mAcqz6rxhI3QV9hK7K1ZoZyCO8i7eMJVL Ho5o8xSqP7RKIlawVPBGyn6MPCNvzqY= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Joseph Turner To: Eshel Yaron Subject: =?US-ASCII?Q?Re=3A_bug=2372437=3A_Unexpected_behavior_when_ins?= =?US-ASCII?Q?erting_with_prefix_arg_in_electric-pair-mode?= In-Reply-To: References: <87le1edqqm.fsf@breatheoutbreathe.in> <86h6c2ug0p.fsf@gnu.org> <86a5htvclm.fsf@gnu.org> <86zfpttpfl.fsf@gnu.org> <20F64DCD-929F-4B4C-BF85-ABE26FC7C995@breatheoutbreathe.in> <87plp0w7g7.fsf@breatheoutbreathe.in> <87o74gsyvq.fsf@breatheoutbreathe.in> Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 72437 Cc: 72437@debbugs.gnu.org, Eli Zaretskii , Stefan Monnier X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) On September 22, 2024 1:21:13 AM PDT, Eshel Yaron wr= ote: >close 72437 31=2E1 >quit > >Joseph Turner writes: > >> Eshel Yaron writes: >> >>> Joseph Turner writes: >>> >>>> Joseph Turner writes: >>>> >>>>> On August 13, 2024 10:07:23 PM PDT, Eshel Yaron wrote: >>>>>>Hi Stefan, >>>>>> >>>>>>Stefan Monnier writes: >>>>>> >>>>>>>> Let's hear what Stefan thinks (and anyone else who has an >>>>>>>> opinion or some case other than electric-pair-mode)=2E >>>>>>> >>>>>>> I think the requested behavior makes a lot of sense, but I lost to= uch >>>>>>> with the way elec-pair works and interacts with other electric mod= es, so >>>>>>> I'm not sure how to make it work without breaking other things=2E >>>>>> >>>>>>In case you missed it, the patch I shared upthread might give you >>>>>>some ideas=2E It implements the requested behavior, safely, I think= =2E >>>>>>So I would just ask Joseph to try it out for a while and see if it >>>>>>works as expected and if any other issues crop up :) >>>>> >>>>> Thanks for this patch! I am testing it in my daily config=2E So fa= r >>>>> so good, and I'll report back after a few weeks of usage=2E >>>> >>>> I have been running this patch for over a month with no issue=2E >>> >>> That's great, thanks for testing it and for reporting back! >>> >>>> I vote to merge it! >>> >>> Agreed=2E Here's a full patch with tests, doc updates and a NEWS entr= y: >> >> Nice! How about also adding a test like the attached patch? > >Looks good :) > >I've now pushed my patch to master as a7192fd7b73 followed by your test >addition as 0f4c09d2678=2E And with that, I'm closing this bug=2E Thank you!! Joseph From unknown Mon Aug 18 21:17:11 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Mon, 21 Oct 2024 11:24:05 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator