2

I am trying to set up some keybindings for working with scheme. I have these two mode hooks which contain the bindings I want:

(add-hook 'scheme-mode-hook
          (lambda ()
            (local-set-key (kbd "C-j") 'scheme-send-last-sexp)))

(add-hook 'scheme-mode-hook
          (lambda ()
            (local-set-key (kbd "C-c C-j") 'scheme-send-region)))

The problem is that I also have these hooks defined which I use for elisp:

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

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

My question is: how can I modify eval-after-load to set up my scheme key bindings only when in Scheme mode?

Malabarba
  • 22,878
  • 6
  • 78
  • 163
bitops
  • 333
  • 1
  • 12
  • If you only use those paredit bindings for elisp, then they should be written like your scheme bindings but using the `emacs-lisp-mode-hook` or `lisp-interaction-mode-hook`. – Jordon Biondo May 11 '15 at 17:47
  • @JordonBiondo I occasionally use them for Clojure too. – bitops May 11 '15 at 17:53
  • Write a function that locally creates bindings and add it to every major mode hook you want to use them in. That is the standard way to do it. – Jordon Biondo May 11 '15 at 19:06
  • @JordonBiondo how is that different from the lambdas in the add-hook calls above? – bitops May 11 '15 at 20:39

2 Answers2

0
  1. I think you mean set up only my scheme key bindings instead of "set up my scheme bindings only". Otherwise, if you do mean set up the scheme bindings only in Scheme mode then that should already be happening.

  2. If paredit-mode is a minor mode and scheme-mode is a major mode then you can't. A minor-mode keymap takes precedence over a major-mode keymap (aka local map).

    You can put one or the other command on a different key. But if you put both commands on the same key then the minor-mode binding wins.

Drew
  • 75,699
  • 9
  • 109
  • 225
0

I ended up solving this by unwinding paredit's keybindings first, then setting up my mode-hooks.

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

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

(add-hook 'emacs-lisp-mode-hook
          '(lambda ()
             (local-set-key (kbd "C-c C-j") 'eval-region)
             (local-set-key (kbd "C-j") 'eval-last-sexp)))

(add-hook 'racket-mode-hook
          '(lambda ()
             (paredit-mode)
             (local-set-key (kbd "C-j") 'racket-send-last-sexp)
             (local-set-key (kbd "C-c C-j") 'racket-send-region)
             (local-set-key (kbd "C-c C-s") 'racket-repl)
             (local-set-key (kbd "C-c C-p") 'clipboard-yank)
             ))
bitops
  • 333
  • 1
  • 12