Permalink
Browse files

made the parsing machinery wait for a user pause before reparsing the…

… whole text, etc
  • Loading branch information...
1 parent f645efa commit 9fd2659a338e93e6825a828e6ebbe9fca6d23d0e @laurentpetit laurentpetit committed Aug 8, 2010
View
@@ -0,0 +1 @@
+ccw.support.leiningen/classes/
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Counterclockwise Plugin
Bundle-SymbolicName: ccw.branding;singleton:=true
-Bundle-Version: 0.0.59.RD01
+Bundle-Version: 0.0.59.RD02
Bundle-ActivationPolicy: lazy
Bundle-Vendor: Counterclockwise team
Require-Bundle: org.eclipse.help
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Counterclockwise Clojure Plug-in
Bundle-SymbolicName: ccw.core;singleton:=true
-Bundle-Version: 0.0.59.RD01
+Bundle-Version: 0.0.59.RD02
Bundle-Localization: plugin
Bundle-Activator: ccw.CCWPlugin
Require-Bundle: org.eclipse.ui,
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -217,7 +217,6 @@ public void documentChanged(DocumentEvent event) {
private void updateParseRef(String text) {
parseRef = EditorSupport.updateParseRef(text, parseRef);
- System.out.println("cached the parser!");
}
public Object getParsed() {
@@ -15,15 +15,32 @@
:methods [^{:static true} [updateParseRef [String Object] Object]
^{:static true} [getParser [String Object] Object]]))
+; TODO move in a utility namespace, or remove
+(defprotocol Cancellable (isCancelled [this]) (cancel [this]))
+
+; TODO move in a utility namespace, or remove
+(defn timed-delay [pause fun]
+ (let [d (delay (fun))
+ f (future (Thread/sleep pause) @d)]
+ (reify
+ clojure.lang.IDeref
+ (deref [_] @d)
+ Cancellable
+ (isCancelled [_] (future-cancelled? f))
+ (cancel [_] (future-cancel f)))))
+
(defn -updateParseRef [text r]
(let [r (if (nil? r) (ref nil) r)]
- (dosync (ref-set r {:text text :parser (future (p/parse text))}))
+ (dosync
+ (if-let [rv @r] (cancel (:parser rv)))
+ (ref-set r {:text text :parser (timed-delay 3000 #(time (p/parse text)))}))
r))
(defn -getParser [text r]
- (if (= text (-> r deref :text))
- (-> r deref :parser deref)
- (do
- (println "cached parser miss !")
- (-updateParseRef text r)
- (-> r deref :parser deref))))
+ (let [rv @r]
+ (if (= text (:text rv))
+ @(:parser rv)
+ (do
+ (println "cached parser miss !")
+ (-updateParseRef text r)
+ (recur text r)))))
@@ -33,7 +33,9 @@
(def *strict-commands*
#{:paredit-close-round, :paredit-close-square, :paredit-close-curly,
- :paredit-forward-delete, :paredit-backward-delete})
+ :paredit-forward-delete, :paredit-backward-delete,
+ :paredit-open-round, :paredit-open-square, :paredit-open-curly,
+ :paredit-doublequote})
(def
#^{:doc "{:command configuration-key ...}"}
@@ -64,7 +66,7 @@
(defn do-command?
"Will do command if it is :strict and the editor allows it, or if it is not :strict"
[#^AntlrBasedClojureEditor editor par-command]
- (println (str "do-command? : '" par-command "'"))
+ ;(println (str "do-command? : '" par-command "'"))
(cond
(*strict-commands* par-command)
(.useStrictStructuralEditing editor)
@@ -84,7 +86,7 @@
par-command {:text (.text command) :offset (.offset command) :length (.length command)}
;_ (println (str "par-command:" par-command))
[par-command par-text] (paredit-args par-command document-text)
- _ (println "here is the par-command:" par-command)
+ ;_ (println "here is the par-command:" par-command)
result (and
par-command
(do-command? (-> this .state deref :editor) par-command)
View
@@ -2,7 +2,7 @@
<feature
id="ccw.feature"
label="%featureName"
- version="0.0.59.RD01"
+ version="0.0.59.RD02"
provider-name="%providerName"
plugin="ccw.branding">

0 comments on commit 9fd2659

Please sign in to comment.