博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Using Emacs as Clojure IDE
阅读量:5342 次
发布时间:2019-06-15

本文共 2931 字,大约阅读时间需要 9 分钟。

  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

  • Toggle focus between nrepl window and clojure source file window: C-c C-z (you should add "(add-to-list 'same-window-buffer-names "nrepl")" to ~/.emacs;

  • Always pretty printing in the REPL: M-x nrepl-toggle-pretty-printing

  • Move over sexp: C-M-b/C-M-f;

  • Interrupt any pending evaluations: C-c C-b;

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 ;

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:

  • In clojure mode with Evil, you have to switch to insert state and put the cursor after the last parenthsis, then evaluate the expression with C-x C-e. If you put the cursor on the last parenthesis in normal state, The result will be wrong.

  • It unnecessary to put your clojure file in a leiningen-created project, which is more flexible than vim-fireplace;

  • The value of expression will be output to the message area (bottom of the emacs window), while the output by "println" will be output to nrepl buffer;

  • Switch cursor between windows: C-x o;

  • Clear repl output: C-c M-o;

  • Indent code blocks intelligently: C-M-q

  • All the keyboard shortcuts will be more convenient if you swap CapsLock key and Escape key, together with Ctrl key and Alt key, see Define Keymap on Ubuntu for detail;

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

Ref:

转载于:https://www.cnblogs.com/darkmatter/p/3606814.html

你可能感兴趣的文章
adb命令
查看>>
SQL自定义排序 ORDER BY
查看>>
Modal模态框scrolltop保留上次位移的解决方案
查看>>
python 函数(一)
查看>>
我说我在总结谁会信。。
查看>>
数据库索引的作用和长处缺点
查看>>
Laravel 安装代码智能提示扩展「laravel-ide-helper」
查看>>
java开发配套版本
查看>>
MySQL的 Grant命令权限分配
查看>>
非阻塞的c/s,epoll服务器模型
查看>>
YII框架安装过程总结
查看>>
HDOJ(HDU) 1862 EXCEL排序(类对象的快排)
查看>>
Codeforces Round #381 (Div. 2) 复习倍增//
查看>>
Money类型转化为String去除小数点后0解决方法
查看>>
ArcScene 高程不同的表面无法叠加
查看>>
[ONTAK2010] Peaks
查看>>
DLL 导出函数
查看>>
windows超过最大连接数解决命令
查看>>
12个大调都是什么
查看>>
angular、jquery、vue 的区别与联系
查看>>