Blog: 2024-09-16: Difference between revisions
No edit summary |
No edit summary |
||
Line 250: | Line 250: | ||
it'll exit the program and say "you entered x bytes. Saving to (datetime).txt" - something like that. |
it'll exit the program and say "you entered x bytes. Saving to (datetime).txt" - something like that. |
||
So I want to get a single character. https://github.com/max1220/lua-getch should work but it doesn't work on mac I guess. Probably read its source code (c) and port it |
Latest revision as of 21:42, 16 September 2024
Trying to install sci https://github.com/babashka/sci?tab=readme-ov-file to use for a clojure-esque based editor ... oh yeah to get https://github.com/babashka/babashka?tab=readme-ov-file
Anyways
https://clojars.org/org.babashka/sci
Gives
[org.babashka/sci "0.8.43"]
It'd be nice to have a way to "pip install" this kind of dependency. Though I must remember that this is a clojure dependency, not a babashka one etc (so it wouldn't work quite like this in my editor)
Still adding some clojure tooling is nice
Ok so here's how I start my clojure project
hack $ lein new empty install-babashka WARNING: update-vals already refers to: #'clojure.core/update-vals in namespace: cider.nrepl.middleware.util.misc, being replaced by: #'cider.nrepl.middleware.util.misc/update-vals WARNING: update-keys already refers to: #'clojure.core/update-keys in namespace: cider.nrepl.middleware.util.misc, being replaced by: #'cider.nrepl.middleware.util.misc/update-keys Retrieving empty/lein-template/1.1.0/lein-template-1.1.0.pom from clojars Retrieving empty/lein-template/1.1.0/lein-template-1.1.0.jar from clojars Generating empty project. hack $ cd install-babashka/
Adding the dep
install-babashka $ cat project.clj (defproject install-babashka "0.1.0-SNAPSHOT" :description "A Clojure project" :dependencies [[org.clojure/clojure "1.11.1"] [org.babashka/sci "0.8.43"]] :main install-babashka.core)
Well I got some weird errors when I tried to lein repl
install-babashka $ lein repl WARNING: update-vals already refers to: #'clojure.core/update-vals in namespace: cider.nrepl.middleware.util.misc, being replaced by: #'cider.nrepl.middleware.util.misc/update-vals WARNING: update-keys already refers to: #'clojure.core/update-keys in namespace: cider.nrepl.middleware.util.misc, being replaced by: #'cider.nrepl.middleware.util.misc/update-keys Retrieving org/clojure/clojure/1.11.1/clojure-1.11.1.pom from central Retrieving org/babashka/sci/0.8.43/sci-0.8.43.pom from clojars Retrieving org/clojure/clojure/1.9.0/clojure-1.9.0.pom from central Retrieving org/clojure/spec.alpha/0.1.143/spec.alpha-0.1.143.pom from central Retrieving org/clojure/core.specs.alpha/0.1.24/core.specs.alpha-0.1.24.pom from central Retrieving borkdude/sci.impl.reflector/0.0.1/sci.impl.reflector-0.0.1.pom from clojars Retrieving borkdude/edamame/1.4.24/edamame-1.4.24.pom from clojars Retrieving org/clojure/tools.reader/1.3.4/tools.reader-1.3.4.pom from central Retrieving org/clojure/clojure/1.5.1/clojure-1.5.1.pom from central Retrieving org/sonatype/oss/oss-parent/5/oss-parent-5.pom from central Retrieving org/babashka/sci.impl.types/0.0.2/sci.impl.types-0.0.2.pom from clojars Retrieving org/clojure/clojure/1.10.3/clojure-1.10.3.pom from central Retrieving org/clojure/spec.alpha/0.2.194/spec.alpha-0.2.194.pom from central Retrieving org/clojure/pom.contrib/0.3.0/pom.contrib-0.3.0.pom from central Retrieving org/clojure/core.specs.alpha/0.2.56/core.specs.alpha-0.2.56.pom from central Retrieving nrepl/nrepl/1.0.0/nrepl-1.0.0.pom from clojars Retrieving org/nrepl/incomplete/0.1.0/incomplete-0.1.0.pom from clojars Retrieving org/clojure/clojure/1.11.1/clojure-1.11.1.jar from central Retrieving org/clojure/tools.reader/1.3.4/tools.reader-1.3.4.jar from central Retrieving borkdude/sci.impl.reflector/0.0.1/sci.impl.reflector-0.0.1.jar from clojars Retrieving nrepl/nrepl/1.0.0/nrepl-1.0.0.jar from clojars Retrieving org/babashka/sci/0.8.43/sci-0.8.43.jar from clojars Retrieving borkdude/edamame/1.4.24/edamame-1.4.24.jar from clojars Retrieving org/babashka/sci.impl.types/0.0.2/sci.impl.types-0.0.2.jar from clojars Retrieving org/nrepl/incomplete/0.1.0/incomplete-0.1.0.jar from clojars WARNING: update-vals already refers to: #'clojure.core/update-vals in namespace: cider.nrepl.middleware.util.misc, being replaced by: #'cider.nrepl.middleware.util.misc/update-vals WARNING: update-keys already refers to: #'clojure.core/update-keys in namespace: cider.nrepl.middleware.util.misc, being replaced by: #'cider.nrepl.middleware.util.misc/update-keys [WARNING] No nREPL middleware descriptor in metadata of #'cider.nrepl/wrap-apropos, see nrepl.middleware/set-descriptor! [WARNING] No nREPL middleware descriptor in metadata of #'cider.nrepl/wrap-classpath, see nrepl.middleware/set-descriptor! [WARNING] No nREPL middleware descriptor in metadata of #'cider.nrepl/wrap-complete, see nrepl.middleware/set-descriptor! [WARNING] No nREPL middleware descriptor in metadata of #'cider.nrepl/wrap-debug, see nrepl.middleware/set-descriptor! [WARNING] No nREPL middleware descriptor in metadata of #'cider.nrepl/wrap-enlighten, see nrepl.middleware/set-descriptor! [WARNING] No nREPL middleware descriptor in metadata of #'cider.nrepl/wrap-format, see nrepl.middleware/set-descriptor! [WARNING] No nREPL middleware descriptor in metadata of #'cider.nrepl/wrap-info, see nrepl.middleware/set-descriptor! [WARNING] No nREPL middleware descriptor in metadata of #'cider.nrepl/wrap-inspect, see nrepl.middleware/set-descriptor! [WARNING] No nREPL middleware descriptor in metadata of #'cider.nrepl/wrap-macroexpand, see nrepl.middleware/set-descriptor! [WARNING] No nREPL middleware descriptor in metadata of #'cider.nrepl/wrap-ns, see nrepl.middleware/set-descriptor! [WARNING] No nREPL middleware descriptor in metadata of #'cider.nrepl/wrap-out, see nrepl.middleware/set-descriptor! [WARNING] No nREPL middleware descriptor in metadata of #'cider.nrepl/wrap-pprint, see nrepl.middleware/set-descriptor! [WARNING] No nREPL middleware descriptor in metadata of #'cider.nrepl/wrap-pprint-fn, see nrepl.middleware/set-descriptor! [WARNING] No nREPL middleware descriptor in metadata of #'cider.nrepl/wrap-refresh, see nrepl.middleware/set-descriptor! [WARNING] No nREPL middleware descriptor in metadata of #'cider.nrepl/wrap-resource, see nrepl.middleware/set-descriptor! [WARNING] No nREPL middleware descriptor in metadata of #'cider.nrepl/wrap-spec, see nrepl.middleware/set-descriptor! [WARNING] No nREPL middleware descriptor in metadata of #'cider.nrepl/wrap-stacktrace, see nrepl.middleware/set-descriptor! [WARNING] No nREPL middleware descriptor in metadata of #'cider.nrepl/wrap-test, see nrepl.middleware/set-descriptor! [WARNING] No nREPL middleware descriptor in metadata of #'cider.nrepl/wrap-trace, see nrepl.middleware/set-descriptor! [WARNING] No nREPL middleware descriptor in metadata of #'cider.nrepl/wrap-tracker, see nrepl.middleware/set-descriptor! [WARNING] No nREPL middleware descriptor in metadata of #'cider.nrepl/wrap-undef, see nrepl.middleware/set-descriptor! [WARNING] No nREPL middleware descriptor in metadata of #'cider.nrepl/wrap-version, see nrepl.middleware/set-descriptor! nREPL server started on port 49395 on host 127.0.0.1 - nrepl://127.0.0.1:49395 Exception in thread "nREPL-session-445432a3-a0e3-4bb1-894a-35e6d574cf23" java.lang.IllegalArgumentException: No implementation of method: :send of protocol: #'nrepl.transport/Transport found for class: cider.nrepl.middleware.track_state$make_transport$reify__5966 at clojure.core$_cache_protocol_fn.invokeStatic(core_deftype.clj:584) at clojure.core$_cache_protocol_fn.invoke(core_deftype.clj:576) at nrepl.transport$eval658$fn__676$G__649__683.invoke(transport.clj:23) at nrepl.middleware.print$send_nonstreamed.invokeStatic(print.clj:157) at nrepl.middleware.print$send_nonstreamed.invoke(print.clj:138) at nrepl.middleware.print$printing_transport$reify__1190.send(print.clj:174) at nrepl.middleware.caught$caught_transport$reify__1225.send(caught.clj:58) at nrepl.middleware.print$replying_PrintWriter$fn__1151.invoke(print.clj:115) at nrepl.middleware.print.proxy$java.io.Writer$ff19274a.write(Unknown Source) at java.base/java.io.BufferedWriter.implFlushBuffer(BufferedWriter.java:178) at java.base/java.io.BufferedWriter.flushBuffer(BufferedWriter.java:169) at java.base/java.io.BufferedWriter.implFlush(BufferedWriter.java:371) at java.base/java.io.BufferedWriter.flush(BufferedWriter.java:365) at java.base/java.io.PrintWriter.implFlush(PrintWriter.java:426) at java.base/java.io.PrintWriter.flush(PrintWriter.java:418) at nrepl.middleware.interruptible_eval$evaluate.invokeStatic(interruptible_eval.clj:136) at nrepl.middleware.interruptible_eval$evaluate.invoke(interruptible_eval.clj:56) at nrepl.middleware.interruptible_eval$interruptible_eval$fn__1301$fn__1305.invoke(interruptible_eval.clj:152) at clojure.lang.AFn.run(AFn.java:22) at nrepl.middleware.session$session_exec$main_loop__1371$fn__1375.invoke(session.clj:218) at nrepl.middleware.session$session_exec$main_loop__1371.invoke(session.clj:217) at clojure.lang.AFn.run(AFn.java:22) at java.base/java.lang.Thread.run(Thread.java:1583) ^[ERROR: java.lang.ArithmeticException: long overflow at java.base/java.lang.Math.multiplyExact(Math.java:1032) at clojure.lang.Numbers.multiply(Numbers.java:1971) at nrepl.bencode$read_long.invokeStatic(bencode.clj:128) at nrepl.bencode$read_long.invokePrim(bencode.clj) at nrepl.bencode$read_netstring_STAR_.invokeStatic(bencode.clj:155) at nrepl.bencode$read_netstring_STAR_.invoke(bencode.clj:153) at nrepl.bencode$read_token.invokeStatic(bencode.clj:246) at nrepl.bencode$read_token.invoke(bencode.clj:236) at nrepl.bencode$read_bencode.invokeStatic(bencode.clj:256) at nrepl.bencode$read_bencode.invoke(bencode.clj:253) at nrepl.transport$bencode$fn__746$fn__747.invoke(transport.clj:122) at nrepl.transport$bencode$fn__746.invoke(transport.clj:122) at nrepl.transport$fn_transport$fn__700.invoke(transport.clj:50) at clojure.core$binding_conveyor_fn$fn__5823.invoke(core.clj:2047) at clojure.lang.AFn.call(AFn.java:18) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:317) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642) at java.base/java.lang.Thread.run(Thread.java:1583) ^C
Then I saw https://github.com/technomancy has some contributions to https://github.com/bakpakin/Fennel
And neovim supports lua
So maybe rather than a totally new editor, it's a neovim distribution that is configured only in fennel
Let's do a little fennel research
Ok I installed fennel pretty easily with a git clone then `make`. But I got a warning about readline
So I brew installed readline and heeded the warnings
==> Caveats readline is keg-only, which means it was not symlinked into /usr/local, because macOS provides BSD libedit. For compilers to find readline you may need to set: set -gx LDFLAGS "-L/usr/local/opt/readline/lib" set -gx CPPFLAGS "-I/usr/local/opt/readline/include" For pkg-config to find readline you may need to set: set -gx PKG_CONFIG_PATH "/usr/local/opt/readline/lib/pkgconfig" ==> Summary 🍺 /usr/local/Cellar/readline/8.2.13: 51 files, 1.7MB, built in 42 seconds
Adding the environment variables to my ~/.profile didn't do anything (it even auto sourced so I think it applied fine)
I tried symlinking but that didn't work either
Fennel $ symlink /usr/local/opt/readline/include/readline/ /usr/local/include/ Fennel $ ls /usr/local/include/readline/ chardefs.h keymaps.h rlconf.h rltypedefs.h history.h readline.h rlstdc.h tilde.h
Here's the error
Fennel $ sudo luarocks install readline Installing https://luarocks.org/readline-3.3-0.src.rock Error: Could not find header file for HISTORY No file readline/history.h in /usr/include No file readline/history.h in /include No file readline/history.h in /usr/local/opt/include You may have to install HISTORY in your system and/or pass HISTORY_DIR or HISTORY_INCDIR to the luarocks command. Example: luarocks install readline HISTORY_DIR=/usr/local
Alright some errors later and I'm cooking
Fennel $ sudo luarocks install readline HISTORY_DIR=/usr/local/ HISTORY_LIBDIR=/usr/local/opt/readline/lib
Well
env MACOSX_DEPLOYMENT_TARGET=11.0 gcc -bundle -undefined dynamic_lookup -all_load -o /tmp/luarocks_build-Readline-3.3-0-2087270/C-readline.so C-readline.o -L/Users/razzi/Downloads/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib -L/usr/local/opt/readline/lib -lreadline -lhistory readline 3.3-0 is now installed in /usr/local (license: MIT/X11) Fennel $ ./fennel Welcome to Fennel 1.5.2-dev on PUC Lua 5.4! Use ,help to see available commands. Try installing readline via luarocks for a better repl experience. >> 3 3 >> ^P
Maybe recompiling fennel will fix it
Well I found the error was in the .so:
>> (pcall require :readline) false "error loading module 'C-readline' from file '/usr/local/lib/lua/5.4/C-readline.so': \tdlopen(/usr/local/lib/lua/5.4/C-readline.so, 6): Symbol not found: _rl_callback_sigcleanup Referenced from: /usr/local/lib/lua/5.4/C-readline.so Expected in: flat namespace in /usr/local/lib/lua/5.4/C-readline.so"
So I tried uninstalling readline to see if it'd remove that file, and it did... and fixed the error o_O
Fennel $ sudo luarocks remove readline Checking stability of dependencies in the absence of readline 3.3-0... Removing readline 3.3-0... Removal successful. Fennel $ ls /usr/local/lib/lua/5.4/C-readline.so ls: /usr/local/lib/lua/5.4/C-readline.so: No such file or directory Fennel $ ./fennel Welcome to Fennel 1.5.2-dev on PUC Lua 5.4! Use ,help to see available commands. >>
Weirdly if I put 3 it doesn't show up in command history... anyways the editor should be able to connect a more featureful repl ... heh
---
Ok so rather than jump right into the fennel environment, I can start by making my editor in lua and then add fennel scripting support. Then eventually rewrite the editor in fennel other than a short bootstrap ... if I want ... lua ain't that bad. But it's harder to evaluate interactively due to its lack of explicit parens () !
The first thing for my editor to do is respond to keys being pressed. Like a c getch(). So forgetting about file IO for a moment, my "editor" is going to start looking like a command line, but each key press is handled by the program and printed individually - one at a time style. When you hit (? some key that is like quit)
(could be c-q for now)
it'll exit the program and say "you entered x bytes. Saving to (datetime).txt" - something like that.
So I want to get a single character. https://github.com/max1220/lua-getch should work but it doesn't work on mac I guess. Probably read its source code (c) and port it