2

According to https://www.emacswiki.org/emacs/AutoPairs the package smartparens supports an electric pair of any length for example \{.

My question about the possibility that the built-in electric-pair-mode can do it. I tried this without success:

(add-hook 'LaTeX-mode-hook
              (lambda ()
                (define-key LaTeX-mode-map "\\{" 'electric-pair)))
Drew
  • 75,699
  • 9
  • 109
  • 225
Name
  • 7,689
  • 4
  • 38
  • 84
  • 1
    AUCTeX doesn't play nicely with `electric-pair-mode`, this minor mode is actually disabled in AUCTeX if `LaTeX-electric-left-right-brace` is non nil. – giordano Sep 15 '16 at 10:56
  • @giordano if you have a solution purely based on auctex or any other suggestion (e.g. using another package) I would be grateful. Otherwise I am happy to use smartparens. – Name Sep 15 '16 at 10:59

1 Answers1

4

AUCTeX has a bultin support for pairing braces, and \{...\} is in the default set of supported braces. In order to enable this feature, just set LaTeX-electric-left-right-brace to non nil, either with customize interface (M-x customize-variable RET LaTeX-electric-left-right-brace RET) or by adding the following line to your init file:

(setq LaTeX-electric-left-right-brace t)

This is much more advanced than any other generic mode for pairing braces, because it is able to do something like this:

\Bigl\{  →  \Bigl\{\Bigr\}
giordano
  • 3,245
  • 13
  • 19
  • 1
    If one likes to temporary disable inserting electric braces, one use `C-q` or `C-u 1` before typing `{`, `(`, `[`, etc. – Name Sep 22 '16 at 09:26
  • I enable smartparens-mode globally, but since LaTeX-electric-left-right-brace is more useful for tex file, so I disable sp using (turn-off-smartparens-mode) inside LaTeX-mode-hook, but sp will always be triggered somehow after some time of editing tex file, and I don't know how to completely in LaTeX-mode. Any idea? – CodyChan Oct 09 '16 at 08:22
  • No, I don't use smart parens, sorry. – giordano Oct 09 '16 at 10:30