Is there access to Emacs paredit available so that I can override Cj?

I like to use C-jto eval-last-sexp, but paredit-mode (which I like) overrides this value with paredit-newline. If you look at the paredit-mode docs, I don’t see anything like this paredit-mode-hookwhere I can add-hookcall local-set-keyor a similar function.

Anyone have a suggestion?

Update Having chosen the two answers below and not having received much success, I think the problem may be due to the fact that paredit loads in several different contexts? To do this, I open the Common Lisp, Clojure, and Emacs Lisp files, all of which can use paredit. Unfortunately, different forms eval-last-sexphave slightly different names in each mode, so I cannot determine the key once for everything. Rather, I need to bind a key based on the main mode, in which I too. Hope this adds another useful data point.

+5
source share
3 answers

No need to use hooks, the following should work:

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

, - , define-key , paredit.

+10

, define-*-mode, MODE-hook.

, paredit-mode - , (define-minor-mode paredit-mode ...), paredit-mode-hook.

M-x find-function RET define-minor-mode RET run-hooks, , .

( ):

C-x C-e eval-last-sexp? , :

(local-set-key (kbd "C-j") (key-binding (kbd "C-x C-e")))
+6

There is paredit-mode-hook. You do not see this until you add something to it. Strange, but this is how the hooks behave.

However, in your case, the best approach might be to clear the paredit binding for Cj:

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

And then set your own using a local key set in each main mode.

+2
source

All Articles