3 ms·
Does anyone know better ways to evaluate and execute Clojure expressions in Emacs? I find key combinations like these clunky: C-x C-e C-M-x
by va_coder 16y ago
Does anyone know better ways to evaluate and execute Clojure expressions in Emacs?
I find key combinations like these clunky:
C-x C-e
C-M-x
- silentbicycle 16y agoThose kinds of shortcuts of are very typical of Emacs defaults, but you can rebind them. Here's how. First, find the name of the function you want to rebind. Press C-h k (describe-key), and then the normal shortcut for the command you want to rebind. It should open a help buffer beginning with e.g. "C-x C-e runs the command something-hyphenated". That's your command name. (You can get a list of all commands in clojure's mode by pressing C-h m, which might be quicker if you're redefining several.) Then, set up a mode-specific hook (something that runs when you edit a buffer in that mode). Add this to your Emacs config: (add-hook 'clojure-mode-hook 'my-clojure-mode-hook) (or whatever the clojure mode is called, I haven't used clojure). Finally, define your mode hook and add custom local keybindings with local-set-key. It should look like this: (defun my-clojure-mode-hook () (local-set-key (kbd "better-shortcut") 'name-of-command) (local-set-key (kbd "better-shortcut-2") 'name-of-second-command)) Where (kbd "better-shortcut") is in the usual Emacs keyboard shortcut notation, like (kbd "C-M-e").* To figure out what this is for a key, you can press C-h k again, followed by your shortcut. It will say "X is unbound", "X is assemble-delicious-sandwich", or whatever. The X part is what Emacs calls that key combination. * You don't strictly need the (kbd "string") form, but it's probably the simplest form to use - you can press C-x C-e after the (kbd _) form to verify that it recognizes the key description. Anything else you want to run when you start editing clojure code can go in the mode hook, too. Let me know if you have any questions. While I haven't done much with clojure, I know customizing Emacs pretty well, and adding keybindings like this works for any mode. You just need to know what the mode is called.