Using Emacs as Clojure IDE

时间:2014-03-18 11:48:12   收藏:0   阅读:550
  1. Open emacs24;

  2. Change CWD to parent folder of project home: M-x cd ~/docs/tmp;

  3. Build a leiningen project: M-! lein new calc-cov (see Run Shell Command in Emacs for other method to run shell command in emacs);

  4. Change CWD to project home: M-x cd calc-cov;

  5. Start nrepl server: M-x nrepl-jack-in;

  6. Open source file in another window: C-x 2 C-x C-f src/.../core.clj;

  7. Change the namespace of the REPL to the namespace of the file you are in: C-c M-n;

  8. Evaluate the whole source file: C-c C-k, evaluate a s-exp before the cursor: C-x C-e;

  9. Open clojure doc of the function under the cursor: C-c C-d

  10. Run test: C-c C-,

Frequently used keyboard shortcuts and commands

Evaluate a sexp without evaluate all file

  1. Add this sexp into source file (unnecessary to save source file);

  2. Use following methods to evaluate the sexp:

  3. Move cursor to the sexp for test, C-M-x (or C-c C-c) to evaluate the top-level form (such as a defn expression) under the cursor; If you want insert the evaluation result to current buffer, use C-u C-M-x;

  4. If the the target form is not a "top-level" form, move the cursor to the end of this sexp, C-x C-e to evaluate it, See more shortcuts at nrepl official site;

Then this sexp has been added to the repl, you can use it in repl;

This is very helpful in some circumstances. For example, I want debug function "cell-block" (see p141 in "Clojure Programming"), add

(println "[left mid right] is:") (println [left mid right])

before "(window (map ...)". But You can‘t evaluate the whole file because there are some lazy sequences and evaluate whole file will cause JVM heap out of memory; So I only evaluate this modified version with C-x C-e, test it in repl. After I figure out how this function works, undo my modification and move on.

Note:

Ref: http://stackoverflow.com/questions/3636364/can-i-clean-the-repl

Ref: Clojure with Emacs

Using Emacs as Clojure IDE,布布扣,bubuko.com

原文:http://www.cnblogs.com/darkmatter/p/3606814.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!