Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an Emacs paredit hook available so I can redefine C-j?

Tags:

emacs

elisp

I like using C-j to eval-last-sexp but paredit-mode (which I otherwise like) overrides this to paredit-newline. Looking in the paredit-mode docs I don't see anything like a paredit-mode-hook defined where I can add-hook to call local-set-key or a similar function.

Anyone have a suggestion?

Update After trying out the two answers below and not having much success, I think the problem may be related to the fact that paredit is getting loaded in a few different contexts? To wit, I am opening both Common Lisp, Clojure and Emacs Lisp files, all of which can use paredit. Sadly, the various forms of eval-last-sexp have slightly different names in each mode, so I can't define the key once for everything. Rather, I need to bind the key based on the major mode that I am in also. Hopefully that adds another useful data point.

like image 913
bitops Avatar asked Jun 27 '12 20:06

bitops


1 Answers

No need to use hooks, something like the following should work:

(eval-after-load "paredit"
  #'(define-key paredit-mode-map (kbd "C-j") 'eval-last-sexp))

Alternatively, if for some reason that doesn't work, or you simply prefer the use of hooks, you can add the above define-key invocation to the hooks of the major modes for which paredit is activated.

like image 200
Greg E. Avatar answered Nov 15 '22 12:11

Greg E.