-
Notifications
You must be signed in to change notification settings - Fork 19
/
clogn.clj
54 lines (49 loc) · 2.02 KB
/
clogn.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
(ns debux.cs.clogn
(:require [debux.dbg :as dbg]
[debux.dbgn :as dbgn]
[debux.common.skip :as sk]
[debux.common.util :as ut]
[debux.cs.util :as cs.ut] ))
(defmacro d [form]
`(let [opts# ~'+debux-dbg-opts+
n# (or (:n opts#) (:print-seq-length @ut/config*))
form-style# (or (:style opts#) :debug)
form# '~(dbgn/remove-d form 'debux.cs.clogn/d)
result# ~form
result2# (ut/take-n-if-seq n# result#)]
(when (or (:dup opts#) (ut/eval-changed? (:evals opts#) form# result2#))
(cs.ut/clog-form-with-indent (cs.ut/form-header form# (:msg opts#))
form-style#
(:indent-level @ut/config*))
(cs.ut/clog-result-with-indent result2# (:indent-level @ut/config*)))
result#))
(defmacro clogn
"Console LOG every Nested forms of a form."
[form & [{:keys [condition msg style] :as opts}]]
`(let [~'+debux-dbg-opts+ ~(dissoc opts :js :once)
condition# ~condition]
(try
(if (or (nil? condition#) condition#)
(let [title# (str "\n%cclogn: %c " (ut/truncate (pr-str '~form))
" %c" (and ~msg (str " <" ~msg ">"))
" =>")
style# (or ~style :debug)]
(cs.ut/clog-header title# style#)
~(-> (if (ut/include-recur? form)
(sk/insert-o-skip-for-recur form &env)
form)
(dbgn/insert-skip &env)
(dbgn/insert-d 'debux.cs.clogn/d &env)
dbgn/remove-skip))
~form)
(catch js/Error ~'e (throw ~'e)) )))
;;; break
(defmacro break
"Sets a break point."
[{:keys [msg condition] :as opts}]
`(when (or (nil? ~condition) ~condition)
(.log js/console (str "%c break %c"
(and ~msg (str " <" ~msg ">")))
"background: #FF1493; color: white"
"background: white; color: black")
~'(js* "debugger;") ))