From 2da3d79f082ae29e4510b28448217abffa929489 Mon Sep 17 00:00:00 2001 From: Philippa Markovics Date: Sun, 5 Nov 2023 12:05:13 +0100 Subject: [PATCH] =?UTF-8?q?Default=20to=20=E2=8C=98=20for=20regional=20eva?= =?UTF-8?q?ls=20&=20Name=20command=20fns=20(#38)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Make Meta the default modifier for regional eval * Make sure eval- cmds are named in bindings * Update bindings in doc, demo & readme --------- Co-authored-by: Martin Kavalar --- README.md | 6 +++--- demo/src/nextjournal/clojure_mode/demo.cljs | 6 +++--- demo/src/nextjournal/clojure_mode/demo/sci.cljs | 14 ++++++++------ public/index.html | 6 +++--- .../clojure_mode/extensions/eval_region.cljs | 2 +- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 15cecc19..0fd71f1e 100644 --- a/README.md +++ b/README.md @@ -19,9 +19,9 @@ Enabling a decent Clojure/Script editor experience in the browser. Built for and * Expand/Contract: Alt + ↑ / ↓ or Mod + 1 / 2 πŸ§™ **Prepared for evaluation** -* At Cursor: Alt + ⏎ -* Top-level form: Alt + ⇧ + ⏎ -* Cell: Mod + ⏎ +* At Cursor: Mod + ⏎ +* Top-level form: Mod + ⇧ + ⏎ +* Cell: Alt + ⏎ **🧹 Autoformatting** following [Tonsky’s Better Clojure Formatting](https://tonsky.me/blog/clojurefmt/) diff --git a/demo/src/nextjournal/clojure_mode/demo.cljs b/demo/src/nextjournal/clojure_mode/demo.cljs index 70269479..c8b9bcca 100644 --- a/demo/src/nextjournal/clojure_mode/demo.cljs +++ b/demo/src/nextjournal/clojure_mode/demo.cljs @@ -64,8 +64,8 @@ (j/obj :state (test-utils/make-state (cond-> #js [extensions] - eval? (.concat #js [(eval-region/extension {:modifier "Alt"}) - (demo.sci/extension {:modifier "Alt" + eval? (.concat #js [(eval-region/extension {:modifier "Meta"}) + (demo.sci/extension {:modifier "Meta" :on-result (partial reset! last-result)})])) source) :parent el)))))] @@ -211,7 +211,7 @@ (j/assoc! (js/document.getElementById "viewer-stylesheet") :innerHTML (rc/inline "stylesheets/viewer.css")) - (rdom/render [key-bindings-table (merge keymap/paredit-keymap* (demo.sci/keymap* "Alt"))] (js/document.getElementById "docs")) + (rdom/render [key-bindings-table (merge keymap/paredit-keymap* (demo.sci/keymap* "Mod"))] (js/document.getElementById "docs")) (rdom/render [:div.rounded-md.mb-0.text-sm.monospace.overflow-auto.relative.border.shadow-lg.bg-white [markdown-editor {:doc "# Hello Markdown diff --git a/demo/src/nextjournal/clojure_mode/demo/sci.cljs b/demo/src/nextjournal/clojure_mode/demo/sci.cljs index aa783a20..82546e40 100644 --- a/demo/src/nextjournal/clojure_mode/demo/sci.cljs +++ b/demo/src/nextjournal/clojure_mode/demo/sci.cljs @@ -14,13 +14,13 @@ (catch js/Error e {:error (str (.-message e))}))))) -(j/defn eval-at-cursor [on-result ^:js {:keys [state]}] +(j/defn eval-at-cursor* [on-result ^:js {:keys [state]}] (some->> (eval-region/cursor-node-string state) (eval-string) (on-result)) true) -(j/defn eval-top-level [on-result ^:js {:keys [state]}] +(j/defn eval-top-level* [on-result ^:js {:keys [state]}] (some->> (eval-region/top-level-string state) (eval-string) (on-result)) @@ -35,7 +35,7 @@ (defn keymap* [modifier] {:eval-cell - [{:key "Mod-Enter" + [{:key "Alt-Enter" :doc "Evaluate cell"}] :eval-at-cursor [{:key (str modifier "-Enter") @@ -48,8 +48,10 @@ on-result]}] (.of view/keymap (j/lit - [{:key "Mod-Enter" + [{:key "Alt-Enter" :run (partial eval-cell on-result)} {:key (str modifier "-Enter") - :shift (partial eval-top-level on-result) - :run (partial eval-at-cursor on-result)}]))) + :shift (j/fn eval-top-level [result] + (eval-top-level* on-result result)) + :run (j/fn eval-at-cursor [result] + (eval-at-cursor* on-result result))}]))) diff --git a/public/index.html b/public/index.html index 77e11d95..bafb199f 100644 --- a/public/index.html +++ b/public/index.html @@ -166,7 +166,7 @@

Try evaluating an At Cursor - Alt + ⏎ + Mod + ⏎ @@ -174,7 +174,7 @@

Try evaluating an Top-level form - Alt + ⇧ + ⏎ + Mod + ⇧ + ⏎ @@ -182,7 +182,7 @@

Try evaluating an Cell - Mod + ⏎ + Alt + ⏎ diff --git a/src/nextjournal/clojure_mode/extensions/eval_region.cljs b/src/nextjournal/clojure_mode/extensions/eval_region.cljs index 3f8fb739..a952ae7c 100644 --- a/src/nextjournal/clojure_mode/extensions/eval_region.cljs +++ b/src/nextjournal/clojure_mode/extensions/eval_region.cljs @@ -137,7 +137,7 @@ :keyup handle-key-event})])) (defn extension [{:keys [modifier] - :or {modifier "Alt"}}] + :or {modifier "Meta"}}] #js[(modifier-extension modifier) region-field (.. EditorView -decorations (from region-field))])