Permalink
Browse files

Fixed intercept-setup bug on reload.

The intercept-setup macros are based on the global interception method now.
  • Loading branch information...
1 parent 13db42e commit f0c6b8cf7f54d8b9eb1066f947e29f1ed49b3e05 @guv committed Jun 23, 2012
Showing with 46 additions and 29 deletions.
  1. +3 −8 README.md
  2. +5 −1 project.clj
  3. +38 −20 src/debug/intercept.clj
View
@@ -1,22 +1,20 @@
# clj-debug
-Library for debugging Clojure programms. More documentation will be written soon.
+Library for debugging Clojure programms with support for tracing, timing and inspection. More documentation will be written soon.
## Install
Add one of the following to your ```project.clj``` to let Leiningen install ```clj-debug``` for you:
```clj
-:dependencies [[clj-debug "0.6.1"]]
-:dev-dependencies [[clj-debug "0.6.1"]]
+:dependencies [[clj-debug "0.6.2"]]
+:dev-dependencies [[clj-debug "0.6.2"]]
```
## TODO
-* remove all clojure.contrib references
-
### debug.trace
* variable args not supported, yet
@@ -26,9 +24,6 @@ Add one of the following to your ```project.clj``` to let Leiningen install ```c
* there is still a lot of redundancy in the multimethod implementations for handling known macros
* expression nodes should contain the expression form with filled in parameters
-### debug.intercept
-
-* *-setup throws an Exception on reevaluation in REPL (via CCW CTRL+ALT+S; most likely also in general)
## License
View
@@ -1,4 +1,8 @@
-(defproject clj-debug "0.6.1"
+(defproject clj-debug "0.6.2"
+ :description "Library for debugging Clojure programms with support for tracing, timing and inspection."
+ :url "https://github.com/guv/clj-debug"
+ :license {:name "Eclipse Public License"
+ :url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies
[[org.clojure/clojure "1.2.1"]
[org.clojure/core.incubator "0.1.0"]
View
@@ -6,8 +6,6 @@
; the terms of this license.
; You must not remove this notice, or any other, from this software.
-; * REMARKS:
-; - *-setup throws an Exception on reevaluation in REPL (via CCW CTRL+ALT+S; most likely also in general)
(ns debug.intercept
{:author "Gunnar Völkel"}
(:require
@@ -17,9 +15,10 @@
[clojure.string :only (join)])
(:import java.io.File))
-
+; store clojure.core/defn
(def core-defn (var-get #'clojure.core/defn))
(.setMacro (var core-defn))
+; store clojure.core/deftype
(def core-deftype (var-get #'clojure.core/deftype))
(.setMacro (var core-deftype))
@@ -142,22 +141,26 @@
nil)))
+(defn create-intercept-symbol
+ [symb]
+ (symbol "debug.intercept", (name symb)))
+
+(defn create-local-symbol
+ [symb]
+ (symbol (-> *ns* ns-name name) (name symb)))
+
(defn create-setup-macro
[registry, create-key, macro-name, intercept-func, info-prefix]
`(defmacro ~macro-name
[& func-symbols#]
- (do
- (interception-setup ~registry, ~create-key, ~intercept-func, func-symbols# ~info-prefix)
- (when (and (not global-interception?) (nil? (resolve (symbol (str *ns* "/defn")) ) ))
- `(do
- (ns-import-intercept-symbols
- '~'~'[
- [defn-intercept defn],
- [defn-intercept- defn-],
- [deftype-intercept deftype],
- [defrecord-intercept defrecord]
- ])
- nil)))))
+ `(do
+ (interception-on)
+ (interception-setup
+ ~'~(create-intercept-symbol registry),
+ ~'~(create-intercept-symbol create-key),
+ ~'~(create-local-symbol intercept-func),
+ '~func-symbols#
+ ~~info-prefix))))
(defn ns-import-intercept-symbols
@@ -285,24 +288,39 @@
(catch Exception e false)))
+(defn interception-on
+ "Replaces clojure.core macros for interception. Returns true, when interception was switched on - nil, if it was activated already."
+ []
+ (when-not global-interception?
+ (alter-var-root #'global-interception? (constantly true))
+ (alter-var-root #'clojure.core/defn (constantly (var-get #'defn-intercept)))
+ (alter-var-root #'clojure.core/deftype (constantly (var-get #'deftype-intercept)))
+ true))
+
+(defn interception-off
+ "Restores original clojure.core macros. Returns true, when interception was switched off - nil, if it was deactivated already."
+ []
+ (when global-interception?
+ (alter-var-root #'global-interception? (constantly false))
+ (alter-var-root #'clojure.core/defn (constantly (var-get #'core-defn)))
+ (alter-var-root #'clojure.core/deftype (constantly (var-get #'core-deftype)))
+ true))
+
+
(def ^{:private true} interception-enabled? false) ; Determines whether interception of functions is enabled.
(defn enable-intercept
[enabled?]
(alter-var-root #'interception-enabled? (constantly enabled?)))
-
(defn setup-global-interception
[file-name, intercept-config-funcs]
(when (file-exists? file-name)
(doseq [func-symb intercept-config-funcs]
(use [(symbol (namespace func-symb)) :only [(symbol (name func-symb))]]))
(refer 'debug.intercept :only '[enable-intercept])
(load-file file-name)
- (when interception-enabled?
- (alter-var-root #'clojure.core/defn (constantly (var-get #'defn-intercept)))
- (alter-var-root #'global-interception? (constantly true))
- (alter-var-root #'clojure.core/deftype (constantly (var-get #'deftype-intercept))))))
+ (when interception-enabled? (interception-on))))
(defmacro intercept-global
[file-name & intercept-config-funcs]

0 comments on commit f0c6b8c

Please sign in to comment.