Reputation: 3451
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.
Upvotes: 3
Views: 1342
Reputation: 1761
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.
Upvotes: 3
Reputation: 486
You can use keyboard macro for that.
The idea is you record your actions and name the action. Emacs will generate the code for you and you just set your key mapping.
So first, you need to start recording your macro by C-x (
or <f3>
and execute your commands until you finish then C-x )
or <f4>
to end the macro recording session.
Now you will have an unnamed macro which you can test it by C-x e
or <f5>
which will execute all of your recorded commands.
Now you name your macro by M-x name-last-kbd-macro
. After that, go to your init.el
and then do M-x insert-kbd-macro
which will paste (fset <macro-name> <your-macro-definition>)
for you and now you can call your macro by using M-x <macro-name>
even if you open new emacs session.
You can also set key binding if you like. For example:
(global-set-key (kbd "C-c a") 'my-macro)
For more info, you can have a look at EmacsWiki: Keyboard Macros
Upvotes: 3