This feature may help newcomers like myself better understand editor internals / how to write plugins. The idea is: 1. write a clojure expression (intended to be pure) 2. have it re-evaluated on every keystroke in editor 3. have output displayed in another browser window The idea is that by being able to "see" how the internal editor state changes, it makes it a bit more obvious how to write plugins that manip editor state.
* = right below cursor
"editor view" = current view
"debug view" = thing to add
1. Fire up two browser windows. One in debug view, one in editor view.
2. In debug view, type in "@editor-state"
3. Every expressikon in debug view is
* expected to be pure
* is re-evaluated on everyy keystroke
========== ========== ==========
Editor View:
+--------------------+
|hello world |
+--------*-----------+
Debug View:
@editor-state = {:before "hello wo" :end "rld"}
========== ========== ==========
## User presses "right arrow"
Editor View:
+--------------------+
|hello world |
+---------*----------+
Debug View:
@editor-state = {:before "hello wor" :end "ld"}
========== ========== ==========
## User presses "<esc>^" (start of line in vim)
Editor View:
+--------------------+
|hello world |
+*-------------------+
Debug View:
@editor-state = {:before "" :end "hello world"}
## User changes expression from "@editor-state" to
(count (:before @editor-state))
Editor View:
+--------------------+
|hello world |
+*-------------------+
Debug View:
(count (:before #editor-state)) = 0
========== ========== ==========
## User presses "right arrow"
Editor View:
+--------------------+
|hello world |
+-*------------------+
Debug View:
(count (:before #editor-state)) = 1
(ps: I have no idea how long this would take to implement, but you seem really fast 🙂 )
I think displaying the whole editor will be too much. It contains all buffers, with all sliders and lists of sliders for undoing. Displaying the current slider should be manageable. I hope it will only be very specialized extensions that needs to do stuff on slider level. At least my aim is that most extensions can be created knowing only editor functions. If you evaluate the snippet below, F5 will be asigned to display the current slider content in the -prompt- window. You can then do an operation an press F5 afterwards to see the change:
(editor/set-global-key :f5
(fn [] (let [sl (-> (dk.salza.liq.editor/current-buffer) dk.salza.liq.buffer/get-slider)]
(dk.salza.liq.editor/prompt-set sl))))
(Maybe it does make since to starte another server inside Liquid, to make a second web-output instead of -prompt-. That I think should also be doable just by evaluating a function.)
I do not think these features belong in core, but maybe I should create an extension into which functionality to inspect the editor itself is collected.
Maybe I should also add hooks. I have avoided that until now, but I realize that I often want make custom code run each time a key is pressed.
Btw, the new git-deps feature in Clojure is just a huge present for Liquid. "Installing" extensions is just a matter of adding the git url to deps.edn. That is 1 line for Liquid and 1 line for each extension. Yay. I will have to rewrite my installation instructions for that.