2

When I open a Clojure file, and I'm not using Paredit, I expect to be able to type unbalanced parentheses and brackets. I can type any of these characters: ()[]{, balanced on not. But if I try to type a } that has no matching start {, it won't let me.

Why is this? And how do I turn it off? I expect this type of behavior in paredit-mode, but outside of that mode I want to be free to type any characters.

GNU Emacs 25.3.1 on macOS. Clojure mode 5.8.2.

3
  • 2
    Do you see this if you start Emacs with emacs -Q (no init file)? If so, please provide a step-by-step recipe to reproduce it. If not, bisect your init file to find the culprit. Commented Jan 7, 2019 at 16:07
  • 2
    I can't reproduce this in Emacs 27.0.50 and Clojure mode 20190105 from Melpa. It's possible it's a problem with the particular versions you're using, but more likely a problem in your init as @Drew suggests Commented Jan 7, 2019 at 18:39
  • 3
    Okay, thanks. I just noticed that it doesn't happen until I enable paredit-mode and then try to turn it off. So it seems like some remnant of paredit stays around and prevents the } character. Commented Jan 7, 2019 at 20:08

2 Answers 2

2

The problem only occurs after you've turned paredit on and off: this is because clojure-mode adds a hook to paredit-mode, and that hook adds some paredit-mode keybindings to the clojure-mode map.

In other words, turning on paredit-mode makes changes to clojure-mode keybindings and those changes stick even if you turn off paredit-mode. The really surprising thing is if you edit a file in clojure-mode, then use paredit-mode in a different file, returning to the clojure file you'll get the paredit keybindings for "{" and "}".

That's arguably a bug in clojure-mode.

Update:

This has been reported as a bug (not by me), although I'm not sure if the maintainer agrees: https://github.com/clojure-emacs/clojure-mode/issues/504

1

You can insert unbalanced parentheses with C-q (quoted-insert).

If you really don't want Clojure Mode to bind { and } to ParEdit keys, here is a work-around:

(add-hook 'clojure-mode-hook (lambda () (remove-hook 'paredit-mode-hook #'clojure-paredit-setup))) 

(You need to restart Emacs, since once clojure-paredit-setup runs, the keys is set)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.