Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After turning off paredit-mode, can't type unbalanced curly brace } #504

Open
rnikander opened this issue Jan 8, 2019 · 5 comments
Open

Comments

@rnikander
Copy link

Expected behavior

Turn on paredit-mode, then turn it off, and be able to type unbalanced characters ()[]{}.

Actual behavior

Can't type an unbalanced }

Steps to reproduce the problem

Open a clojure file, run M-x paredit-mode, then run it again to turn it off. Try to type a }. Something of paredit mode persists and prevents it.

Environment & Version information

clojure-mode version information

Clojure Mode 5.10.0
I see this is package list, but oddly, clojure-mode-display-version is showing clojure-mode (version nil) in the minibuffer.

Emacs version

Emacs 25.3.1

Operating system

macOS 10.13.6

@carlosgeos
Copy link
Contributor

This function might have something to do with it:

(defun clojure-paredit-setup (&optional keymap)
"Make \"paredit-mode\" play nice with `clojure-mode'.
If an optional KEYMAP is passed the changes are applied to it,
instead of to `clojure-mode-map'.
Also advice `paredit-convolute-sexp' when used on a let form as drop in
replacement for `cljr-expand-let`."
(when (>= paredit-version 21)
(let ((keymap (or keymap clojure-mode-map)))
(define-key keymap "{" #'paredit-open-curly)
(define-key keymap "}" #'paredit-close-curly))
(add-to-list 'paredit-space-for-delimiter-predicates

@rnikander
Copy link
Author

Probably needs a another function to undo this when leaving paredit-mode.

@bbatsov
Copy link
Member

bbatsov commented Mar 11, 2019

paredit's config should have no effect if paredit is disabled.

@wandersoncferreira
Copy link
Contributor

@bbatsov I was able to reproduce the problem, and in fact there are side effects in the code above. The defined keys are not restored when the paredit-mode is disabled.

I wrote the following code to restore the desired behavior. If you think this is a proper solution, I can submit a PR with the changes.

(defun clojure-paredit-restore-default-keys (&optional keymap)
  "Disabling \"paredit-mode\" should restore the `paredit` defined keys on `clojure-mode-map'.

If an optional KEYMAP is passed the changes are applied to it,
instead of to `clojure-mode-map'."
  (when (>= paredit-version 21)
    (let ((keymap (or keymap clojure-mode-map)))
      (define-key keymap "{" #'self-insert-command)
      (define-key keymap "}" #'self-insert-command))))

(defadvice paredit-mode (after toggle-clojure-setup-mode activate)
  "Advice to restore defined `paredit' keys on the `clojure-mode-map' when `paredit-mode' is disabled."
  (when (not paredit-mode)
    (clojure-paredit-restore-default-keys)))

@wandersoncferreira
Copy link
Contributor

wandersoncferreira commented Jul 21, 2019

I was refactoring my proposed solution and just noticed that I'm not considering the case where a keymap was provided to the clojure-paredit-setup function. To proper solve this case, I would need to provide the same keymap as an argument to my defadvice function, I don't know if this is possible in elisp, though.

Something link:

(defun clojure-paredit-setup (&optional keymap)
....
    (let ((keymap (or keymap clojure-mode-map)))
      (define-key keymap "{" #'paredit-open-curly)
      (define-key keymap "}" #'paredit-close-curly)
      ;; added advice
      (advice-add 'paredit-mode :after (lambda (keymap) (clojure-paredit-restore-default-keys keymap))))
....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants