Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Jun 10, 2024
1 parent 3df5e83 commit 6436843
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 24 deletions.
50 changes: 27 additions & 23 deletions src-shared/nextjournal/clojure_mode/commands.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -139,37 +139,41 @@
(defn slurp [direction]
(fn [^js state]
(u/update-ranges state
(j/fn [^:js {:as range :keys [from to empty]}]
(j/fn [^:js {:keys [from empty]}]
(when empty
(when-let [parent (n/closest (n/tree state from)
(every-pred n/coll?
(every-pred (some-fn n/coll?
n/string?)
#(not
(case direction
1 (some-> % n/with-prefix n/right n/end-edge?)
-1 (some-> % n/with-prefix n/left n/start-edge?)))))]
(when-let [target (case direction 1 (first (remove n/line-comment? (n/rights (n/with-prefix parent))))
-1 (first (remove n/line-comment? (n/lefts (n/with-prefix parent)))))]
{:cursor/mapped from
:changes (case direction
1
(let [edge (n/down-last parent)]
[{:from (-> target n/end)
:insert (n/name edge)}
(-> edge
n/from-to
(j/assoc! :insert " "))])
-1
(let [^string edge (n/left-edge-with-prefix state parent)
start (n/start (n/with-prefix parent))]
[{:from start
:to (+ start (count edge))
:insert " "}
{:from (n/start target)
:insert edge}]))})))))))
-1 (some-> % n/with-prefix n/left n/start-edge?)))))]
(let [str? (n/string? parent)]
(when-let [target (case direction 1 (first (remove n/line-comment? (n/rights (n/with-prefix parent))))
-1 (first (remove n/line-comment? (n/lefts (n/with-prefix parent)))))]
(js/console.log :target target)
{:cursor/mapped from
:changes (case direction
1
(let [edge (n/down-last parent)]
[{:from (-> target n/end)
:insert (n/name edge)}
(-> edge
n/from-to
(cond->
(not str?) (j/assoc! :insert " ")))])
-1
(let [^string edge (n/left-edge-with-prefix state parent)
start (n/start (n/with-prefix parent))]
[{:from start
:to (+ start (count edge))
:insert " "}
{:from (n/start target)
:insert edge}]))}))))))))

(defn barf [direction]
(fn [^js state]
(->> (j/fn [^:js {:as range :keys [from to empty]}]
(->> (j/fn [^:js {:keys [from empty]}]
(when empty
(when-let [parent (-> (n/tree state from)
(n/closest n/coll?))]
Expand Down
12 changes: 12 additions & 0 deletions src-shared/nextjournal/clojure_mode/scratch.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(ns nextjournal.clojure-mode.scratch
(:require [nextjournal.clojure-mode.commands :as commands]
[nextjournal.clojure-mode :as cm-clojure]
[nextjournal.clojure-mode.extensions.eval-region :as eval-region]
[nextjournal.clojure-mode.test-utils :as test-utils]))

(def extensions
(.concat cm-clojure/default-extensions (eval-region/extension #js {})))

(def apply-f (partial test-utils/apply-f extensions))

(js/console.log (apply-f (commands/slurp 1) "\"|\" 1"))
3 changes: 2 additions & 1 deletion test/nextjournal/clojure_mode_tests.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@
"('is-d|ata) :x" 1 "('is-d|ata :x)"
"('xy|z 1) 2" 1 "('xy|z 1 2)"
"'ab|c 1" 1 "'ab|c 1"
))

"\"x|\" 1" 1 "\"x1\""))

#?(:squint nil
:cljs
Expand Down

0 comments on commit 6436843

Please sign in to comment.