LLMs get very good in producing tutorials for Clojure libraries in markdown. By "good" I mean better then me, and far faster. So the "text" I will in practice read through and mostly leave untouched. They contain embedded code blocks as well, which are good , but not perfect. So I would like to "validate / execute / fix" these code blocks (after the markdown file is generated) They are now VScode plugin which nicely render markdown and code side-by-side Just an example:
## Model Utilities
### Loading Datasets
Load example datasets from Smile's repository.
clojure
(require '[scicloj.ml.smile.toydata :as toydata])
;; Load ARFF dataset
(def iris-dataset
(toydata/get-smile-data "weka/regression/cpu.arff"))
;; Load with custom options
(def housing-dataset
(toydata/get-smile-data "regression/housing.data"
{:column-names [:CRIM :ZN :INDUS :CHAS :NOX :RM]
:separator " "}))
So I can "review" the LLM result (= markdown) very comfortable.
This is not true, for reviewing of the embedded Clojure blocks, which would be great if working better.
This file is "not a .clj" file, so most Calva features don't, work.
I would hope that Calva can get "special" support for this type of files. "markdown + clj".
Maybe a good start would be a feature of a
• running a single code block (on keypress)
• runnig all code blocks of such markdown+clojure file
There are external plugins doing this: https://marketplace.visualstudio.com/items?itemName=renathossain.markdown-runner&ssr=false#qna but they don't keep "state" between the blocks. I nearly all my uses cases I would assume to have a "single clojure repl session" for the whole tutorial. This touches as well the topic of enable Calva for "Literate programming"
Worth looking at what we can do about this. Please file an issue. That said: • You can select the code in the markdown block and use the Calva command Evaluate Current for or Selection. It’s not default bound to a keyboard shortcut in a markdown file, but it is still available. • I ask the agent to verify code it suggests, using the repl • You can evaluate code using default keybindings in the Copilot chat. (The Clojure code blocks in Copilot chat are readonly Calva editors.)
> You can select the code in the markdown block and use the Calva command Evaluate Current for or Selection. It’s not default bound to a keyboard shortcut in a markdown file, but it is still available.
Yes I saw that one. Maybe binding this to a key fixes my use cases to a large extend... Of course, ideally the codeblocks have "code completion and other features of Calva".... Some kind of "sync" might as well wok
Issue created: https://github.com/BetterThanTomorrow/calva/issues/3113
There are also testing tools that can run code examples in Markdown as test cases. LazyTest has that ability. There's also com.github.lread/test-doc-blocks {:mvn/version "1.2.21"} which I use to verify all the examples in HoneySQL's docs.
Org Babel in Emacs (according to https://orgmode.org/manual/Editing-Source-Code.html) can pop a single code block open in a new, language-specific buffer, with the language's major-mode commands available, and then pop the edited version back into your original babel (literate) babel buffer afterward.
yes, that's the emacs solution for this. One of the strong points of "org-mode" See comments in the issue above, where I propose the "other way arround" now Make Calva "render" markdown embeded in comments ";;" in a normal namespace Here we have "Calva supported code editing given", and "markdown editing in comments" is not too bad.
I don’t understand what this means: > Make Calva “render” markdown embeded in comments “;;” in a normal namespace
Both "Clay" and "Clerk" support this syntax, so we have "users" for this.
I write:
;; # my header
(def a 1)
and Calva shows "my header" as "header" (markdown syntax) in a side panel.Like this: (using the markdown-everywhere plugin)
The "plugin" has a few issues... But maybe we could report it and have it fixed ...
Isn’t this what Calva notebooks is about a bit?
a bit yes...alternative syntax. (and not really working, is it ?) "Clay" and "Clerk" do work with that syntax (and can render it to html) , but as well including evaluation results (which above is not showing, and which is not needed when "concentrating on the text")
There are Clay commands in Calva Power Tools. Tried?
yes. They work as well, but sometimes: • "inside Calva is more convienent" • "every text change requires re-render which is slow...."
The above "syncs" in realtime.... I type left, it updates right.....
Yeah, but that extension also already exists, right?
Yes, its true. I will try to isolate the issues and report them. It's a kind of "setup issue" , and sometimes the initial markdown support does not trigger. But its probably more economic to get it working then re-write it...
I’m not opposed to creating a webview that renders markdown and code like that screenshot. We could leverage the REPL for a more interactive experience. I think it could be pretty sweet. But it is a separate issue from the thread start, right? You are welcome to file an issue about this as well.
yes, it's a different issue. Let's say both are nice to have, but I believe that the original 3113 so "to support well clojure-blocks-in-markdown" is far harder to implement then "support/render" markdown-syntax in clojure comments"
Agree. With some luck the VS Code team will bring the code block widget from the Copilot chat to the markdown previews and that would take care of 3113 beautifully. You could file an issue on VS Code about this. I would upvote and comment with my support for sure.