From c6d775bd0c52748c2efa910aaf754cbef43d16b8 Mon Sep 17 00:00:00 2001 From: Austin Miller Date: Sun, 21 Jan 2024 12:59:07 -0800 Subject: [PATCH 1/3] guile: append stray output to log This checks to see if there was a result found and if so gathers all text from after the end of the last prompt until '$n = ...'. If not then everything from the last prompt up until the next is gathered. In either scenario the stray text is appended to Conjure's log. This makes the Guile client more consistent with the built-in Fennel client. Also, this uses Fennel's support for multiple cond/body pairs within if forms thus removing a nested if. --- fnl/conjure/client/guile/socket.fnl | 34 +++++++++++++++++------------ fnl/conjure/sponsors.fnl | 1 - lua/conjure/client/guile/socket.lua | 25 +++++++++++++-------- lua/conjure/sponsors.lua | 2 +- 4 files changed, 37 insertions(+), 25 deletions(-) diff --git a/fnl/conjure/client/guile/socket.fnl b/fnl/conjure/client/guile/socket.fnl index ac63eb21..474303a9 100644 --- a/fnl/conjure/client/guile/socket.fnl +++ b/fnl/conjure/client/guile/socket.fnl @@ -115,22 +115,28 @@ (defn- parse-guile-result [s] (let [prompt (s:find "scheme@%([%w%-%s]+%)> ")] - (if prompt - (let [(ind1 ind2 result) (s:find "%$%d+ = ([^\n]+)\n")] - (if result - {:done? true - :error? false - :result result} - {:done? true - :error? false - :result (s:sub 1 (- prompt 1))})) - (if (s:find "scheme@%([%w%-%s]+%) %[%d+%]>") + (if + prompt + (let [(ind1 _ result) (s:find "%$%d+ = ([^\n]+)\n") + stray-output (s:sub + 1 + (- (if result ind1 prompt) 1))] + (when (> (length stray-output) 0) + (log.append + (-> (text.trim-last-newline stray-output) + (text.prefixed-lines "; (out) ")))) {:done? true - :error? true - :result nil} - {:done? false :error? false - :result s})))) + :result result}) + + (s:find "scheme@%([%w%-%s]+%) %[%d+%]>") + {:done? true + :error? true + :result nil} + + {:done? false + :error? false + :result s}))) (defn connect [opts] (disconnect) diff --git a/fnl/conjure/sponsors.fnl b/fnl/conjure/sponsors.fnl index 756d9371..743bad08 100644 --- a/fnl/conjure/sponsors.fnl +++ b/fnl/conjure/sponsors.fnl @@ -1,5 +1,4 @@ [ ;; Generated by: make sponsors -"AbhinavOmprakash" "Akeboshiwind" "aleksandersumowski" "AlexChalk" diff --git a/lua/conjure/client/guile/socket.lua b/lua/conjure/client/guile/socket.lua index b7e34336..1ebcc50d 100644 --- a/lua/conjure/client/guile/socket.lua +++ b/lua/conjure/client/guile/socket.lua @@ -156,18 +156,25 @@ _2amodule_2a["disconnect"] = disconnect local function parse_guile_result(s) local prompt = s:find("scheme@%([%w%-%s]+%)> ") if prompt then - local ind1, ind2, result = s:find("%$%d+ = ([^\n]+)\n") - if result then - return {["done?"] = true, result = result, ["error?"] = false} - else - return {["done?"] = true, result = s:sub(1, (prompt - 1)), ["error?"] = false} + local ind1, _0, result = s:find("%$%d+ = ([^\n]+)\n") + local stray_output + local function _21_() + if result then + return ind1 + else + return prompt + end end - else - if s:find("scheme@%([%w%-%s]+%) %[%d+%]>") then - return {["done?"] = true, ["error?"] = true, result = nil} + stray_output = s:sub(1, (_21_() - 1)) + if (#stray_output > 0) then + log.append(text["prefixed-lines"](text["trim-last-newline"](stray_output), "; (out) ")) else - return {result = s, ["done?"] = false, ["error?"] = false} end + return {["done?"] = true, result = result, ["error?"] = false} + elseif s:find("scheme@%([%w%-%s]+%) %[%d+%]>") then + return {["done?"] = true, ["error?"] = true, result = nil} + else + return {result = s, ["done?"] = false, ["error?"] = false} end end _2amodule_locals_2a["parse-guile-result"] = parse_guile_result diff --git a/lua/conjure/sponsors.lua b/lua/conjure/sponsors.lua index 4dec0e77..edc4d6bc 100644 --- a/lua/conjure/sponsors.lua +++ b/lua/conjure/sponsors.lua @@ -1,2 +1,2 @@ local _2afile_2a = "fnl/conjure/sponsors.fnl" -return {"AbhinavOmprakash", "Akeboshiwind", "aleksandersumowski", "AlexChalk", "alloy-d", "anthony-khong", "axvr", "beanpuppy", "BerkeleyTrue", "campbellr", "daveyarwood", "davidmh", "dharrigan", "djwhitt", "edlandm", "extradosages", "frenchy64", "fuadsaud", "harrisoncramer", "harrygallagher4", "jacobobryant", "jcpsantiago", "jkrasnay", "ketansrivastav", "kevinkrouse", "lucasdf", "lucaslollobrigida", "martinklepsch", "NickCellino", "nickcernis", "orestis", "penryu", "pyrmont", "qnkhuat", "rafaeldelboni", "rbatista", "rgm", "stelcodes", "thiru", "TimoKramer", "trev-dev", "valsen", "victorb", "zhming0"} \ No newline at end of file +return {"Akeboshiwind", "aleksandersumowski", "AlexChalk", "alloy-d", "anthony-khong", "axvr", "beanpuppy", "BerkeleyTrue", "campbellr", "daveyarwood", "davidmh", "dharrigan", "djwhitt", "edlandm", "extradosages", "frenchy64", "fuadsaud", "harrisoncramer", "harrygallagher4", "jacobobryant", "jcpsantiago", "jkrasnay", "ketansrivastav", "kevinkrouse", "lucasdf", "lucaslollobrigida", "martinklepsch", "NickCellino", "nickcernis", "orestis", "penryu", "pyrmont", "qnkhuat", "rafaeldelboni", "rbatista", "rgm", "stelcodes", "thiru", "TimoKramer", "trev-dev", "valsen", "victorb", "zhming0"} \ No newline at end of file From 1f43cfc996d27731fd54903b7feb9d90971a27ae Mon Sep 17 00:00:00 2001 From: Oliver Caldwell Date: Fri, 2 Feb 2024 12:03:09 +0000 Subject: [PATCH 2/3] Fix / improve localleader defaulting in the school --- fnl/conjure/school.fnl | 22 ++++++++++++---------- lua/conjure/school.lua | 23 ++++++++++++----------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/fnl/conjure/school.fnl b/fnl/conjure/school.fnl index 8d3b5f23..8c56577e 100644 --- a/fnl/conjure/school.fnl +++ b/fnl/conjure/school.fnl @@ -45,13 +45,19 @@ (nvim.ex.autocmd "BufNewFile,BufRead *.fnl setlocal filetype=clojure") (nvim.ex.augroup :END)) - (let [buf (upsert-buf)] + (let [maplocalleader-was-unset? + (when (and (= "" (config.get-in [:mapping :prefix])) + (a.empty? nvim.g.maplocalleader)) + (set nvim.g.maplocalleader ",") + true) + + buf (upsert-buf)] (nvim.ex.edit buf-name) (nvim.buf_set_lines buf 0 -1 false []) (append (a.concat ["(module user.conjure-school" - " {require {school conjure.school}})" + " {require {school conjure.school}})" "" ";; Welcome to Conjure school!" ";; Grab yourself a nice beverage and let's get evaluating. I hope you enjoy!" @@ -66,14 +72,10 @@ ";; You can learn how to change these mappings with :help conjure-mappings" "" (.. ";; Let's begin by evaluating the whole buffer using " (map-str :eval_buf))] - (when (= "" (config.get-in [:mapping :prefix])) - (if (a.empty? nvim.g.maplocalleader) - (do - (set nvim.g.maplocalleader ",") - (nvim.ex.edit) - [";; Your wasn't configured so I've defaulted it to comma (,) for now." - ";; See :help localleader for more information. (let maplocalleader=\",\")"]) - [(.. ";; Your is currently mapped to \"" nvim.g.maplocalleader "\"")])) + (if maplocalleader-was-unset? + [";; Your wasn't configured so I've defaulted it to comma (,) for now." + ";; See :help localleader for more information. (let maplocalleader=\",\")"] + [(.. ";; Your is currently mapped to \"" nvim.g.maplocalleader "\"")]) ["(school.lesson-1)"])))) (defn lesson-1 [] diff --git a/lua/conjure/school.lua b/lua/conjure/school.lua index c90f0ab5..a42b53a2 100644 --- a/lua/conjure/school.lua +++ b/lua/conjure/school.lua @@ -68,22 +68,23 @@ local function start() nvim.ex.augroup("END") else end + local maplocalleader_was_unset_3f + if (("" == config["get-in"]({"mapping", "prefix"})) and a["empty?"](nvim.g.maplocalleader)) then + nvim.g.maplocalleader = "," + maplocalleader_was_unset_3f = true + else + maplocalleader_was_unset_3f = nil + end local buf = upsert_buf() nvim.ex.edit(buf_name) nvim.buf_set_lines(buf, 0, -1, false, {}) - local _6_ - if ("" == config["get-in"]({"mapping", "prefix"})) then - if a["empty?"](nvim.g.maplocalleader) then - nvim.g.maplocalleader = "," - nvim.ex.edit() - _6_ = {";; Your wasn't configured so I've defaulted it to comma (,) for now.", ";; See :help localleader for more information. (let maplocalleader=\",\")"} - else - _6_ = {(";; Your is currently mapped to \"" .. nvim.g.maplocalleader .. "\"")} - end + local _7_ + if maplocalleader_was_unset_3f then + _7_ = {";; Your wasn't configured so I've defaulted it to comma (,) for now.", ";; See :help localleader for more information. (let maplocalleader=\",\")"} else - _6_ = nil + _7_ = {(";; Your is currently mapped to \"" .. nvim.g.maplocalleader .. "\"")} end - return append(a.concat({"(module user.conjure-school", " {require {school conjure.school}})", "", ";; Welcome to Conjure school!", ";; Grab yourself a nice beverage and let's get evaluating. I hope you enjoy!", "", ";; This language is Fennel, it's quite similar to Clojure.", ";; Conjure is written in Fennel, it's compiled to Lua and executed inside Neovim itself.", ";; This means we can work with a Lisp without installing or running anything else.", "", ";; Note: Some colorschemes will make the HUD unreadable, see here for more: https://git.io/JJ1Hl", "", ";; Let's learn how to evaluate it using Conjure's assortment of mappings.", ";; You can learn how to change these mappings with :help conjure-mappings", "", (";; Let's begin by evaluating the whole buffer using " .. map_str("eval_buf"))}, _6_, {"(school.lesson-1)"})) + return append(a.concat({"(module user.conjure-school", " {require {school conjure.school}})", "", ";; Welcome to Conjure school!", ";; Grab yourself a nice beverage and let's get evaluating. I hope you enjoy!", "", ";; This language is Fennel, it's quite similar to Clojure.", ";; Conjure is written in Fennel, it's compiled to Lua and executed inside Neovim itself.", ";; This means we can work with a Lisp without installing or running anything else.", "", ";; Note: Some colorschemes will make the HUD unreadable, see here for more: https://git.io/JJ1Hl", "", ";; Let's learn how to evaluate it using Conjure's assortment of mappings.", ";; You can learn how to change these mappings with :help conjure-mappings", "", (";; Let's begin by evaluating the whole buffer using " .. map_str("eval_buf"))}, _7_, {"(school.lesson-1)"})) end _2amodule_2a["start"] = start local function lesson_1() From 6546acc2db247482b7707d355e9611ec2d086a14 Mon Sep 17 00:00:00 2001 From: Oliver Caldwell Date: Fri, 2 Feb 2024 12:25:40 +0000 Subject: [PATCH 3/3] Add more Guile testing tools --- .nvim.fnl | 3 +++ dev/guile/sandbox.scm | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/.nvim.fnl b/.nvim.fnl index 4d708e9b..ffc6517c 100644 --- a/.nvim.fnl +++ b/.nvim.fnl @@ -8,6 +8,9 @@ ; (set vim.g.conjure#client#scheme#stdio#prompt_pattern "\n-#;%d-> ") ; (set vim.g.conjure#mapping#enable_defaults false) +; (set vim.g.conjure#filetype#scheme "conjure.client.guile.socket") +; (set vim.g.conjure#client#guile#socket#pipename "guile-repl.socket") + ; (set vim.g.conjure#client#python#stdio#command "ipython --classic") diff --git a/dev/guile/sandbox.scm b/dev/guile/sandbox.scm index 27f271c6..8f95e17b 100644 --- a/dev/guile/sandbox.scm +++ b/dev/guile/sandbox.scm @@ -5,3 +5,16 @@ (+ 5 6) (add 1 2) + +(define (print-hi-and-return x) + (begin + (display "Hi") + (newline)) + x) + +(print-hi-and-return 123) + +(define (return-values) + (values 123 "Hi")) + +(return-values)