[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: electric-pair-mode as a minor mode?

From: João Távora
Subject: Re: electric-pair-mode as a minor mode?
Date: Fri, 27 Mar 2015 11:18:48 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (windows-nt)

Hi Stefan and Yuri,

Stefan Monnier <address@hidden> writes:

>> I'd like to disable electric-pair-mode in certain buffers.
>> Probably the most important example is the minibuffer.
> [ I'm curious to know more about those isearch and minibuffer cases
>   because I haven't bumped into them.  Not that it makes any difference
>   to the following.  ]

I also don't see it. I though that, rightfully so, the syntax in
isearch-mode is tweaked so that parens don't match there.

This is probably the case in most minibuffers (though one still has to
deal with the `electric-pair-pairs' overrider, but not isearch, where
most keys are mapped to `isearch-printing-char' and not
`self-insert'. And this is why they are pair-free.

>    (electric-pair-mode 1)
>    (setq-default electric-pair-mode nil)
>    (add-hook 'foo-mode-hook
>              (lambda () (setq-local electric-pair-mode t)))

I would do it like this. Though I didn't test much, it looks less hacky
to me:

   (electric-pair-mode 1)
   (add-hook 'foo-mode-hook
             (lambda ()
               (setq-local electric-pair-pairs nil)
               (setq-local electric-pair-text-pairs nil)
               (setq-local electric-pair-inhibit-predicate #'identity)))

So electric-pair-mode is still active (you still get autoskipping if the
syntax determines it), but autopairing is inhibited. Is this still

But making electric-pair-local-mode also sounds good to me.

>> When editing regular text, as opposed to code, I also occasionally
>> switch it off because I find it distracting.
> I'm pretty sure that can be done fairly easily, by fixing a few
> concrete cases.

Can you name some?

`electric-pair-pairs' and `electric-pair-text-pairs' which mean "always
always pair these" are the "eager" cases, in my opinion.

At least `electric-pair-pairs' could be made to default to nil, and
probably `electric-pair-text-pairs' too. The snippet above becomes

If I recall correctly, `electric-pair-pairs' was kept for backward
compatibility with the original implementation of `electric-pair-mode'
that didn't deduce its behaviour from the mode's syntax.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]