2

I use Emacs 24.3.1 and AUCTeX. I switched on the electric-pair-mode in LaTeX-buffers. The only time I would really like to disable it in the minibuffer while inserting math-mode parentheses via the \left and \right commands. For these commands in Emacs, I use \ as TeX-electric macro.

My question would be if there is an easy way to disable the electric-pair-mode inside the minibuffer? Or do I maybe use an inconvenient setup for putting parentheses into equations?

3
  • The echo area is for output, not input. Do you mean the minibuffer? If so, please edit.
    – Drew
    Commented Jul 1, 2015 at 15:24
  • You say that "The only time I would really like to disable it is while inserting math-mode parenthesis via the \left and \right commands." Did you mean enable?
    – elethan
    Commented Dec 28, 2015 at 17:14
  • I would like to disable the electric pairing, when I enter the minibuffer after inserting \left inside the ordinary latex-mode buffer.
    – jjokella
    Commented Dec 28, 2015 at 19:22

2 Answers 2

4

Here is a trick that I learned from this answer to only use electric-pair-mode with specifically whitelisted modes:

(defvar my-electic-pair-modes '(python-mode org-mode))

(defun my-inhibit-electric-pair-mode (char)
  (not (member major-mode my-electic-pair-modes)))

(setq electric-pair-inhibit-predicate #'my-inhibit-electric-pair-mode)

Then you can add any mode that you want to use electric-pair-mode for to my-electric-pair-modes.

I have tested this, and it removes the annoyance of having parens pair in the minibuffer. In your case you can replace python-mode with latex-mode or whatever modes you want.

1
  • 1
    I accepted your solution - it worked well for my problem: Since the minibuffer has its own major-mode, electric pairs are disabled by default. Additionally, I feel like I have better control over the electric-pair-mode through implementing the list of allowed modes like you suggested - thanks.
    – jjokella
    Commented Dec 28, 2015 at 19:32
4

To specifically disable electric-pair-mode in the minibuffer change elethan's example to use the minibufferp function. Below is the relevant part from my Emacs configuration:

;; Enable smart paring
(electric-pair-mode)

(defun pvj/inhibit-electric-pair-mode (char)
  (minibufferp))

(setq electric-pair-inhibit-predicate #'pvj/inhibit-electric-pair-mode)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.