This repository was archived by the owner on Oct 21, 2022. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33 :lt.plugins.js/js-exception :lt.plugins.js/on-eval
44 :lt.plugins.js/on-eval.one
55 :lt.plugins.js/watch-src
6+ :lt.plugins.js/watch-custom-src
67 :lt.plugins.js/js-watch
78 (:lt.object/add-tag :watchable)]
89 :files [(:lt.objs.files/file-types [{:name "Javascript" :exts [:js] :mime "text/javascript" :tags [:editor.javascript]}
1819 :lt.plugins.js.node/changelive!
1920 :lt.plugins.js.node/connect-retry]
2021 :nodejs.lang [:lt.plugins.js.node/connect!]
21- }}
22+ }}
Original file line number Diff line number Diff line change 8484 opts-str (.stringify js/JSON opts)]
8585 (str " lttools.watch(" src " , " opts-str " )" semi)))
8686
87+ (defn fill-placeholders [src exp meta]
88+ (-> exp
89+ (string/replace " __SELECTION*__" , (str " '" src " '" ))
90+ (string/replace " __SELECTION__" src)
91+ (string/replace " __ID__" (:id meta))))
92+
93+ (defn custom-src->watch [src exp meta]
94+ (let [hassemi (= (last src) " ;" )
95+ subsrc (if hassemi (butlast src) src)
96+ end (if hassemi " ;" " " )
97+ sym (name (gensym " jswatch_temp" ))]
98+ (str " (function() {"
99+ " var " sym " = (" subsrc " );"
100+ (src->watch meta (fill-placeholders sym exp meta)) " ;"
101+ " return " sym " ;"
102+ " }())" end)))
103+
104+ (defn clean-code [src]
105+ (string/replace src (js/RegExp. " \n *#!.*\n " " gm" ) " \n " ))
106+
107+
87108(behavior ::watch-src
88109 :triggers #{:watch.src+ }
89110 :reaction (fn [editor cur meta src]
90111 (src->watch meta src)))
91112
92- (defn clean-code [src]
93- (string/replace src (js/RegExp. " \n *#!.*\n " " gm" ) " \n " ))
113+ (behavior ::watch-custom-src
114+ :triggers #{:watch.custom.src+ }
115+ :reaction (fn [editor cur meta {:keys [exp]} src]
116+ (let [type (-> (parse exp) (.-body ) (aget 0 ) (.-type ))])
117+ (if (= " ExpressionStatement" type)
118+ (custom-src->watch src exp meta)
119+ (do
120+ (notifos/set-msg! " Custom expression is not a syntactic statement" {:class " error" })
121+ (src->watch meta src)))))
122+
94123
95124(behavior ::on-eval
96125 :triggers #{:eval }
You can’t perform that action at this time.
0 commit comments