Question
I am using nrepl in Emacs 24 as Clojure IDE. When I want to write some codes in a Clojure project(after starting Emacs), I have to repeat the following commands:
M-x cd
docs/clojurefiles/conways-game-of-life
M-x nrepl-jack-in
C-x 4 f src/conways_game_of_life/core.clj
I want to save all above actions as a command and invoke it in "M-x" interface. Following this instruction I record my actions and save it as "last-kbd-macro" in ~/.emacs file:
F3
M-x cd
docs/clojurefiles/conways-game-of-life
M-x nrepl-jack-in
C-x 4 f src/conways_game_of_life/core.clj
F4
M-x name-last-kbd-macro<RET> start-conway-project
M-x insert-kbd-macro<RET> start-conway-project
Now the following variable is added to my ~/.emacs file:
(setq last-kbd-macro
[?\M-x ?c ?d return ?d ?o ?c ?s ?/ ?c ?l ?o ?j ?u ?r ?e ?f ?i ?l ?e ?s ?/ ?c ?o ?n ?w ?a ?y ?s ?- ?g ?a ?m ?e ?- ?o ?f ?- ?l ?i ?f ?e return ?\M-x ?n ?r ?e ?p ?l ?- ?j ?a ?c ?k ?- ?i ?n return ?\C-x ?4 ?f ?s ?r ?c ?/ ?c ?o ?n ?w ?a ?y ?s ?_ ?g ?a ?m ?e ?_ ?o ?f ?_ ?l ?i ?f ?e ?/ ?c ?o ?r ?e ?. ?c ?l ?j return])
And after restarting Emacs, I can use F4 to invoke this macro. However, what I want is defining my own command and invoke it in "M-x". So I modify above definition as:
(setq start-conway-project
[?\M-x ?c ?d return ?d ?o ?c ?s ?/ ?c ?l ?o ?j ?u ?r ?e ?f ?i ?l ?e ?s ?/ ?c ?o ?n ?w ?a ?y ?s ?- ?g ?a ?m ?e ?- ?o ?f ?- ?l ?i ?f ?e return ?\M-x ?n ?r ?e ?p ?l ?- ?j ?a ?c ?k ?- ?i ?n return ?\C-x ?4 ?f ?s ?r ?c ?/ ?c ?o ?n ?w ?a ?y ?s ?_ ?g ?a ?m ?e ?_ ?o ?f ?_ ?l ?i ?f ?e ?/ ?c ?o ?r ?e ?. ?c ?l ?j return])
But when I use "M-x" and input "start-conway-project", there is a "[no match]" sign and it doesn't work. What is the "emacs" way to define some actions as a command (macro or something else) and invoke it with "M-x"?
Solution
After adding the (setq last-kbd-macro ...)
to ~/.emacs,
modify it as (fset 'start-conway-project ...)
.
That's it.