bug#50236: 27.2; electric-pair-mode is inconvenient in comint

Andrew Hyatt <[email protected]> Wed, 05 Aug 2026 22:07:20 -0400
Newsgroups gmane.emacs.bugs
Message-ID <[email protected]>
Augusto Stoffel <[email protected]> writes:

> On Sun, 19 Jul 2026, Andrew Hyatt wrote:
>
>> Augusto Stoffel <[email protected]> writes: 
>>
>>  Hi Andrew, 
>>
>>  in your proposed patch, why did you choose to change
>>  electric-pair-post-self-insert-function directly and not
>>  electric-pair-default-skip-self (or even define a skip-self function specifically for
>>  comint)? 
>>
>> Isn't skip-self for avoiding two closing parens in a row? This doesn't seem related to the
>> problem. 
>
> It is definitely related to the issue I originally reported in this bug
> [1].
>
> My suggestion was to define e.g.
>
>    (defun electric-pair-skip-in-field (char)
>      (save-restriction
>        (narrow-to-region (field-beginning) (field-end))
>        (electric-pair-default-skip-self char)))
>
> and then, in comint-mode and wherever else it's suitable,
>
>    (setq-local electric-pair-skip-self #'electric-pair-skip-in-field)
>
> This fixes at least my test case.  What is again your test case?

It's both your case, but also one with quotes.  Not only does your
original test case also have an issue with quotes, but also if there's a
quote, and you have `electric-pair-preserve-balance` on, if you type a
quote and there's already an unmatched one in a previous input, or in
machine output, it will not attempt to quote it.  And if you then press
it again, it will type two quotes.

I believe just changing the skip-self behavior won't fix this problem
with preserving balance incorrectly.

>
> [1] https://yhetil.org/emacs-bugs/[email protected]/