2

I want to enable paredit-mode on all clojure, cljs and elisp buffers by default, which is probably going to happen through the .spacemacs file. This is what I have so far in the user-config function of my .spacemacs:

;; paredit autoload
  (autoload 'enable-paredit-mode "paredit" "Turn on pseudo-structural editing of Lisp code." t)
  (add-hook 'clojure-mode #'enable-paredit-mode)
  (add-hook 'clojurescript-mode #'enable-paredit-mode)

But it doesn't really work. What am I doing wrong?

-- EDIT -- I've tried

;; paredit autoload
  (autoload 'enable-paredit-mode "paredit" "Turn on pseudo-structural editing of Lisp code." t)
  (add-hook 'clojure-mode-hook 'enable-paredit-mode)
  (add-hook 'clojurescript-mode-hook 'enable-paredit-mode)

and

;; paredit autoload
  (autoload 'enable-paredit-mode "paredit" "Turn on pseudo-structural editing of Lisp code." t)
  (add-hook 'clojure-mode-hook #'enable-paredit-mode)
  (add-hook 'clojurescript-mode-hook #'enable-paredit-mode)

and neither works.

-- EDIT --

The value of clojure-mode-hook is:

(#f(compiled-function
    ()
    #<bytecode 0x464d0c01>)
   (lambda nil
     (set
      (make-local-variable 'sesman-system)
      'CIDER))
   clojure--check-wrong-major-mode clj-refactor-mode cider-mode spacemacs//init-jump-handlers-clojure-mode)
2
  • I don’t know what you’ve done wrong but clearly your hook to enable paredit has not made it into clojure-mode-hook. Maybe you need to wrap those in an eval-after-load. Do you have any evidence that the code you’ve written actually runs? Commented May 27, 2020 at 13:58
  • To help debug, instead of trying fancy things with autoloading, just require all the modes you need (clojure-mode, clojurescript-mode, paredit), then add your hooks (and check their value). Use C-x C-e to interactively evaluate expressions as you go, and C-h v to check the value of variables. Commented Feb 23, 2021 at 4:00

3 Answers 3

0

I think in your first attempt you wrote clojure-mode instead of closure-mode-hook, and likewise for clojurescript-mode. But changing it didn’t fix things. My best guess is that your changes to those hooks get clobbered when the mode loads.

Try using eval-after-load to only make the change after the hooks are defined:

(autoload 'enable-paredit-mode "paredit" "Turn on pseudo-structural editing of Lisp code." t)
(eval-after-load ‘clojure-mode
  '((add-hook 'clojure-mode-hook #'enable-paredit-mode)
    (add-hook 'clojurescript-mode-hook #'enable-paredit)))
9
  • I tried that but it didn't work Commented May 27, 2020 at 13:47
  • If you want help you will need to be more descriptive with what is not working. You should also explain what else you have tried. Please update your question accordingly with the code that didn’t work. The code in your question definitely won’t work. Also, what is the value of clojure-mode-hook? Commented May 27, 2020 at 13:50
  • How do you find the value of clojure-mode-hook? Commented May 27, 2020 at 13:53
  • Do C-h v clojure-mode-hook RET Commented May 27, 2020 at 13:54
  • 1
    That is not sufficient information for one to debug your problem. What was the value of clojure-mode-hook after you tied it? Do you have any evidence that the code you’ve added to your .spacemacs has been evaluated? Commented May 27, 2020 at 16:15
0

One possible cause of the problem is the content of the source code file rather than the Emacs config.

I don't know closure, but I had encountered a similar issue with lisp (which costed me lots of time trying to fix the Emacs config). For a minimal example, if you create a one-liner file test.el with an imbalanced parenthesis:

(1 + 2 

After saving and reopening the file, paredit mode will be missing. Upon closer investigation, there is an error:

File mode specification error: (user-error Unmatched bracket or quote)

in the Message buffer. (Tested in Emacs 28.1 under Ubuntu 22.04)

This rarely happens as paredit keeps the parenthesis balanced (until you break the balance in a manner unexpected by paredit ..). Another symptom of this issue is that the cursor is parked at the problem site (where the imbalance happens) rather than the beginning of the source file.

0

Don't enable paredit in Spacemacs.

I'm surprised no one has mentioned this yet, but as great as paredit is, it doesn't play well with evil which Spacemacs defaults to. Instead of using paredit, Spacemacs defaults to using something called evil-lisp-state to do structural editing for various lisps.

https://github.com/syl20bnr/evil-lisp-state

In Spacemacs, SPC k will give you access to evil-lisp-state functionality.

If you're using Spacemacs without evil, disregard this answer.

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.