Search code examples
emacsclojure

How do I add the following key bindings to my Emacs init.el?


I'm learning Clojure. Every day, I open up Emacs and type 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 tasks, 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.


Solution

  • To have these commands all run at startup in clojure-mode only, add the following to your ~/.emacs.d/init.el file:

    (defun my-clojure-startup ()
      "Startup sequence for clojure-mode"
      (interactive)
      (split-window-horizontally)
      (cider-jack-in)
      (other-window)
      (find-file "/your/full/filepath.ext"))
    

    To bind this to a key, for example CRTL+c a :

    (global-set-key (kbd "C-c a") 'my-clojure-startup)
    

    Or to have it run whenever you start in clojure mode:

    (add-hook 'clojure-mode-hook 'my-clojure-startup)
    

    NOTE this is untested as I do not have clojure so cannot see full behaviour of each of the commands, but this should hopefully give you a boost at least.