I'm learning Clojure.

Every day, I open up Emacs and key in the following commands:

C-x 3 ; create a new window on the right
M-x cider-jack-in ; open up a REPL
C-x o ; switch to my left window
C-x C-f code/clojure-projects/something.clj ; open up a file and start coding

I would like to automate these, so that they automatically happen every time Emacs starts.

To do this, I need to add something to the bottom of my ~/.emacs.d/init.el file, right?

I would also like to know the process by which I can figure out how to do these things in the future.

  • Welcome to Emacs.SE! Please do not cross-post the same question on Stack Overflow at the same time. Please pick one or the other.
    – Dan
    Apr 28 '17 at 14:58
  • @Dan Thanks! And why not? Apr 28 '17 at 16:37
  • Use global-set-key to create or change a global key binding.

  • Use define-key to create or change a local (mode-specific) key binding, that is, a binding in a particular keymap.

Use the Emacs manual to find out about these things: C-h r.

In the manual, use i to look something up in the index, using completion. For example, i key bindings (or i key bind TAB to complete).

That takes you to node (page) Key Bindings of the manual, where you see a "menu" (table of contents) that includes this entry, which is the node you want to visit:

* Init Rebinding  Rebinding keys with your initialization file.

Just click the link Init Rebinding to go to that node. There you'll find a complete description of how to bind keys in your init file, including examples.

For a specific mode or keymap, such as Clojure mode likely uses, check the doc for the mode to see what keymap(s) it uses. If you can't discover the map(s) that way, try the mode name (e.g. clojure-mode?) followed by -map: clojure-mode-map. Use define-key to define a key binding in that keymap.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.