emacs的cider-debug-defun-point


用emacs工具debug后端的clj代码

简书地址

演示代码

;; 1. Call M-x cider-debug-init-connectiong(only needed once),
;; 2. Call M-x cider-debug-defun-at-ponit with point inside this defn.
;; 3. Run the function, and using key word
;; 4. link:https://docs.cider.mx/cider/debugging/debugger.html
(defn foo [n]
  (map (partial * 2)
       (filter even?
               (range 0 n))))

;; break out when reaching a condition
(defn foo2 []
  (dotimes [i 10]
    #dbg ^{:break/when (= i 7)}
    (prn i)))


(defn eval-msg [{:keys [inspect] :as msg}]
  (if inspect
    #break (clojure.inspector/inspect msg)
    msg))

进入debug
M-x cider-debug-defun-at-point

常见的操作:

j Inject a value into running code

e C-c M-: 表达式求值

enlighten模式:查看最后一次表达式的值
M-x cider-enlighten-mode
C-M-x 或者 C-x C-e 开始执行。 C-c C-k取消操作。
M-x cider-enlighten-mode关闭enlighten模式

(defn foo2 [x]
  (let [y (* 3 x)]
    (+ x y)))

(defn bar [x]
  (dotimes [i x]
    (foo2 i)))

(bar 5)

参考

debugger
Enlighten


评论
  目录