How do you define a key-chord key only in specific mode, for example I want to bind a cider repl to a specific key only in clojure-mode
or cider-mode
. I can only find an example that activates the key globally.
Thanks for your help.
EDIT:
(require 'evil)
(require 'key-chord)
(evil-mode 1)
(key-chord-mode 1)
(key-chord-define evil-insert-state-map "jk" 'evil-normal-state)
(key-chord-define-global "gt" 'other-window)
(key-chord-define clojure-mode-hook "gj" 'cider-jack-in)
;; error : Wrong type argument: keymapp, (rainbow-delimiters-mode)
(provide 'init-evil)
Here is an example of how to do this:
(define-key clojure-mode-map (kbd "C-c r") 'cider-repl)
... where of course you would have to replace cider-repl
with the specific command you want to bind. Note that the quote '
before the command name is required.
To generalize:
(define-key <mode-map> <key-binding> '<command>)
key-chord
-specific instructionsYou need to change the line where you're trying to set up the clojure-mode
-specific key binding to
(add-hook 'clojure-mode-hook
(lambda () (key-chord-define clojure-mode-map "gj" 'cider-jack-in)))
In order for modifications to clojure-mode-map
to work properly, you have to make sure it is defined when you call define-key
as described above.
If you are using the Emacs Package Manager, you are likely to have this line
(package-initialize)
somewhere in your .emacs
file (which takes care of loading packages installed via package-install
). Make sure you call define-key
somewhere below this line.
Alternatively you can add the call to define-key
to the hook that is run when clojure-mode
is enabled:
(defun clojure-set-up-key-bindings ()
(define-key clojure-mode-map (kbd "C-c r") 'cider-repl)
;; If necessary, add more calls to `define-key' here ...
)
(add-hook 'clojure-mode-hook 'clojure-set-up-key-bindings)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With