new-ryuslash.org/posts/paredit-and-ielm.org
Tom Willemse 7bdefe9504 Add posts repository to website project
This doesn't belong with the usual publish actions, so exclude posts from being published.
2023-06-28 23:07:41 -07:00

1.5 KiB
Raw Blame History

IELM & Paredit

For a while I've been bothered by being unable to use IELM to evaluate Emacs Lisp expressions. Then Making IELM More Comfortable pointed out that using paredit in IELM causes the RET and C-j keybindings to be bound to the wrong functions and proposes to fix them. The given fix, however, appears to change the keybindings for all buffers using paredit. I don't want that, and Emacs can do better!

A quick search yielded Buffer-locally overriding minor-mode key bindings in Emacs suggesting a fix. My adaptation of that solution:

  (defun oni-elisp-ielm-remove-paredit-newline-keys ()
    "Disable C-j and RET keybindings from paredit-mode."
    (let ((oldmap (map-elt minor-mode-map-alist 'paredit-mode))
          (newmap (make-sparse-keymap)))
      (set-keymap-parent newmap oldmap)
      (define-key newmap (kbd "RET") nil)
      (define-key newmap (kbd "C-j") nil)
      (make-local-variable 'minor-mode-overriding-map-alist)
      (push `(paredit-mode . ,newmap) minor-mode-overriding-map-alist)))

  (add-hook 'ielm-mode-hook #'oni-elisp-ielm-remove-paredit-newline-keys)

Defining RET and C-j as nil means that the keybinding defaults back to the major-mode keybinding.