lite-xl 2.1 support, sort of (currently requires hack for luasocket)

some nrepl fixes, "project file" support for customizing lite-xl on a
per-project basis by loading a fennel file
This commit is contained in:
Jeremy Penner 2022-12-27 21:20:44 -05:00
parent 8872d0f828
commit 1bcea81f43
6 changed files with 49 additions and 16 deletions

View file

@ -79,7 +79,7 @@ local function count(tbl)
end
function encode(x)
local unpack = unpack or table.unpack
local unpack = rawget(_G, "unpack") or table.unpack
if(type(x) == "table" and select("#", unpack(x)) == count(x)) then
return encode_list(x)
elseif(type(x) == "table") then

View file

@ -66,8 +66,8 @@
"repl:create" #(show)
"repl:switch-connection"
#(core.command_view:enter "Connection Type"
#(when $2.text (set replsession.default-repl $2.text))
#(mm.keys replsession.submit))
{:submit #(when $2.text (set replsession.default-repl $2.text))
:suggest #(mm.keys replsession.submit)})
})
(command.add #(nrepl:connected?) {
@ -106,7 +106,7 @@
(fn autocomplete-symbol [callback ?starting-text]
(fn fixup-result [text item] (callback (or (and item item.text) text)))
(core.command_view:enter "Symbol" fixup-result autocomplete-results)
(core.command_view:enter "Symbol" {:submit fixup-result :suggest autocomplete-results})
(print "start-text" ?starting-text)
(when ?starting-text
(core.command_view:set_text ?starting-text)

View file

@ -1,8 +1,9 @@
-- mod-version:2 -- lite-xl 2.0
-- mod-version:3 -- lite-xl 2.1
local fennel = require "plugins.fennel-xl.fennel"
fennel.path = package.path:gsub("%.lua", ".fnl")
debug.traceback = fennel.traceback
table.insert(package.loaders or package.searchers, fennel.searcher)
require "plugins.fennel-xl.editor"
require "plugins.fennel-xl.project"

View file

@ -16,7 +16,8 @@
(self:do #(nrepl:new-session
#(do (set self.session $2)
(self:done-msg))
(self:make-handlers)))))
(self:make-handlers))
true)))
(fn Session.shutdown-session [self]
(set self.queue [])
@ -42,8 +43,9 @@
{:status/done #(coroutine.resume coro)
:status/interrupted #(coroutine.resume coro)})))
(fn Session.do [self f]
(if self.in-progress (table.insert self.queue f)
(fn Session.do [self f ?init]
(if (or self.in-progress (and (not ?init) (= self.session nil)) )
(table.insert self.queue f)
(do (set self.in-progress true)
(f))))
@ -73,15 +75,18 @@
(lume.merge (or ?handlers {}) (self:input-handler input))))
(local fennel (require :plugins.fennel-xl.fennel))
(fn parse-vals [s]
(let [parser (fennel.parser s)]
(icollect [ok ast (fennel.parser s)] (if ok ast s))))
(fn parse-vals [s] [s])
; (let [parser (fennel.parser s)]
; (icollect [ok ast (fennel.parser s)] (if ok ast s))))
(defmethod restart :nrepl (fn [session]
(when (not (nrepl:connected?)) (error "Must connect nrepl"))
(when session.conn (session.conn:shutdown-session))
(set session.conn (Session))
(session.conn:init-session)
(if (not (nrepl:connected?))
(nrepl:connect {:host session.host
:port session.port
:on-connect #(session.conn:init-session)})
(session.conn:init-session))
session))
(defmethod submit :nrepl (fn [session chunk callback ?suppress-crash]

View file

@ -90,14 +90,16 @@
(set self.active-requests {})
(set self.session-handlers {})))
:connect
(fn [self ?port ?host]
(fn [self ?opt]
(when (not self.connection)
(local (port host) (values (or ?port 7888) (or ?host :localhost)))
(local opt (or ?opt {}))
(local (port host) (values (or opt.port 7888) (or opt.host :localhost)))
(set self.connection (assert (socket.connect host port)))
(self.connection:settimeout 0)
(core.add_thread #(while true (self:receive) (coroutine.yield)) self)
(self:send {:op :clone}
{:new-session #(set self.default-session $2)})))
{:new-session #(do (set self.default-session $2)
(when opt.on-connect (opt.on-connect self)))})))
:connected?
(fn [self] (not= self.default-session nil))
:new-session

25
project.fnl Normal file
View file

@ -0,0 +1,25 @@
(local core (require :core))
(local fennel (require :plugins.fennel-xl.fennel))
(fn load-fennel-project-file [dir]
(let [project-path (.. dir _G.PATHSEP "lite-xl-project.fnl")
fennel-path fennel.path]
(when (system.get_file_info project-path)
; temporarily allow importing project-local modules
(set fennel.path (.. fennel-path ";" project-path _G.PATHSEP "?.fnl;" project-path _G.PATHSEP "?" _G.PATHSEP "init.fnl"))
(fennel.dofile project-path)
(set fennel.path fennel-path))))
(let [run core.run]
(fn core.run [...]
; when a new lite-xl window opens with a project, on_enter_project is _not_ called
(core.try load-fennel-project-file core.project_dir)
(let [on-enter-project core.on_enter_project]
(fn core.on_enter_project [new-dir]
(on-enter-project new-dir)
(core.try load-fennel-project-file new-dir)))
(set core.run run)
(run ...)))
{}