Skip to content

Add paredit setup for edn-mode#700

Merged
bbatsov merged 1 commit intoclojure-emacs:masterfrom
grzm:grzm/edn-paredit-setup
Mar 18, 2026
Merged

Add paredit setup for edn-mode#700
bbatsov merged 1 commit intoclojure-emacs:masterfrom
grzm:grzm/edn-paredit-setup

Conversation

@grzm
Copy link
Contributor

@grzm grzm commented Mar 17, 2026

Like clojure-mode, edn-mode needs to coax paredit to auto-pair curly braces.

I've replicated the minimum set of features from the existing clojure-paredit-setup to edn-paredit-setup to allow auto-pair functionality for curly braces ({)

I tried to a test to confirm the behavior, but my emacs/buttercup testing skills aren't currently up to the task. Here's what I (naïvely) tried (added to edn-mode-indentation-test.el for experimentation).

(require 'paredit)

(describe "edn-mode paredit support"
          (describe "auto-pairs curly braces"
                    (it "should add a closing brace with an opening brace is inserted"
                        (with-edn-buffer ""
                                         (paredit-mode)
                                         (insert "{")
                                         (expect (buffer-string) :to-equal "{}")))))

Before submitting a PR mark the checkboxes for the items you've done (if you
think a checkbox does not apply, then leave it unchecked):

  • The commits are consistent with our contribution guidelines.
  • [-] You've added tests (if possible) to cover your change(s). Bugfix, indentation, and font-lock tests are extremely important!
  • You've run M-x checkdoc and fixed any warnings in the code you've written.
  • You've updated the changelog (if adding/changing user-visible functionality).
  • [n/a] You've updated the readme (if adding/changing user-visible functionality).

Thanks!

Copy link
Member

@bbatsov bbatsov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! The problem diagnosis is correct — edn-mode-map has prog-mode-map as parent, not clojure-mode-map, so the paredit {/} bindings from clojure-paredit-setup don't reach EDN buffers.

However, I think we can fix this without duplicating the setup function. The root cause is that clojure-paredit-setup defaults to clojure-mode-map when no keymap is passed. If we change it to default to (current-local-map) instead, the existing paredit-mode-hook (which edn-mode already inherits from clojure-mode) will just work for all derived modes automatically.

Something like:

(let ((keymap (or keymap (current-local-map))))

That single-line change should fix EDN mode (and any future derived modes) without needing edn-paredit-setup at all.

@grzm grzm force-pushed the grzm/edn-paredit-setup branch from 09f018e to e18ec2e Compare March 18, 2026 03:31
@grzm
Copy link
Contributor Author

grzm commented Mar 18, 2026

That's the knowledge your years of emacs-lisp experience provides :) Thanks for explaining. I've updated the patch as suggested. (And thanks for your patience!)

CHANGELOG.md Outdated

## master (unreleased)

* Update current-local-map during clojure-paredit-setup to work with edn-mode
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should also add a "Bugs Fixed" heading for this entry.

replacement for `cljr-expand-let`."
(when (>= paredit-version 21)
(let ((keymap (or keymap clojure-mode-map)))
(let ((keymap (or keymap (current-local-map))))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to update the docstring above as well. (it still mentions clojure-mode-map as the default)

Using current-local-map instead of clojure-mode-map allows the edn-mode-map to
be updated in edn-mode (and, of course, the clojure-mode-map to be updated in
clojure-mode). Using clojure-mode-map directly prevented edn-mode from
inheriting the benefits of clojure-paredit-setup, such as auto-pairing curly
braces.
@grzm grzm force-pushed the grzm/edn-paredit-setup branch from e18ec2e to 12cc356 Compare March 18, 2026 13:17
@grzm
Copy link
Contributor Author

grzm commented Mar 18, 2026

It's not clear to me why the windows-latest and ubuntu-latest/snapshot CI checks are failing when the others are still passing and the error messages are inscrutable to my naïve eyes. Any hints as to what might be going on?

@bbatsov bbatsov merged commit 361b2e0 into clojure-emacs:master Mar 18, 2026
5 of 7 checks passed
@bbatsov
Copy link
Member

bbatsov commented Mar 18, 2026

Don't worry, that's not related to your changes. Thanks!

@grzm
Copy link
Contributor Author

grzm commented Mar 18, 2026

Thanks!

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

Successfully merging this pull request may close these issues.

2 participants