Initial checkin

This commit is contained in:
Jeremy Penner 2021-02-07 16:56:19 -05:00
commit 23b6193024
615 changed files with 163774 additions and 0 deletions

5
conf.lua Normal file
View file

@ -0,0 +1,5 @@
function love.conf(t)
t.window.width = 1280
t.window.height = 1000
t.window.resizable = true
end

17
editor/editmode.fnl Normal file
View file

@ -0,0 +1,17 @@
(local modes (require :editor.lovemode))
(local core (require :core))
(local events [])
(local editor-mode
{:draw system.draw_love_frame
:update (fn [...]
(when (and core.active_view core.active_view.handle-love-update)
(core.active_view:handle-love-update ...)))
:handler (fn [...]
(system.enqueue_love_event ...)
(when (and core.active_view core.active_view.handle-love-event)
(core.active_view:handle-love-event ...)))})
(modes:register :editor editor-mode)
{: editor-mode : events}

215
editor/imstate.fnl Normal file
View file

@ -0,0 +1,215 @@
(local core (require :core))
(local config (require :core.config))
(local command (require :core.command))
(local keymap (require :core.keymap))
(local style (require :core.style))
(local lume (require :lib.lume))
(fn attach-imstate [view]
(set view.imstate {})
(fn view.on_mouse_pressed [self button x y clicks]
(tset self.imstate button :pressed)
(self.__index.on_mouse_pressed self button x y clicks))
(fn view.on_mouse_released [self button x y]
(tset self.imstate button :released)
(self.__index.on_mouse_released self button x y))
(fn view.on_key_pressed [self key]
(when (= self.imstate.keys nil)
(set self.imstate.keys []))
(table.insert self.imstate.keys key))
(fn view.on_text_input [self text]
(set self.imstate.text (.. (or self.imstate.text "") text))
(self.__index.on_text_input self text))
(fn view.draw [self]
(set self.cursor nil)
(self.__index.draw self)
(when (= self.cursor nil) (set self.cursor :arrow))
(set self.imstate.keys nil)
(set self.imstate.text nil)
(when (= self.imstate.left :released)
(set self.imstate.active nil))
(each [_ button (pairs [:left :middle :right])]
(tset self.imstate button
(match (. self.imstate button)
:pressed :down
:down :down
:released nil)))))
(fn register-keys [keys]
(local commands {})
(local keymaps {})
(each [_ key (ipairs keys)]
(local command-name (.. "imstate:" key))
(tset commands command-name #(core.active_view:on_key_pressed key))
(tset keymaps key command-name))
(command.add #(not= (-?> core.active_view.imstate (. :focus)) nil) commands)
(keymap.add keymaps))
(register-keys [:backspace :delete :left :right :shift+left :shift+right :home :end :shift+home :shift+end
:ctrl+left :ctrl+right :ctrl+shift+left :ctrl+shift+right :ctrl+c :ctrl+v])
(fn cmd-predicate [p]
(var p-fn p)
(when (= (type p-fn) :string) (set p-fn (require p-fn)))
(when (= (type p-fn) :table)
(local cls p-fn)
(set p-fn (fn [] (core.active_view:is cls))))
(fn [] (when (= (-?> core.active_view.imstate (. :focus)) nil)
(p-fn))))
(fn make-tag [tag]
(match (type tag)
:string tag
:table (table.concat tag "::")
_ (tostring tag)))
(fn mouse-inside [x y w h]
(local (mx my) (values (love.mouse.getX) (love.mouse.getY)))
(and (>= mx x) (<= mx (+ x w)) (>= my y) (<= my (+ y h))))
(fn activate [view tag x y w h]
(when (and (= view.imstate.left :pressed) (mouse-inside x y w h))
(set view.imstate.active (make-tag tag))
true))
(fn active? [view tag] (= view.imstate.active (make-tag tag)))
(fn button [view tag x y w h]
(when (mouse-inside x y w h) (set view.cursor :hand))
(activate view tag x y w h)
(and (active? view tag) (= view.imstate.left :released) (mouse-inside x y w h)))
(fn textbutton [view label x y]
(local (w h) (values (+ (style.font:get_width label) 8) 24))
(renderer.draw_rect x y w h style.selection)
(renderer.draw_text style.font label (+ x 4) (+ y 4) style.text)
(values (button view label x y w h) (+ y h)))
(fn checkbox [view name isset x y ?tag]
(love.graphics.rectangle (if isset :fill :line) x y 12 12)
(local xEnd (renderer.draw_text style.font name (+ x 16) y style.text))
(love.graphics.setColor 1 1 1 1)
(button view (or ?tag name) x y (- xEnd x) 12))
(fn focused? [view tag] (= tag (-?> view.imstate.focus (. :tag))))
(fn focus [view tag x y w h opts]
(if (activate view tag x y w h)
(set view.imstate.focus
(doto (lume.clone (or opts {}))
(tset :tag tag)))
(and (= view.imstate.left :released) (focused? view tag) (not (active? view tag)))
(set view.imstate.focus nil))
(focused? view tag))
(local blink_period 0.8)
(fn x-from-i [s i xLeft font]
(if (or (<= i 1) (= s "")) xLeft
(x-from-i (s:sub 2) (- i 1) (+ xLeft (font:get_width (s:sub 1 1))) font)))
(fn i-from-x [s x xLeft font ?i]
(local i (or ?i 1))
(local w (font:get_width (s:sub 1 1)))
(local xMid (+ xLeft (/ w 2)))
(if (or (<= x xMid) (= s "")) i
(i-from-x (s:sub 2) x (+ xLeft w) font (+ i 1))))
(fn next-match [text i di pred]
(local imax (+ (length text) 1))
(local inext (+ i di))
(if (<= inext 1) 1
(> inext imax) imax
(pred (text:sub inext inext)) (if (< di 0) i inext)
(next-match text inext di pred)))
(fn is-nonword-char [char] (config.non_word_chars:find char nil true))
(fn next-word [text i di]
(let [iwordboundary (next-match text i di #(is-nonword-char $1))]
(next-match text iwordboundary di #(not (is-nonword-char $1)))))
(fn textnav [key i text]
(local imax (+ (length text) 1))
(match key
:left (math.max 1 (- i 1))
:right (math.min imax (+ i 1))
:ctrl+left (next-word text i -1)
:ctrl+right (next-word text i 1)
:home 1
:end imax))
(fn selection-span [view]
(let [f view.imstate.focus
iStart (math.min f.i f.iAnchor)
iLim (math.max f.i f.iAnchor)]
(values iStart iLim)))
(fn selection-text [view text]
(local (iStart iLim) (selection-span view))
(text:sub iStart (- iLim 1)))
(fn replace-selection [view s replacement ?iStart ?iLim]
(local (iStart iLim) (if ?iLim (values ?iStart ?iLim) (selection-span view)))
(local text
(.. (s:sub 1 (- iStart 1))
replacement
(s:sub iLim)))
(local iNew (+ iStart (length replacement)))
(set view.imstate.focus.i iNew)
(set view.imstate.focus.iAnchor iNew)
text)
(fn textbox [view tag text x y w]
(var textNew (or text ""))
(local (h hText xText yText) (values 20 16 (+ x 2) (+ y 2)))
; handle key events
(when (focus view tag x y w h {:i 1 :iAnchor 1 :blink (love.timer.getTime)})
(local f view.imstate.focus)
(when view.imstate.text
(set textNew (replace-selection view textNew view.imstate.text)))
(each [_ key (ipairs (or view.imstate.keys []))]
(set view.imstate.focus.blink (love.timer.getTime))
(if (= key :ctrl+c) (system.set_clipboard (selection-text view textNew))
(= key :ctrl+v) (set textNew (replace-selection view textNew (system.get_clipboard)))
(key:find "shift%+") (set f.i (or (textnav (key:gsub "shift%+" "") f.i textNew) f.i))
(let [iNav (textnav key f.i textNew)]
(when iNav
(set f.i iNav)
(set f.iAnchor iNav))
(when (or (= key :delete) (= key :backspace))
(local (iStartDel iLimDel)
(if (not= f.i f.iAnchor) (selection-span view)
(= key :delete) (values f.i (+ f.i 1))
(= key :backspace) (values (math.max 1 (- f.i 1)) f.i)))
(set textNew (replace-selection view textNew "" iStartDel iLimDel)))))))
; handle mouse events
(when (mouse-inside x y w h) (set view.cursor :ibeam))
(when (and (focused? view tag) (active? view tag) (mouse-inside x y w h))
(local mouse-i (i-from-x textNew (love.mouse.getX) x style.font))
(when (= view.imstate.left :pressed)
(set view.imstate.focus.iAnchor mouse-i))
(set view.imstate.focus.i mouse-i))
; draw box
(love.graphics.setLineWidth 1)
(love.graphics.rectangle :line x y w h)
(if (focused? view tag)
; draw text with selection + caret
(let [(iStart iLim) (selection-span view)
xSelect (renderer.draw_text style.font (textNew:sub 1 (- iStart 1)) xText yText style.text)
sSelect (textNew:sub iStart (- iLim 1))
wSelect (style.font:get_width sSelect)
xTail (+ xSelect wSelect)]
(when (> wSelect 0)
(renderer.draw_rect xSelect yText wSelect hText style.selection)
(renderer.draw_text style.font sSelect xSelect yText style.text))
(renderer.draw_text style.font (textNew:sub iLim) xTail yText style.text)
(when (or (active? view tag)
(< (% (- (love.timer.getTime) view.imstate.focus.blink) (* blink_period 2)) blink_period))
(renderer.draw_rect (x-from-i textNew view.imstate.focus.i xText style.font) yText style.caret_width hText style.caret)))
; just draw the text
(renderer.draw_text style.font textNew xText yText style.text))
(love.graphics.setColor 1 1 1)
(values textNew (+ y h)))
(fn textfield [view label text x y wLabel wText]
(renderer.draw_text style.font label x y style.text)
(textbox view label text (+ x wLabel) y wText))
{: attach-imstate : cmd-predicate : mouse-inside : activate : active? : button : checkbox : textbox : textfield : textbutton}

17
editor/init.fnl Normal file
View file

@ -0,0 +1,17 @@
(local util (require :lib.util))
(local core (require :core))
(local command (require :core.command))
(local keymap (require :core.keymap))
(local common (require :core.common))
(fn inline-eval [eval]
(let [ldoc core.active_view.doc
(aline acol bline bcol) (ldoc:get_selection)
inject #(ldoc:insert bline bcol (eval $1))]
(if (and (= aline bline) (= acol bcol))
(inject (ldoc:get_text aline 1 aline 10000000))
(inject (ldoc:get_text aline acol bline bcol)))))
(require :editor.editmode)
{: inline-eval}

44
editor/lovemode.fnl Normal file
View file

@ -0,0 +1,44 @@
(local lume (require :lib.lume))
(local common (require :core.common))
(local style (require :core.style))
(local std-handlers love.handlers)
(local modes {:name-to-mode {}
:mode-index 1
:names []
: std-handlers})
(fn modes.cycle [self]
(set self.mode-index (+ self.mode-index 1))
(when (> self.mode-index (length self.names))
(set self.mode-index 1))
(self:switch (self:current)))
(fn modes.current [self]
(. self.name-to-mode (. self.names self.mode-index)))
(fn add-mode-cycler [handlers]
(fn mode-cycler [ev key ...]
(when (and (= ev :keyreleased) (= key :f1))
(modes:cycle))
(when (rawget handlers :any) (handlers.any ev key ...)))
(setmetatable {:any mode-cycler} {:__index handlers}))
(fn modes.switch [self mode]
(set love.handlers (add-mode-cycler (if mode.handler {:any mode.handler} std-handlers)))
(set love.update mode.update)
(set love.draw (fn []
(xpcall mode.draw (fn [msg]
(love.graphics.reset)
(love.graphics.setColor 1 0 0 1)
(love.graphics.setNewFont 14)
(love.graphics.printf (.. msg "\n" (debug.traceback))
20 20 (- (love.graphics.getWidth) 40)))))))
(fn modes.register [self name mode]
(tset self.name-to-mode name mode)
(when (not (lume.any self.names #(= $1 name)))
(table.insert self.names name))
(when (= (length self.names) 1) (self:cycle)))
modes

25
editor/modeview.fnl Normal file
View file

@ -0,0 +1,25 @@
(local modes (require :editor.lovemode))
(local View (require :core.view))
(local ModeView (View:extend))
(fn ModeView.new [self mode]
(ModeView.super.new self)
(set self.mode mode))
(fn ModeView.draw [self]
(love.graphics.push :all)
(love.graphics.translate self.position.x self.position.y)
(xpcall self.mode.draw (fn [...] (love.graphics.pop) (error ...)))
(love.graphics.pop))
(fn ModeView.handle-love-update [self ...]
(when self.mode.update (self.mode.update ...)))
(fn ModeView.handle-love-event [self ev ...]
(if self.mode.handler
(self.mode.handler ev ...)
((. modes.std-handlers ev) ...)))
ModeView

View file

@ -0,0 +1,12 @@
(local Entity (require :game.entity))
(local rules (require :game.rules))
(local Bomberman (Entity:extend))
(set Bomberman.keymap {:up :w :down :s :left :a :right :d :bomb :x})
(set Bomberman.color [0.2 0.2 0.2])
(fn Bomberman.update [self dt]
(Bomberman.super.update self dt)
(when (love.keyboard.isDown self.keymap.bomb)
(rules.place-bomb self.x self.y)))
Bomberman

9
game/entities/pacman.fnl Normal file
View file

@ -0,0 +1,9 @@
(local Entity (require :game.entity))
(local rules (require :game.rules))
(local Pacman (Entity:extend))
(set Pacman.keymap {:up :up :down :down :left :left :right :right})
(set Pacman.color [1 1 0])
Pacman

24
game/entity.fnl Normal file
View file

@ -0,0 +1,24 @@
(local util (require :lib.util))
(local {: vec* : dir-from-key} (util.require :game.helpers))
(local rules (require :game.rules))
(local Object (require :core.object))
(local Entity (Object:extend))
(fn Entity.new [self x y]
(set self.x x)
(set self.y y)
(set self.velocity [0 0]))
(fn Entity.draw [self]
(when (= self.color nil)
(set self.color [(math.random) (math.random) (math.random)]))
(love.graphics.setColor (table.unpack self.color))
(love.graphics.circle :fill self.x self.y 16))
(fn Entity.move [self [dx dy]]
(set self.velocity [dx dy])
(set self.x (rules.collide :x self dx))
(set self.y (rules.collide :y self dy)))
(fn Entity.update [self dt]
(self:move (vec* (dir-from-key self.keymap) (* self.speed dt))))
(set Entity.speed 64)
Entity

12
game/helpers.fnl Normal file
View file

@ -0,0 +1,12 @@
(fn dir-from-key [keymap]
(var (dx dy) (values 0 0))
(when (love.keyboard.isDown keymap.up) (set dy -1))
(when (love.keyboard.isDown keymap.down) (set dy 1))
(when (love.keyboard.isDown keymap.left) (set dx -1))
(when (love.keyboard.isDown keymap.right) (set dx 1))
[dx dy])
(fn vec* [vec scalar]
(icollect [_ v (ipairs vec)] (* v scalar)))
{: dir-from-key : vec*}

21
game/init.fnl Normal file
View file

@ -0,0 +1,21 @@
(local util (require :lib.util))
(local modes (require :editor.lovemode))
(local ModeView (require :editor.modeview))
(local state (require :game.state))
(local core (require :core))
(local command (require :core.command))
(local gamemode (require :game.mode))
(modes:register :game gamemode)
(set state.entities
[((require :game.entities.bomberman) 20 20)
((require :game.entities.pacman) 350 350)])
(command.add nil {
"love:game" (fn []
(let [node (core.root_view:get_active_node)]
(node:add_view (ModeView gamemode))))
})
{}

12
game/mode.fnl Normal file
View file

@ -0,0 +1,12 @@
(local state (require :game.state))
(fn update [dt]
(each [_ entity (ipairs state.entities)]
(entity:update dt)))
(fn draw []
(each [_ entity (ipairs state.entities)]
(entity:draw)))
{: update : draw}

8
game/rules.fnl Normal file
View file

@ -0,0 +1,8 @@
(local state (require :game.state))
(fn collide [axis entity d]
(+ (. entity axis) d))
(fn place-bomb [x y])
{: collide : place-bomb}

1
game/state.fnl Normal file
View file

@ -0,0 +1 @@
{}

16
game/tiles.fnl Normal file
View file

@ -0,0 +1,16 @@
(local tiles
[{:name :empty
:draw (fn [])}
{:name :strongwall
:draw (fn [x y w h]
(love.graphics.setColor 0.4 0.4 0.4)
(love.graphics.rectangle :fill x y w h))}
{:name :weakwall
:draw (fn [x y w h]
(love.graphics.setColor 0.4 0.4 0.4)
(love.graphics.rectangle :fill x y w h))}
{:name :dot
:draw (fn [x y w h]
(love.graphics.setColor 1 1 1)
(love.graphics.circle :fill x y w 5))}
])

89
lib/bencode.lua Normal file
View file

@ -0,0 +1,89 @@
-- Based on bencode.lua from the jeejah project by Phil Hagelberg
-- Distributed under the MIT license
-- https://gitlab.com/technomancy/jeejah/
local encode, decode
local function decode_list(str, t, total_len)
-- print("list", str, lume.serialize(t))
if #str == 0 then error("Incomplete") end
if(str:sub(1,1) == "e") then return t, total_len + 1 end
local value, v_len = decode(str)
table.insert(t, value)
total_len = total_len + v_len
return decode_list(str:sub(v_len + 1), t, total_len)
end
local function decode_table(str, t, total_len)
-- print("table", str, lume.serialize(t))
if #str == 0 then error("Incomplete") end
if(str:sub(1,1) == "e") then return t, total_len + 1 end
local key, k_len = decode(str)
local value, v_len = decode(str:sub(k_len+1))
local end_pos = 1 + k_len + v_len
t[key] = value
total_len = total_len + k_len + v_len
return decode_table(str:sub(end_pos), t, total_len)
end
function decode(str)
-- print("decoding", str)
if #str == 0 then
error("Incomplete")
elseif(str:sub(1,1) == "l") then
return decode_list(str:sub(2), {}, 1)
elseif(str:sub(1,1) == "d") then
return decode_table(str:sub(2), {}, 1)
elseif(str:sub(1,1) == "i") then
local iend = str:find("e")
if iend == nil then error("Incomplete") end
return(tonumber(str:sub(2, iend - 1))), iend
elseif(str:match("[0-9]+:")) then
local num_str = str:match("[0-9]+")
local beginning_of_string = #num_str + 2
local str_len = tonumber(num_str)
local total_len = beginning_of_string + str_len - 1
if #str < total_len then error("Incomplete") end
return str:sub(beginning_of_string, total_len), total_len
else
error("Could not parse "..str)
end
end
local function encode_str(s) return #s .. ":" .. s end
local function encode_int(n) return "i" .. tostring(n) .. "e" end
local function encode_table(t)
local s = "d"
for k,v in pairs(t) do s = s .. encode(k) .. encode(v) end
return s .. "e"
end
local function encode_list(l)
local s = "l"
for _,x in ipairs(l) do s = s .. encode(x) end
return s .. "e"
end
local function count(tbl)
local i = 0
for _ in pairs(tbl) do i = i + 1 end
return i
end
function encode(x)
local unpack = unpack or table.unpack
if(type(x) == "table" and select("#", unpack(x)) == count(x)) then
return encode_list(x)
elseif(type(x) == "table") then
return encode_table(x)
elseif(type(x) == "number" and math.floor(x) == x) then
return encode_int(x)
elseif(type(x) == "string") then
return encode_str(x)
else
error("Could not encode " .. type(x) .. ": " .. tostring(x))
end
end
return {decode=decode, encode=encode}

714
lib/dkjson.lua Normal file
View file

@ -0,0 +1,714 @@
-- Module options:
local always_try_using_lpeg = true
local register_global_module_table = false
local global_module_name = 'json'
--[==[
David Kolf's JSON module for Lua 5.1/5.2
Version 2.5
For the documentation see the corresponding readme.txt or visit
<http://dkolf.de/src/dkjson-lua.fsl/>.
You can contact the author by sending an e-mail to 'david' at the
domain 'dkolf.de'.
Copyright (C) 2010-2013 David Heiko Kolf
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
--]==]
-- global dependencies:
local pairs, type, tostring, tonumber, getmetatable, setmetatable, rawset =
pairs, type, tostring, tonumber, getmetatable, setmetatable, rawset
local error, require, pcall, select = error, require, pcall, select
local floor, huge = math.floor, math.huge
local strrep, gsub, strsub, strbyte, strchar, strfind, strlen, strformat =
string.rep, string.gsub, string.sub, string.byte, string.char,
string.find, string.len, string.format
local strmatch = string.match
local concat = table.concat
local json = { version = "dkjson 2.5" }
if register_global_module_table then
_G[global_module_name] = json
end
local _ENV = nil -- blocking globals in Lua 5.2
pcall (function()
-- Enable access to blocked metatables.
-- Don't worry, this module doesn't change anything in them.
local debmeta = require "debug".getmetatable
if debmeta then getmetatable = debmeta end
end)
json.null = setmetatable ({}, {
__tojson = function () return "null" end
})
local function isarray (tbl)
local max, n, arraylen = 0, 0, 0
for k,v in pairs (tbl) do
if k == 'n' and type(v) == 'number' then
arraylen = v
if v > max then
max = v
end
else
if type(k) ~= 'number' or k < 1 or floor(k) ~= k then
return false
end
if k > max then
max = k
end
n = n + 1
end
end
if max > 10 and max > arraylen and max > n * 2 then
return false -- don't create an array with too many holes
end
return true, max
end
local escapecodes = {
["\""] = "\\\"", ["\\"] = "\\\\", ["\b"] = "\\b", ["\f"] = "\\f",
["\n"] = "\\n", ["\r"] = "\\r", ["\t"] = "\\t"
}
local function escapeutf8 (uchar)
local value = escapecodes[uchar]
if value then
return value
end
local a, b, c, d = strbyte (uchar, 1, 4)
a, b, c, d = a or 0, b or 0, c or 0, d or 0
if a <= 0x7f then
value = a
elseif 0xc0 <= a and a <= 0xdf and b >= 0x80 then
value = (a - 0xc0) * 0x40 + b - 0x80
elseif 0xe0 <= a and a <= 0xef and b >= 0x80 and c >= 0x80 then
value = ((a - 0xe0) * 0x40 + b - 0x80) * 0x40 + c - 0x80
elseif 0xf0 <= a and a <= 0xf7 and b >= 0x80 and c >= 0x80 and d >= 0x80 then
value = (((a - 0xf0) * 0x40 + b - 0x80) * 0x40 + c - 0x80) * 0x40 + d - 0x80
else
return ""
end
if value <= 0xffff then
return strformat ("\\u%.4x", value)
elseif value <= 0x10ffff then
-- encode as UTF-16 surrogate pair
value = value - 0x10000
local highsur, lowsur = 0xD800 + floor (value/0x400), 0xDC00 + (value % 0x400)
return strformat ("\\u%.4x\\u%.4x", highsur, lowsur)
else
return ""
end
end
local function fsub (str, pattern, repl)
-- gsub always builds a new string in a buffer, even when no match
-- exists. First using find should be more efficient when most strings
-- don't contain the pattern.
if strfind (str, pattern) then
return gsub (str, pattern, repl)
else
return str
end
end
local function quotestring (value)
-- based on the regexp "escapable" in https://github.com/douglascrockford/JSON-js
value = fsub (value, "[%z\1-\31\"\\\127]", escapeutf8)
if strfind (value, "[\194\216\220\225\226\239]") then
value = fsub (value, "\194[\128-\159\173]", escapeutf8)
value = fsub (value, "\216[\128-\132]", escapeutf8)
value = fsub (value, "\220\143", escapeutf8)
value = fsub (value, "\225\158[\180\181]", escapeutf8)
value = fsub (value, "\226\128[\140-\143\168-\175]", escapeutf8)
value = fsub (value, "\226\129[\160-\175]", escapeutf8)
value = fsub (value, "\239\187\191", escapeutf8)
value = fsub (value, "\239\191[\176-\191]", escapeutf8)
end
return "\"" .. value .. "\""
end
json.quotestring = quotestring
local function replace(str, o, n)
local i, j = strfind (str, o, 1, true)
if i then
return strsub(str, 1, i-1) .. n .. strsub(str, j+1, -1)
else
return str
end
end
-- locale independent num2str and str2num functions
local decpoint, numfilter
local function updatedecpoint ()
decpoint = strmatch(tostring(0.5), "([^05+])")
-- build a filter that can be used to remove group separators
numfilter = "[^0-9%-%+eE" .. gsub(decpoint, "[%^%$%(%)%%%.%[%]%*%+%-%?]", "%%%0") .. "]+"
end
updatedecpoint()
local function num2str (num)
return replace(fsub(tostring(num), numfilter, ""), decpoint, ".")
end
local function str2num (str)
local num = tonumber(replace(str, ".", decpoint))
if not num then
updatedecpoint()
num = tonumber(replace(str, ".", decpoint))
end
return num
end
local function addnewline2 (level, buffer, buflen)
buffer[buflen+1] = "\n"
buffer[buflen+2] = strrep (" ", level)
buflen = buflen + 2
return buflen
end
function json.addnewline (state)
if state.indent then
state.bufferlen = addnewline2 (state.level or 0,
state.buffer, state.bufferlen or #(state.buffer))
end
end
local encode2 -- forward declaration
local function addpair (key, value, prev, indent, level, buffer, buflen, tables, globalorder, state)
local kt = type (key)
if kt ~= 'string' and kt ~= 'number' then
return nil, "type '" .. kt .. "' is not supported as a key by JSON."
end
if prev then
buflen = buflen + 1
buffer[buflen] = ","
end
if indent then
buflen = addnewline2 (level, buffer, buflen)
end
buffer[buflen+1] = quotestring (key)
buffer[buflen+2] = ":"
return encode2 (value, indent, level, buffer, buflen + 2, tables, globalorder, state)
end
local function appendcustom(res, buffer, state)
local buflen = state.bufferlen
if type (res) == 'string' then
buflen = buflen + 1
buffer[buflen] = res
end
return buflen
end
local function exception(reason, value, state, buffer, buflen, defaultmessage)
defaultmessage = defaultmessage or reason
local handler = state.exception
if not handler then
return nil, defaultmessage
else
state.bufferlen = buflen
local ret, msg = handler (reason, value, state, defaultmessage)
if not ret then return nil, msg or defaultmessage end
return appendcustom(ret, buffer, state)
end
end
function json.encodeexception(reason, value, state, defaultmessage)
return quotestring("<" .. defaultmessage .. ">")
end
encode2 = function (value, indent, level, buffer, buflen, tables, globalorder, state)
local valtype = type (value)
local valmeta = getmetatable (value)
valmeta = type (valmeta) == 'table' and valmeta -- only tables
local valtojson = valmeta and valmeta.__tojson
if valtojson then
if tables[value] then
return exception('reference cycle', value, state, buffer, buflen)
end
tables[value] = true
state.bufferlen = buflen
local ret, msg = valtojson (value, state)
if not ret then return exception('custom encoder failed', value, state, buffer, buflen, msg) end
tables[value] = nil
buflen = appendcustom(ret, buffer, state)
elseif value == nil then
buflen = buflen + 1
buffer[buflen] = "null"
elseif valtype == 'number' then
local s
if value ~= value or value >= huge or -value >= huge then
-- This is the behaviour of the original JSON implementation.
s = "null"
else
s = num2str (value)
end
buflen = buflen + 1
buffer[buflen] = s
elseif valtype == 'boolean' then
buflen = buflen + 1
buffer[buflen] = value and "true" or "false"
elseif valtype == 'string' then
buflen = buflen + 1
buffer[buflen] = quotestring (value)
elseif valtype == 'table' then
if tables[value] then
return exception('reference cycle', value, state, buffer, buflen)
end
tables[value] = true
level = level + 1
local isa, n = isarray (value)
if n == 0 and valmeta and valmeta.__jsontype == 'object' then
isa = false
end
local msg
if isa then -- JSON array
buflen = buflen + 1
buffer[buflen] = "["
for i = 1, n do
buflen, msg = encode2 (value[i], indent, level, buffer, buflen, tables, globalorder, state)
if not buflen then return nil, msg end
if i < n then
buflen = buflen + 1
buffer[buflen] = ","
end
end
buflen = buflen + 1
buffer[buflen] = "]"
else -- JSON object
local prev = false
buflen = buflen + 1
buffer[buflen] = "{"
local order = valmeta and valmeta.__jsonorder or globalorder
if order then
local used = {}
n = #order
for i = 1, n do
local k = order[i]
local v = value[k]
if v then
used[k] = true
buflen, msg = addpair (k, v, prev, indent, level, buffer, buflen, tables, globalorder, state)
prev = true -- add a seperator before the next element
end
end
for k,v in pairs (value) do
if not used[k] then
buflen, msg = addpair (k, v, prev, indent, level, buffer, buflen, tables, globalorder, state)
if not buflen then return nil, msg end
prev = true -- add a seperator before the next element
end
end
else -- unordered
for k,v in pairs (value) do
buflen, msg = addpair (k, v, prev, indent, level, buffer, buflen, tables, globalorder, state)
if not buflen then return nil, msg end
prev = true -- add a seperator before the next element
end
end
if indent then
buflen = addnewline2 (level - 1, buffer, buflen)
end
buflen = buflen + 1
buffer[buflen] = "}"
end
tables[value] = nil
else
return exception ('unsupported type', value, state, buffer, buflen,
"type '" .. valtype .. "' is not supported by JSON.")
end
return buflen
end
function json.encode (value, state)
state = state or {}
local oldbuffer = state.buffer
local buffer = oldbuffer or {}
state.buffer = buffer
updatedecpoint()
local ret, msg = encode2 (value, state.indent, state.level or 0,
buffer, state.bufferlen or 0, state.tables or {}, state.keyorder, state)
if not ret then
error (msg, 2)
elseif oldbuffer == buffer then
state.bufferlen = ret
return true
else
state.bufferlen = nil
state.buffer = nil
return concat (buffer)
end
end
local function loc (str, where)
local line, pos, linepos = 1, 1, 0
while true do
pos = strfind (str, "\n", pos, true)
if pos and pos < where then
line = line + 1
linepos = pos
pos = pos + 1
else
break
end
end
return "line " .. line .. ", column " .. (where - linepos)
end
local function unterminated (str, what, where)
return nil, strlen (str) + 1, "unterminated " .. what .. " at " .. loc (str, where)
end
local function scanwhite (str, pos)
while true do
pos = strfind (str, "%S", pos)
if not pos then return nil end
local sub2 = strsub (str, pos, pos + 1)
if sub2 == "\239\187" and strsub (str, pos + 2, pos + 2) == "\191" then
-- UTF-8 Byte Order Mark
pos = pos + 3
elseif sub2 == "//" then
pos = strfind (str, "[\n\r]", pos + 2)
if not pos then return nil end
elseif sub2 == "/*" then
pos = strfind (str, "*/", pos + 2)
if not pos then return nil end
pos = pos + 2
else
return pos
end
end
end
local escapechars = {
["\""] = "\"", ["\\"] = "\\", ["/"] = "/", ["b"] = "\b", ["f"] = "\f",
["n"] = "\n", ["r"] = "\r", ["t"] = "\t"
}
local function unichar (value)
if value < 0 then
return nil
elseif value <= 0x007f then
return strchar (value)
elseif value <= 0x07ff then
return strchar (0xc0 + floor(value/0x40),
0x80 + (floor(value) % 0x40))
elseif value <= 0xffff then
return strchar (0xe0 + floor(value/0x1000),
0x80 + (floor(value/0x40) % 0x40),
0x80 + (floor(value) % 0x40))
elseif value <= 0x10ffff then
return strchar (0xf0 + floor(value/0x40000),
0x80 + (floor(value/0x1000) % 0x40),
0x80 + (floor(value/0x40) % 0x40),
0x80 + (floor(value) % 0x40))
else
return nil
end
end
local function scanstring (str, pos)
local lastpos = pos + 1
local buffer, n = {}, 0
while true do
local nextpos = strfind (str, "[\"\\]", lastpos)
if not nextpos then
return unterminated (str, "string", pos)
end
if nextpos > lastpos then
n = n + 1
buffer[n] = strsub (str, lastpos, nextpos - 1)
end
if strsub (str, nextpos, nextpos) == "\"" then
lastpos = nextpos + 1
break
else
local escchar = strsub (str, nextpos + 1, nextpos + 1)
local value
if escchar == "u" then
value = tonumber (strsub (str, nextpos + 2, nextpos + 5), 16)
if value then
local value2
if 0xD800 <= value and value <= 0xDBff then
-- we have the high surrogate of UTF-16. Check if there is a
-- low surrogate escaped nearby to combine them.
if strsub (str, nextpos + 6, nextpos + 7) == "\\u" then
value2 = tonumber (strsub (str, nextpos + 8, nextpos + 11), 16)
if value2 and 0xDC00 <= value2 and value2 <= 0xDFFF then
value = (value - 0xD800) * 0x400 + (value2 - 0xDC00) + 0x10000
else
value2 = nil -- in case it was out of range for a low surrogate
end
end
end
value = value and unichar (value)
if value then
if value2 then
lastpos = nextpos + 12
else
lastpos = nextpos + 6
end
end
end
end
if not value then
value = escapechars[escchar] or escchar
lastpos = nextpos + 2
end
n = n + 1
buffer[n] = value
end
end
if n == 1 then
return buffer[1], lastpos
elseif n > 1 then
return concat (buffer), lastpos
else
return "", lastpos
end
end
local scanvalue -- forward declaration
local function scantable (what, closechar, str, startpos, nullval, objectmeta, arraymeta)
local len = strlen (str)
local tbl, n = {}, 0
local pos = startpos + 1
if what == 'object' then
setmetatable (tbl, objectmeta)
else
setmetatable (tbl, arraymeta)
end
while true do
pos = scanwhite (str, pos)
if not pos then return unterminated (str, what, startpos) end
local char = strsub (str, pos, pos)
if char == closechar then
return tbl, pos + 1
end
local val1, err
val1, pos, err = scanvalue (str, pos, nullval, objectmeta, arraymeta)
if err then return nil, pos, err end
pos = scanwhite (str, pos)
if not pos then return unterminated (str, what, startpos) end
char = strsub (str, pos, pos)
if char == ":" then
if val1 == nil then
return nil, pos, "cannot use nil as table index (at " .. loc (str, pos) .. ")"
end
pos = scanwhite (str, pos + 1)
if not pos then return unterminated (str, what, startpos) end
local val2
val2, pos, err = scanvalue (str, pos, nullval, objectmeta, arraymeta)
if err then return nil, pos, err end
tbl[val1] = val2
pos = scanwhite (str, pos)
if not pos then return unterminated (str, what, startpos) end
char = strsub (str, pos, pos)
else
n = n + 1
tbl[n] = val1
end
if char == "," then
pos = pos + 1
end
end
end
scanvalue = function (str, pos, nullval, objectmeta, arraymeta)
pos = pos or 1
pos = scanwhite (str, pos)
if not pos then
return nil, strlen (str) + 1, "no valid JSON value (reached the end)"
end
local char = strsub (str, pos, pos)
if char == "{" then
return scantable ('object', "}", str, pos, nullval, objectmeta, arraymeta)
elseif char == "[" then
return scantable ('array', "]", str, pos, nullval, objectmeta, arraymeta)
elseif char == "\"" then
return scanstring (str, pos)
else
local pstart, pend = strfind (str, "^%-?[%d%.]+[eE]?[%+%-]?%d*", pos)
if pstart then
local number = str2num (strsub (str, pstart, pend))
if number then
return number, pend + 1
end
end
pstart, pend = strfind (str, "^%a%w*", pos)
if pstart then
local name = strsub (str, pstart, pend)
if name == "true" then
return true, pend + 1
elseif name == "false" then
return false, pend + 1
elseif name == "null" then
return nullval, pend + 1
end
end
return nil, pos, "no valid JSON value at " .. loc (str, pos)
end
end
local function optionalmetatables(...)
if select("#", ...) > 0 then
return ...
else
return {__jsontype = 'object'}, {__jsontype = 'array'}
end
end
function json.decode (str, pos, nullval, ...)
local objectmeta, arraymeta = optionalmetatables(...)
return scanvalue (str, pos, nullval, objectmeta, arraymeta)
end
function json.use_lpeg ()
local g = require ("lpeg")
if g.version() == "0.11" then
error "due to a bug in LPeg 0.11, it cannot be used for JSON matching"
end
local pegmatch = g.match
local P, S, R = g.P, g.S, g.R
local function ErrorCall (str, pos, msg, state)
if not state.msg then
state.msg = msg .. " at " .. loc (str, pos)
state.pos = pos
end
return false
end
local function Err (msg)
return g.Cmt (g.Cc (msg) * g.Carg (2), ErrorCall)
end
local SingleLineComment = P"//" * (1 - S"\n\r")^0
local MultiLineComment = P"/*" * (1 - P"*/")^0 * P"*/"
local Space = (S" \n\r\t" + P"\239\187\191" + SingleLineComment + MultiLineComment)^0
local PlainChar = 1 - S"\"\\\n\r"
local EscapeSequence = (P"\\" * g.C (S"\"\\/bfnrt" + Err "unsupported escape sequence")) / escapechars
local HexDigit = R("09", "af", "AF")
local function UTF16Surrogate (match, pos, high, low)
high, low = tonumber (high, 16), tonumber (low, 16)
if 0xD800 <= high and high <= 0xDBff and 0xDC00 <= low and low <= 0xDFFF then
return true, unichar ((high - 0xD800) * 0x400 + (low - 0xDC00) + 0x10000)
else
return false
end
end
local function UTF16BMP (hex)
return unichar (tonumber (hex, 16))
end
local U16Sequence = (P"\\u" * g.C (HexDigit * HexDigit * HexDigit * HexDigit))
local UnicodeEscape = g.Cmt (U16Sequence * U16Sequence, UTF16Surrogate) + U16Sequence/UTF16BMP
local Char = UnicodeEscape + EscapeSequence + PlainChar
local String = P"\"" * g.Cs (Char ^ 0) * (P"\"" + Err "unterminated string")
local Integer = P"-"^(-1) * (P"0" + (R"19" * R"09"^0))
local Fractal = P"." * R"09"^0
local Exponent = (S"eE") * (S"+-")^(-1) * R"09"^1
local Number = (Integer * Fractal^(-1) * Exponent^(-1))/str2num
local Constant = P"true" * g.Cc (true) + P"false" * g.Cc (false) + P"null" * g.Carg (1)
local SimpleValue = Number + String + Constant
local ArrayContent, ObjectContent
-- The functions parsearray and parseobject parse only a single value/pair
-- at a time and store them directly to avoid hitting the LPeg limits.
local function parsearray (str, pos, nullval, state)
local obj, cont
local npos
local t, nt = {}, 0
repeat
obj, cont, npos = pegmatch (ArrayContent, str, pos, nullval, state)
if not npos then break end
pos = npos
nt = nt + 1
t[nt] = obj
until cont == 'last'
return pos, setmetatable (t, state.arraymeta)
end
local function parseobject (str, pos, nullval, state)
local obj, key, cont
local npos
local t = {}
repeat
key, obj, cont, npos = pegmatch (ObjectContent, str, pos, nullval, state)
if not npos then break end
pos = npos
t[key] = obj
until cont == 'last'
return pos, setmetatable (t, state.objectmeta)
end
local Array = P"[" * g.Cmt (g.Carg(1) * g.Carg(2), parsearray) * Space * (P"]" + Err "']' expected")
local Object = P"{" * g.Cmt (g.Carg(1) * g.Carg(2), parseobject) * Space * (P"}" + Err "'}' expected")
local Value = Space * (Array + Object + SimpleValue)
local ExpectedValue = Value + Space * Err "value expected"
ArrayContent = Value * Space * (P"," * g.Cc'cont' + g.Cc'last') * g.Cp()
local Pair = g.Cg (Space * String * Space * (P":" + Err "colon expected") * ExpectedValue)
ObjectContent = Pair * Space * (P"," * g.Cc'cont' + g.Cc'last') * g.Cp()
local DecodeValue = ExpectedValue * g.Cp ()
function json.decode (str, pos, nullval, ...)
local state = {}
state.objectmeta, state.arraymeta = optionalmetatables(...)
local obj, retpos = pegmatch (DecodeValue, str, pos, nullval, state)
if state.msg then
return nil, state.pos, state.msg
else
return obj, retpos
end
end
-- use this function only once:
json.use_lpeg = function () return json end
json.using_lpeg = true
return json -- so you can get the module using json = require "dkjson".use_lpeg()
end
if always_try_using_lpeg then
pcall (json.use_lpeg)
end
return json

3882
lib/fennel.lua Normal file

File diff suppressed because it is too large Load diff

780
lib/lume.lua Normal file
View file

@ -0,0 +1,780 @@
--
-- lume
--
-- Copyright (c) 2020 rxi
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy of
-- this software and associated documentation files (the "Software"), to deal in
-- the Software without restriction, including without limitation the rights to
-- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-- of the Software, and to permit persons to whom the Software is furnished to do
-- so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in all
-- copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-- SOFTWARE.
--
local lume = { _version = "2.3.0" }
local pairs, ipairs = pairs, ipairs
local type, assert, unpack = type, assert, unpack or table.unpack
local tostring, tonumber = tostring, tonumber
local math_floor = math.floor
local math_ceil = math.ceil
local math_atan2 = math.atan2 or math.atan
local math_sqrt = math.sqrt
local math_abs = math.abs
local noop = function()
end
local identity = function(x)
return x
end
local patternescape = function(str)
return str:gsub("[%(%)%.%%%+%-%*%?%[%]%^%$]", "%%%1")
end
local absindex = function(len, i)
return i < 0 and (len + i + 1) or i
end
local iscallable = function(x)
if type(x) == "function" then return true end
local mt = getmetatable(x)
return mt and mt.__call ~= nil
end
local getiter = function(x)
if lume.isarray(x) then
return ipairs
elseif type(x) == "table" then
return pairs
end
error("expected table", 3)
end
local iteratee = function(x)
if x == nil then return identity end
if iscallable(x) then return x end
if type(x) == "table" then
return function(z)
for k, v in pairs(x) do
if z[k] ~= v then return false end
end
return true
end
end
return function(z) return z[x] end
end
function lume.clamp(x, min, max)
return x < min and min or (x > max and max or x)
end
function lume.round(x, increment)
if increment then return lume.round(x / increment) * increment end
return x >= 0 and math_floor(x + .5) or math_ceil(x - .5)
end
function lume.sign(x)
return x < 0 and -1 or 1
end
function lume.lerp(a, b, amount)
return a + (b - a) * lume.clamp(amount, 0, 1)
end
function lume.smooth(a, b, amount)
local t = lume.clamp(amount, 0, 1)
local m = t * t * (3 - 2 * t)
return a + (b - a) * m
end
function lume.pingpong(x)
return 1 - math_abs(1 - x % 2)
end
function lume.distance(x1, y1, x2, y2, squared)
local dx = x1 - x2
local dy = y1 - y2
local s = dx * dx + dy * dy
return squared and s or math_sqrt(s)
end
function lume.angle(x1, y1, x2, y2)
return math_atan2(y2 - y1, x2 - x1)
end
function lume.vector(angle, magnitude)
return math.cos(angle) * magnitude, math.sin(angle) * magnitude
end
function lume.random(a, b)
if not a then a, b = 0, 1 end
if not b then b = 0 end
return a + math.random() * (b - a)
end
function lume.randomchoice(t)
return t[math.random(#t)]
end
function lume.weightedchoice(t)
local sum = 0
for _, v in pairs(t) do
assert(v >= 0, "weight value less than zero")
sum = sum + v
end
assert(sum ~= 0, "all weights are zero")
local rnd = lume.random(sum)
for k, v in pairs(t) do
if rnd < v then return k end
rnd = rnd - v
end
end
function lume.isarray(x)
return type(x) == "table" and x[1] ~= nil
end
function lume.push(t, ...)
local n = select("#", ...)
for i = 1, n do
t[#t + 1] = select(i, ...)
end
return ...
end
function lume.remove(t, x)
local iter = getiter(t)
for i, v in iter(t) do
if v == x then
if lume.isarray(t) then
table.remove(t, i)
break
else
t[i] = nil
break
end
end
end
return x
end
function lume.clear(t)
local iter = getiter(t)
for k in iter(t) do
t[k] = nil
end
return t
end
function lume.extend(t, ...)
for i = 1, select("#", ...) do
local x = select(i, ...)
if x then
for k, v in pairs(x) do
t[k] = v
end
end
end
return t
end
function lume.shuffle(t)
local rtn = {}
for i = 1, #t do
local r = math.random(i)
if r ~= i then
rtn[i] = rtn[r]
end
rtn[r] = t[i]
end
return rtn
end
function lume.sort(t, comp)
local rtn = lume.clone(t)
if comp then
if type(comp) == "string" then
table.sort(rtn, function(a, b) return a[comp] < b[comp] end)
else
table.sort(rtn, comp)
end
else
table.sort(rtn)
end
return rtn
end
function lume.array(...)
local t = {}
for x in ... do t[#t + 1] = x end
return t
end
function lume.each(t, fn, ...)
local iter = getiter(t)
if type(fn) == "string" then
for _, v in iter(t) do v[fn](v, ...) end
else
for _, v in iter(t) do fn(v, ...) end
end
return t
end
function lume.map(t, fn)
fn = iteratee(fn)
local iter = getiter(t)
local rtn = {}
for k, v in iter(t) do rtn[k] = fn(v) end
return rtn
end
function lume.all(t, fn)
fn = iteratee(fn)
local iter = getiter(t)
for _, v in iter(t) do
if not fn(v) then return false end
end
return true
end
function lume.any(t, fn)
fn = iteratee(fn)
local iter = getiter(t)
for _, v in iter(t) do
if fn(v) then return true end
end
return false
end
function lume.reduce(t, fn, first)
local started = first ~= nil
local acc = first
local iter = getiter(t)
for _, v in iter(t) do
if started then
acc = fn(acc, v)
else
acc = v
started = true
end
end
assert(started, "reduce of an empty table with no first value")
return acc
end
function lume.unique(t)
local rtn = {}
for k in pairs(lume.invert(t)) do
rtn[#rtn + 1] = k
end
return rtn
end
function lume.filter(t, fn, retainkeys)
fn = iteratee(fn)
local iter = getiter(t)
local rtn = {}
if retainkeys then
for k, v in iter(t) do
if fn(v) then rtn[k] = v end
end
else
for _, v in iter(t) do
if fn(v) then rtn[#rtn + 1] = v end
end
end
return rtn
end
function lume.reject(t, fn, retainkeys)
fn = iteratee(fn)
local iter = getiter(t)
local rtn = {}
if retainkeys then
for k, v in iter(t) do
if not fn(v) then rtn[k] = v end
end
else
for _, v in iter(t) do
if not fn(v) then rtn[#rtn + 1] = v end
end
end
return rtn
end
function lume.merge(...)
local rtn = {}
for i = 1, select("#", ...) do
local t = select(i, ...)
local iter = getiter(t)
for k, v in iter(t) do
rtn[k] = v
end
end
return rtn
end
function lume.concat(...)
local rtn = {}
for i = 1, select("#", ...) do
local t = select(i, ...)
if t ~= nil then
local iter = getiter(t)
for _, v in iter(t) do
rtn[#rtn + 1] = v
end
end
end
return rtn
end
function lume.find(t, value)
local iter = getiter(t)
for k, v in iter(t) do
if v == value then return k end
end
return nil
end
function lume.match(t, fn)
fn = iteratee(fn)
local iter = getiter(t)
for k, v in iter(t) do
if fn(v) then return v, k end
end
return nil
end
function lume.count(t, fn)
local count = 0
local iter = getiter(t)
if fn then
fn = iteratee(fn)
for _, v in iter(t) do
if fn(v) then count = count + 1 end
end
else
if lume.isarray(t) then
return #t
end
for _ in iter(t) do count = count + 1 end
end
return count
end
function lume.slice(t, i, j)
i = i and absindex(#t, i) or 1
j = j and absindex(#t, j) or #t
local rtn = {}
for x = i < 1 and 1 or i, j > #t and #t or j do
rtn[#rtn + 1] = t[x]
end
return rtn
end
function lume.first(t, n)
if not n then return t[1] end
return lume.slice(t, 1, n)
end
function lume.last(t, n)
if not n then return t[#t] end
return lume.slice(t, -n, -1)
end
function lume.invert(t)
local rtn = {}
for k, v in pairs(t) do rtn[v] = k end
return rtn
end
function lume.pick(t, ...)
local rtn = {}
for i = 1, select("#", ...) do
local k = select(i, ...)
rtn[k] = t[k]
end
return rtn
end
function lume.keys(t)
local rtn = {}
local iter = getiter(t)
for k in iter(t) do rtn[#rtn + 1] = k end
return rtn
end
function lume.clone(t)
local rtn = {}
for k, v in pairs(t) do rtn[k] = v end
return rtn
end
function lume.fn(fn, ...)
assert(iscallable(fn), "expected a function as the first argument")
local args = { ... }
return function(...)
local a = lume.concat(args, { ... })
return fn(unpack(a))
end
end
function lume.once(fn, ...)
local f = lume.fn(fn, ...)
local done = false
return function(...)
if done then return end
done = true
return f(...)
end
end
local memoize_fnkey = {}
local memoize_nil = {}
function lume.memoize(fn)
local cache = {}
return function(...)
local c = cache
for i = 1, select("#", ...) do
local a = select(i, ...) or memoize_nil
c[a] = c[a] or {}
c = c[a]
end
c[memoize_fnkey] = c[memoize_fnkey] or {fn(...)}
return unpack(c[memoize_fnkey])
end
end
function lume.combine(...)
local n = select('#', ...)
if n == 0 then return noop end
if n == 1 then
local fn = select(1, ...)
if not fn then return noop end
assert(iscallable(fn), "expected a function or nil")
return fn
end
local funcs = {}
for i = 1, n do
local fn = select(i, ...)
if fn ~= nil then
assert(iscallable(fn), "expected a function or nil")
funcs[#funcs + 1] = fn
end
end
return function(...)
for _, f in ipairs(funcs) do f(...) end
end
end
function lume.call(fn, ...)
if fn then
return fn(...)
end
end
function lume.time(fn, ...)
local start = os.clock()
local rtn = {fn(...)}
return (os.clock() - start), unpack(rtn)
end
local lambda_cache = {}
function lume.lambda(str)
if not lambda_cache[str] then
local args, body = str:match([[^([%w,_ ]-)%->(.-)$]])
assert(args and body, "bad string lambda")
local s = "return function(" .. args .. ")\nreturn " .. body .. "\nend"
lambda_cache[str] = lume.dostring(s)
end
return lambda_cache[str]
end
local serialize
local serialize_map = {
[ "boolean" ] = tostring,
[ "nil" ] = tostring,
[ "string" ] = function(v) return string.format("%q", v) end,
[ "number" ] = function(v)
if v ~= v then return "0/0" -- nan
elseif v == 1 / 0 then return "1/0" -- inf
elseif v == -1 / 0 then return "-1/0" end -- -inf
return tostring(v)
end,
[ "table" ] = function(t, stk)
stk = stk or {}
if stk[t] then error("circular reference") end
local rtn = {}
stk[t] = true
for k, v in pairs(t) do
rtn[#rtn + 1] = "[" .. serialize(k, stk) .. "]=" .. serialize(v, stk)
end
stk[t] = nil
return "{" .. table.concat(rtn, ",") .. "}"
end
}
setmetatable(serialize_map, {
__index = function(_, k) error("unsupported serialize type: " .. k) end
})
serialize = function(x, stk)
return serialize_map[type(x)](x, stk)
end
function lume.serialize(x)
return serialize(x)
end
function lume.deserialize(str)
return lume.dostring("return " .. str)
end
function lume.split(str, sep)
if not sep then
return lume.array(str:gmatch("([%S]+)"))
else
assert(sep ~= "", "empty separator")
local psep = patternescape(sep)
return lume.array((str..sep):gmatch("(.-)("..psep..")"))
end
end
function lume.trim(str, chars)
if not chars then return str:match("^[%s]*(.-)[%s]*$") end
chars = patternescape(chars)
return str:match("^[" .. chars .. "]*(.-)[" .. chars .. "]*$")
end
function lume.wordwrap(str, limit)
limit = limit or 72
local check
if type(limit) == "number" then
check = function(s) return #s >= limit end
else
check = limit
end
local rtn = {}
local line = ""
for word, spaces in str:gmatch("(%S+)(%s*)") do
local s = line .. word
if check(s) then
table.insert(rtn, line .. "\n")
line = word
else
line = s
end
for c in spaces:gmatch(".") do
if c == "\n" then
table.insert(rtn, line .. "\n")
line = ""
else
line = line .. c
end
end
end
table.insert(rtn, line)
return table.concat(rtn)
end
function lume.format(str, vars)
if not vars then return str end
local f = function(x)
return tostring(vars[x] or vars[tonumber(x)] or "{" .. x .. "}")
end
return (str:gsub("{(.-)}", f))
end
function lume.trace(...)
local info = debug.getinfo(2, "Sl")
local t = { info.short_src .. ":" .. info.currentline .. ":" }
for i = 1, select("#", ...) do
local x = select(i, ...)
if type(x) == "number" then
x = string.format("%g", lume.round(x, .01))
end
t[#t + 1] = tostring(x)
end
print(table.concat(t, " "))
end
function lume.dostring(str)
return assert((loadstring or load)(str))()
end
function lume.uuid()
local fn = function(x)
local r = math.random(16) - 1
r = (x == "x") and (r + 1) or (r % 4) + 9
return ("0123456789abcdef"):sub(r, r)
end
return (("xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"):gsub("[xy]", fn))
end
function lume.hotswap(modname)
local oldglobal = lume.clone(_G)
local updated = {}
local function update(old, new)
if updated[old] then return end
updated[old] = true
local oldmt, newmt = getmetatable(old), getmetatable(new)
if oldmt and newmt then update(oldmt, newmt) end
for k, v in pairs(new) do
if type(v) == "table" then update(old[k], v) else old[k] = v end
end
end
local err = nil
local function onerror(e)
for k in pairs(_G) do _G[k] = oldglobal[k] end
err = lume.trim(e)
end
local ok, oldmod = pcall(require, modname)
oldmod = ok and oldmod or nil
xpcall(function()
package.loaded[modname] = nil
local newmod = require(modname)
if type(oldmod) == "table" then update(oldmod, newmod) end
for k, v in pairs(oldglobal) do
if v ~= _G[k] and type(v) == "table" then
update(v, _G[k])
_G[k] = v
end
end
end, onerror)
package.loaded[modname] = oldmod
if err then return nil, err end
return oldmod
end
local ripairs_iter = function(t, i)
i = i - 1
local v = t[i]
if v ~= nil then
return i, v
end
end
function lume.ripairs(t)
return ripairs_iter, t, (#t + 1)
end
function lume.color(str, mul)
mul = mul or 1
local r, g, b, a
r, g, b = str:match("#(%x%x)(%x%x)(%x%x)")
if r then
r = tonumber(r, 16) / 0xff
g = tonumber(g, 16) / 0xff
b = tonumber(b, 16) / 0xff
a = 1
elseif str:match("rgba?%s*%([%d%s%.,]+%)") then
local f = str:gmatch("[%d.]+")
r = (f() or 0) / 0xff
g = (f() or 0) / 0xff
b = (f() or 0) / 0xff
a = f() or 1
else
error(("bad color string '%s'"):format(str))
end
return r * mul, g * mul, b * mul, a * mul
end
local chain_mt = {}
chain_mt.__index = lume.map(lume.filter(lume, iscallable, true),
function(fn)
return function(self, ...)
self._value = fn(self._value, ...)
return self
end
end)
chain_mt.__index.result = function(x) return x._value end
function lume.chain(value)
return setmetatable({ _value = value }, chain_mt)
end
setmetatable(lume, {
__call = function(_, ...)
return lume.chain(...)
end
})
return lume

44
lib/spawn.lua Normal file
View file

@ -0,0 +1,44 @@
-- adapted from https://gist.github.com/iMega/f47f5a2ae1f02d7d5769a008538fd925
local ffi = require 'ffi'
local C = ffi.C
ffi.cdef([[
typedef int32_t pid_t;
pid_t fork(void);
int open(const char *pathname, int flags, int mode);
int close(int fd);
int dup2(int oldfd, int newfd);
int execvp(const char *file, char *const argv[]);
int kill(pid_t pid, int sig);
pid_t setsid(void);
]])
local bor = bit.bor
local ffi_cast = ffi.cast
local k_char_p_arr_t = ffi.typeof('const char * [?]')
local char_p_k_p_t = ffi.typeof('char * const *')
local function spawn(args)
if not args or #args == 0 then error("couldn't tokenize cmd_line") end
local pid = C.fork()
if pid < 0 then
error("fork failed " .. ffi.errno())
elseif pid == 0 then -- child process
C.setsid()
local argv = k_char_p_arr_t(#args + 1) -- automatically NULL terminated
for i = 1, #args do
argv[i-1] = args[i] -- args is 1-based Lua table, argv is 0-based C array
end
local res = C.execvp(args[1], ffi_cast(char_p_k_p_t, argv))
if res == -1 then error("execvp failed with " .. ffi.errno()) end
-- HERE SHOULD BE UNREACHABLE!!
else
return pid
end
end
return {spawn=spawn, kill=C.kill}

46
lib/stdio.fnl Normal file
View file

@ -0,0 +1,46 @@
(require "love.event")
(local view (require "lib.fennelview"))
;; This module exists in order to expose stdio over a channel so that it
;; can be used in a non-blocking way from another thread.
(local (event channel) ...)
(when channel
(let [prompt (fn [] (io.write "> ") (io.flush) (io.read "*l"))]
((fn looper [input]
(when input
;; This is consumed by love.handlers[event]
(love.event.push event input)
(let [output (: channel :demand)]
;; There is probably a more efficient way of determining an error
(if (and (. output 2) (= "Error:" (. output 2)))
(print (view output))
(each [_ ret (ipairs output)]
(print ret))))
(io.flush)
(looper (prompt)))) (prompt))))
{:start (fn start-repl []
(let [code (love.filesystem.read "lib/stdio.fnl")
luac (if code
(love.filesystem.newFileData
(fennel.compileString code) "io")
(love.filesystem.read "lib/stdio.lua"))
thread (love.thread.newThread luac)
io-channel (love.thread.newChannel)
coro (coroutine.create fennel.repl)
out (fn [val]
(: io-channel :push val))
options {:readChunk coroutine.yield
:onValues out
:onError (fn [kind ...] (out [kind "Error:" ...]))
:pp view
:moduleName "lib.fennel"}]
;; this thread will send "eval" events for us to consume:
(coroutine.resume coro options)
(: thread :start "eval" io-channel)
(set love.handlers.eval
(fn [input]
(coroutine.resume coro (.. input "\n"))))))}

83
lib/util.fnl Normal file
View file

@ -0,0 +1,83 @@
(local lume (require :lib.lume))
(local json (require :lib.dkjson))
(local core (require :core))
(fn string.fromhex [str]
(str:gsub ".." (fn [cc] (string.char (tonumber cc 16)))))
(fn string.tohex [str]
(str:gsub "." (fn [c] (string.format "%02X" (string.byte c)))))
(fn lo [v] (bit.band v 0xff))
(fn hi [v] (bit.band (bit.rshift v 8) 0xff))
(fn int8-to-bytes [i]
(string.char (lo i)))
(fn int16-to-bytes [i]
(string.char (lo i) (hi i)))
(fn int24-to-bytes [i]
(string.char (lo i) (hi i) (bit.band (bit.rshift i 16) 0xff)))
(fn bytes-to-uint8 [b ?offset]
(string.byte b (+ 1 (or ?offset 0)) (+ 1 (or ?offset 0))))
(fn bytes-to-uint16 [b ?offset]
(local (lo hi) (string.byte b (+ 1 (or ?offset 0)) (+ 2 (or ?offset 0))))
(bit.bor lo (bit.lshift hi 8)))
(fn bytes-to-uint24 [b ?offset]
(local (lo mid hi) (string.byte b (+ 1 (or ?offset 0)) (+ 3 (or ?offset 0))))
(bit.bor lo (bit.lshift mid 8) (bit.lshift hi 16)))
(fn splice [bytes offset str]
(.. (bytes:sub 1 offset)
str
(bytes:sub (+ (length str) offset 1))))
(fn reload [modname]
(tset package.loaded modname nil)
(require modname))
; lume.hotswap really assumes your module is a table
(fn hotswap [modname]
(if (= (type (. package.loaded modname)) :table)
(lume.hotswap modname)
(reload modname)))
(fn mk-swappable-fn [table k]
(fn [...] ((. table k) ...)))
(fn swappable [table]
(local s {})
(each [k v (pairs table)]
(if (= (type v) :function)
(tset s k (mk-swappable-fn table k))
(tset s k v)))
s)
(fn swappable-require [modname]
(swappable (require modname)))
(fn readjson [filename]
(local f (io.open filename :r))
(local text (f:read "*a"))
(f:close)
(json.decode text))
(fn writejson [filename value]
(local f (io.open filename :w))
(f:write (json.encode value))
(f:close))
(fn waitfor [pred]
(local coro (coroutine.running))
(core.add_thread
(fn []
(while (not (pred))
(coroutine.yield))
(coroutine.resume coro))
coro)
(coroutine.yield))
(fn in-coro [f ...] (-> (coroutine.create f) (coroutine.resume ...)))
{: int8-to-bytes : int16-to-bytes : int24-to-bytes : bytes-to-uint8 : bytes-to-uint16 : bytes-to-uint24
: splice : lo : hi
: reload : hotswap : swappable :require swappable-require
: readjson : writejson : waitfor : in-coro}

19
main.lua Normal file
View file

@ -0,0 +1,19 @@
-- bootstrap the compiler
fennel = require("lib.fennel")
debug.traceback = fennel.traceback
table.insert(package.loaders, fennel.make_searcher({correlate=true}))
fv = fennel.view
pp = function(x) print(fv(x)) end
lume = require("lib.lume")
_coroutine_resume = coroutine.resume
function coroutine.resume(...)
local state,result = _coroutine_resume(...)
if not state then
error( tostring(result), 2 ) -- Output error message
end
return state,result
end
require("vendor.lite.main")
require("wrap")

View file

@ -0,0 +1,25 @@
local core = require "core"
local command = require "core.command"
local keymap = require "core.keymap"
local CommandView = require "core.commandview"
local function is_finding()
return core.active_view:is(CommandView) and core.active_view.label == "Find Text: "
end
command.add(is_finding, {
["better-find:done"] = function() core.active_view:submit() end,
["better-find:next"] = function()
local commandview = core.active_view
commandview.state.submit(commandview:get_text())
core.set_active_view(core.last_active_view)
command.perform("find-replace:repeat-find")
core.set_active_view(commandview)
end
})
keymap.add {
["escape"] = "better-find:done",
["return"] = "better-find:next"
}

View file

@ -0,0 +1,58 @@
local tokenizer = require "core.tokenizer"
local style = require "core.style"
local common = require "core.common"
local tokenize = tokenizer.tokenize
local closers = {
["("] = ")",
["["] = "]",
["{"] = "}"
}
local function parenstyle(parenstack)
return "paren" .. ((#parenstack % 5) + 1)
end
function tokenizer.tokenize(syntax, text, state)
state = state or {}
local res, istate = tokenize(syntax, text, state.istate)
local parenstack = state.parenstack or ""
local newres = {}
-- split parens out
-- the stock tokenizer can't do this because it merges identical adjacent tokens
for i, type, text in tokenizer.each_token(res) do
if type == "normal" or type == "symbol" then
for normtext1, paren, normtext2 in text:gmatch("([^%(%[{}%]%)]*)([%(%[{}%]%)]?)([^%(%[{}%]%)]*)") do
if #normtext1 > 0 then
table.insert(newres, type)
table.insert(newres, normtext1)
end
if #paren > 0 then
if paren == parenstack:sub(-1) then -- expected closer
parenstack = parenstack:sub(1, -2)
table.insert(newres, parenstyle(parenstack))
elseif closers[paren] then -- opener
table.insert(newres, parenstyle(parenstack))
parenstack = parenstack .. closers[paren]
else -- unexpected closer
table.insert(newres, "paren_unbalanced")
end
table.insert(newres, paren)
end
if #normtext2 > 0 then
table.insert(newres, type)
table.insert(newres, normtext2)
end
end
else
table.insert(newres, type)
table.insert(newres, text)
end
end
return newres, { parenstack = parenstack, istate = istate }
end
style.syntax.paren_unbalanced = style.syntax.paren_unbalanced or { common.color "#DC0408" }
style.syntax.paren1 = style.syntax.paren1 or { common.color "#FC6F71"}
style.syntax.paren2 = style.syntax.paren2 or { common.color "#fcb053"}
style.syntax.paren3 = style.syntax.paren3 or { common.color "#fcd476"}
style.syntax.paren4 = style.syntax.paren4 or { common.color "#52dab2"}
style.syntax.paren5 = style.syntax.paren5 or { common.color "#5a98cf"}

3
todo.txt Normal file
View file

@ -0,0 +1,3 @@
TODO:
* tile editor (geometric shapes for now?)

12
vendor/jeejah/.gitrepo vendored Normal file
View file

@ -0,0 +1,12 @@
; DO NOT EDIT (unless you know what you are doing)
;
; This subdirectory is a git "subrepo", and this file is maintained by the
; git-subrepo command. See https://github.com/git-commands/git-subrepo#readme
;
[subrepo]
remote = https://gitlab.com/technomancy/jeejah.git
branch = master
commit = 3ed9eb1f368c825e33e73dec0bcc9c553c33cf82
parent = 3d52b70bbcc475d8ef69accd990c367f1a72bbba
method = merge
cmdver = 0.4.2

31
vendor/jeejah/Changelog.md vendored Normal file
View file

@ -0,0 +1,31 @@
# Jeejah changelog: history of user-visible changes
## 0.3.1 / 2020-04-24
* Fix compatibility for Lua 5.1 and 5.2.
* Improve error reporting.
* Move Fennel support to special handler instead of middleware.
## 0.3.0 / 2019-08-01
* Fix a bug with socket timeout.
* Add foreground mode.
* Avoid burning CPU when there's nothing to do.
## 0.2.1 / 2019-05-21
* Add support for launching a Fennel server using middleware.
* Add support for middleware.
* Support Luas newer than 5.1.
## 0.2.0 / 2016-06-20
* Support requesting a read from stdin.
* Support stopping the server.
* Change module API to return a table, not a function.
* Support multiple sessions.
## 0.1.0 / 2016-06-09
* Initial release!

19
vendor/jeejah/LICENSE vendored Normal file
View file

@ -0,0 +1,19 @@
Copyright © 2016-2019 Phil Hagelberg and contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

1
vendor/jeejah/Makefile vendored Normal file
View file

@ -0,0 +1 @@
check: ; luacheck --std max jeejah.lua bencode.lua

94
vendor/jeejah/Readme.md vendored Normal file
View file

@ -0,0 +1,94 @@
# JeeJah
An nREPL server for [Fennel](https://fennel-lang.org) and [Lua](https://lua.org).
## A what now?
The [nREPL protocol](https://nrepl.org/nrepl/index.html#_why_nrepl)
allows developers to embed a server in their programs to which
external programs can connect for development, debugging, etc.
The original implementation of the protocol was written in Clojure,
and many clients assume they will connect to a Clojure server; however
the protocol is quite agnostic about what language is being
evaluated. It supports evaluating snippets of code or whole files with
`print` and `io.write` redirected back to the connected client.
This library was originally written to add Emacs support to
[Bussard](https://gitlab.com/technomancy/bussard), a spaceflight
programming game.
Currently mainly tested with
[monroe](https://github.com/sanel/monroe/) and
[shevek](https://git.sr.ht/~technomancy/shevek/) as
clients. [grenchman](https://leiningen.org/grench.html) version 0.3.0+
works. Other clients exist for Vim, Eclipse, and Atom, as well as
several independent command-line clients; however these may require
some adaptation to work with Jeejah. If you try your favorite client
and find that it makes Clojure-specific assumptions, please report a
bug with it so that it can gracefully degrade when those assumptions
don't hold.
## Installation
The pure-Lua dependencies are included (`bencode`, `serpent`, and
`fennel`) but you will need to install `luasocket` yourself. If your
operating system does not provide it, you can install it using LuaRocks:
$ luarocks install --local luasocket
Note that [LÖVE](https://love2d.org) ships with its own copy of
luasocket, so there is no need to install it there.
You can symlink `bin/jeejah` to your `$PATH` or something.
## Usage
You can launch a standalone nREPL server:
$ bin/jeejah
Pass in a `--fennel` flag to start a server for evaluating Fennel code
instead of Lua. Accepts a `--port` argument and a `--debug` flag.
You can use it as a library too, of course:
```lua
local jeejah = require("jeejah")
local coro = jeejah.start(port, {debug=true, sandbox={x=12}})
```
The function returns a coroutine which you'll need to repeatedly
resume in order to handle requests. Each accepted connection is stored
in a coroutine internal to that function; these are each repeatedly
resumed by the main coroutine. If all you're doing is starting an
nrepl server, you can pass `foreground=true` in the options table to
leave the server running in the foreground and skip the step of
resuming the coroutine.
Note that the sandbox feature is not well-tested or audited and should
not be trusted to provide robust security. It currently only works
with Lua 5.1 and LuaJIT.
You can also pass in a `handlers` table where the keys are custom
[nREPL ops](https://nrepl.org/nrepl/ops.html)
you want to handle yourself.
## Completion
The included `monroe-lua-complete.el` file adds support for completion
to the Monroe client by querying the connected nREPL server for
possibilities. Simply invoke `completion-at-point` (bound to `C-M-i`
by default) when connected.
## Caveats
PUC Lua 5.1 does not allow yielding coroutines from inside protected
calls, which means you cannot use `io.read`, though LuaJIT and
Lua 5.2+ allow it.
## License
Copyright © 2016-2020 Phil Hagelberg and contributors
Distributed under the MIT license; see file LICENSE

78
vendor/jeejah/bencode.lua vendored Normal file
View file

@ -0,0 +1,78 @@
local encode, decode
local function decode_list(str, t, total_len)
-- print("list", str, lume.serialize(t))
if(str:sub(1,1) == "e") then return t, total_len + 1 end
local value, v_len = decode(str)
table.insert(t, value)
total_len = total_len + v_len
return decode_list(str:sub(v_len + 1), t, total_len)
end
local function decode_table(str, t, total_len)
-- print("table", str, lume.serialize(t))
if(str:sub(1,1) == "e") then return t, total_len + 1 end
local key, k_len = decode(str)
local value, v_len = decode(str:sub(k_len+1))
local end_pos = 1 + k_len + v_len
t[key] = value
total_len = total_len + k_len + v_len
return decode_table(str:sub(end_pos), t, total_len)
end
function decode(str)
-- print("decoding", str)
if(str:sub(1,1) == "l") then
return decode_list(str:sub(2), {}, 1)
elseif(str:sub(1,1) == "d") then
return decode_table(str:sub(2), {}, 1)
elseif(str:sub(1,1) == "i") then
return(tonumber(str:sub(2, str:find("e") - 1))), str:find("e")
elseif(str:match("[0-9]+")) then
local num_str = str:match("[0-9]+")
local beginning_of_string = #num_str + 2
local str_len = tonumber(num_str)
local total_len = beginning_of_string + str_len - 1
return str:sub(beginning_of_string, total_len), total_len
else
error("Could not parse "..str)
end
end
local function encode_str(s) return #s .. ":" .. s end
local function encode_int(n) return "i" .. tostring(n) .. "e" end
local function encode_table(t)
local s = "d"
for k,v in pairs(t) do s = s .. encode(k) .. encode(v) end
return s .. "e"
end
local function encode_list(l)
local s = "l"
for _,x in ipairs(l) do s = s .. encode(x) end
return s .. "e"
end
local function count(tbl)
local i = 0
for _ in pairs(tbl) do i = i + 1 end
return i
end
function encode(x)
local unpack = unpack or table.unpack
if(type(x) == "table" and select("#", unpack(x)) == count(x)) then
return encode_list(x)
elseif(type(x) == "table") then
return encode_table(x)
elseif(type(x) == "number" and math.floor(x) == x) then
return encode_int(x)
elseif(type(x) == "string") then
return encode_str(x)
else
error("Could not encode " .. type(x) .. ": " .. tostring(x))
end
end
return {decode=decode, encode=encode}

35
vendor/jeejah/bin/jeejah vendored Executable file
View file

@ -0,0 +1,35 @@
#!/usr/bin/env lua
require "luarocks.loader"
local opts, port = {foreground = true}
for n,v in ipairs(arg) do
if(v == "--port") then
port = arg[n+1]
elseif(v == "--fennel") then
opts.fennel = true
elseif(v == "--debug") then
opts.debug = true
elseif(v == "--empty-sandbox") then
opts.sandbox = {}
elseif(v == "--version" or v == "--help") then
print("jeejah 0.2.0\n")
print("Options:")
print(" --fennel Start a Fennel server instead of Lua")
print(" --port Port on which to listen")
print(" --debug Print verbose debugging information")
os.exit(0)
end
end
local root_dir = debug.getinfo(1).source:sub(2, -(1+#"bin/jeejah"))
local search_parent = string.format("%s?.lua;%s", root_dir, package.path)
if(package.searchpath) then
local jeejah = dofile(package.searchpath("jeejah", search_parent))
jeejah.start(port, opts)
else -- 5.1
if root_dir == "" then root_dir = "." end
local jeejah = dofile(root_dir .. "/jeejah.lua")
jeejah.start(port, opts)
end

3319
vendor/jeejah/fennel.lua vendored Normal file

File diff suppressed because it is too large Load diff

202
vendor/jeejah/fennelview.fnl vendored Normal file
View file

@ -0,0 +1,202 @@
;; A pretty-printer that outputs tables in Fennel syntax.
;; Loosely based on inspect.lua: http://github.com/kikito/inspect.lua
(fn view-quote [str] (.. "\"" (: str :gsub "\"" "\\\"") "\""))
(local short-control-char-escapes
{"\a" "\\a" "\b" "\\b" "\f" "\\f" "\n" "\\n"
"\r" "\\r" "\t" "\\t" "\v" "\\v"})
(local long-control-char-escapes
(let [long {}]
(for [i 0 31]
(let [ch (string.char i)]
(when (not (. short-control-char-escapes ch))
(tset short-control-char-escapes ch (.. "\\" i))
(tset long ch (: "\\%03d" :format i)))))
long))
(fn escape [str]
(-> str
(: :gsub "\\" "\\\\")
(: :gsub "(%c)%f[0-9]" long-control-char-escapes)
(: :gsub "%c" short-control-char-escapes)))
(fn sequence-key? [k len]
(and (= (type k) "number")
(<= 1 k)
(<= k len)
(= (math.floor k) k)))
(local type-order {:number 1 :boolean 2 :string 3 :table 4
:function 5 :userdata 6 :thread 7})
(fn sort-keys [a b]
(let [ta (type a) tb (type b)]
(if (and (= ta tb)
(or (= ta "string") (= ta "number")))
(< a b)
(let [dta (. type-order a)
dtb (. type-order b)]
(if (and dta dtb)
(< dta dtb)
dta true
dtb false
:else (< ta tb))))))
(fn get-sequence-length [t]
(var len 1)
(each [i (ipairs t)] (set len i))
len)
(fn get-nonsequential-keys [t]
(let [keys {}
sequence-length (get-sequence-length t)]
(each [k (pairs t)]
(when (not (sequence-key? k sequence-length))
(table.insert keys k)))
(table.sort keys sort-keys)
(values keys sequence-length)))
(fn count-table-appearances [t appearances]
(when (= (type t) "table")
(if (not (. appearances t))
(do (tset appearances t 1)
(each [k v (pairs t)]
(count-table-appearances k appearances)
(count-table-appearances v appearances)))
(tset appearances t (+ (or (. appearances t) 0) 1))))
appearances)
(var put-value nil) ; mutual recursion going on; defined below
(fn puts [self ...]
(each [_ v (ipairs [...])]
(table.insert self.buffer v)))
(fn tabify [self] (puts self "\n" (: self.indent :rep self.level)))
(fn already-visited? [self v] (not= (. self.ids v) nil))
(fn get-id [self v]
(var id (. self.ids v))
(when (not id)
(let [tv (type v)]
(set id (+ (or (. self.max-ids tv) 0) 1))
(tset self.max-ids tv id)
(tset self.ids v id)))
(tostring id))
(fn put-sequential-table [self t len]
(puts self "[")
(set self.level (+ self.level 1))
(for [i 1 len]
(when (< 1 i (+ 1 len))
(puts self " "))
(put-value self (. t i)))
(set self.level (- self.level 1))
(puts self "]"))
(fn put-key [self k]
(if (and (= (type k) "string")
(: k :find "^[-%w?\\^_!$%&*+./@:|<=>]+$"))
(puts self ":" k)
(put-value self k)))
(fn put-kv-table [self t ordered-keys]
(puts self "{")
(set self.level (+ self.level 1))
;; first, output sorted nonsequential keys
(each [i k (ipairs ordered-keys)]
(when (or self.table-edges (not= i 1))
(tabify self))
(put-key self k)
(puts self " ")
(put-value self (. t k)))
;; next, output any sequential keys
(each [i v (ipairs t)]
(tabify self)
(put-key self i)
(puts self " ")
(put-value self v))
(set self.level (- self.level 1))
(when self.table-edges
(tabify self))
(puts self "}"))
(fn put-table [self t]
(let [metamethod (and self.metamethod? (-?> t getmetatable (. :__fennelview)))]
(if (and (already-visited? self t) self.detect-cycles?)
(puts self "#<table @" (get-id self t) ">")
(>= self.level self.depth)
(puts self "{...}")
metamethod
(puts self (metamethod t self.fennelview))
:else
(let [(non-seq-keys len) (get-nonsequential-keys t)
id (get-id self t)]
;; fancy metatable stuff can result in self.appearances not including
;; a table, so if it's not found, assume we haven't seen it; we can't
;; do cycle detection in that case.
(when (and (< 1 (or (. self.appearances t) 0)) self.detect-cycles?)
(puts self "@" id))
(if (and (= (length non-seq-keys) 0) (= (length t) 0))
(puts self (if self.empty-as-square "[]" "{}"))
(= (length non-seq-keys) 0)
(put-sequential-table self t len)
:else
(put-kv-table self t non-seq-keys))))))
(set put-value (fn [self v]
(let [tv (type v)]
(if (= tv "string")
(puts self (view-quote (escape v)))
(or (= tv "number") (= tv "boolean") (= tv "nil"))
(puts self (tostring v))
(= tv "table")
(put-table self v)
:else
(puts self "#<" (tostring v) ">")))))
(fn one-line [str]
;; save return value as local to ignore gsub's extra return value
(let [ret (-> str
(: :gsub "\n" " ")
(: :gsub "%[ " "[") (: :gsub " %]" "]")
(: :gsub "%{ " "{") (: :gsub " %}" "}")
(: :gsub "%( " "(") (: :gsub " %)" ")"))]
ret))
(fn fennelview [x options]
"Return a string representation of x.
Can take an options table with these keys:
* :one-line (boolean: default: false) keep the output string as a one-liner
* :depth (number, default: 128) limit how many levels to go (default: 128)
* :indent (string, default: \" \") use this string to indent each level
* :detect-cycles? (boolean, default: true) don't try to traverse a looping table
* :metamethod? (boolean: default: true) use the __fennelview metamethod if found
* :table-edges (boolean: default: true) put {} table brackets on their own line
* :empty-as-square (boolean: default: false) render empty tables as [], not {}
The __fennelview metamethod should take the table being serialized as its first
argument and a function as its second arg which can be used on table elements to
continue the fennelview process on them.
"
(let [options (or options {})
inspector {:appearances (count-table-appearances x {})
:depth (or options.depth 128)
:level 0 :buffer {} :ids {} :max-ids {}
:indent (or options.indent (if options.one-line "" " "))
:detect-cycles? (not (= false options.detect-cycles?))
:metamethod? (not (= false options.metamethod?))
:fennelview #(fennelview $1 options)
:table-edges (not= options.table-edges false)
:empty-as-square options.empty-as-square}]
(put-value inspector x)
(let [str (table.concat inspector.buffer)]
(if options.one-line (one-line str) str))))

357
vendor/jeejah/jeejah.lua vendored Normal file
View file

@ -0,0 +1,357 @@
local socket = require "socket"
local serpent = require "serpent"
local bencode = require "bencode"
local load = loadstring or load
local timeout = 0.001
local d = os.getenv("DEBUG") and print or function(_) end
local serpent_pp = function(p) return function(x)
local serpent_opts = {maxlevel=8,maxnum=64,nocode=true}
p(serpent.block(x, serpent_opts)) end
end
local sessions = {}
local response_for = function(old_msg, msg)
-- certain implementations break when the ns field is empty; see
-- https://gitlab.com/technomancy/jeejah/issues/5
msg.session, msg.id, msg.ns = old_msg.session, old_msg.id, ">"
return msg
end
local send = function(conn, msg)
d("Sending", bencode.encode(msg))
conn:send(bencode.encode(msg))
end
local write_for = function(conn, msg)
return function(...)
send(conn, response_for(msg, {out=table.concat({...}, "\t")}))
end
end
local print_for = function(write)
return function(...)
local args = {...}
for i,x in ipairs(args) do args[i] = tostring(x) end
table.insert(args, "\n")
write(table.concat(args, " "))
end
end
local read_for = function(conn, msg)
return function()
send(conn, response_for(msg, {status={"need-input"}}))
while(not sessions[msg.session].input) do
coroutine.yield()
d("yielded")
end
local input = sessions[msg.session].input
sessions[msg.session].input = nil
return input
end
end
local sandbox_for = function(write, provided_sandbox)
local sandbox = { io = { write = write },
print = print_for(write), }
for k,v in pairs(provided_sandbox) do
sandbox[k] = v
end
return sandbox
end
-- for stuff that's shared between eval and load_file
local execute_chunk = function(session, chunk, pp)
local old_write, old_print, old_read = io.write, print, io.read
if(session.sandbox) then
setfenv(chunk, session.sandbox)
pp = pp or serpent_pp(session.sandbox.print)
else
_G.print = print_for(session.write)
_G.io.write, _G.io.read = session.write, session.read
pp = pp or serpent_pp(_G.print)
end
local trace, err
local result = {xpcall(chunk, function(e)
trace = debug.traceback()
err = e end)}
_G.print, _G.io.write, _G.io.read = old_print, old_write, old_read
if(result[1]) then
local res, i = pp(result[2]), 3
while i <= #result do
res = res .. ', ' .. pp(result[i])
i = i + 1
end
return res
else
return nil, (err or "Unknown error") .. "\n" .. trace
end
end
local eval = function(session, code, pp)
local chunk, err = load("return " .. code, "*socket*")
if(err and not chunk) then -- statement, not expression
chunk, err = load(code, "*socket*")
if(not chunk) then
return nil, "Compilation error: " .. (err or "unknown")
end
end
return execute_chunk(session, chunk, pp)
end
local load_file = function(session, file, loader)
local chunk, err = (loader or loadfile)(file)
if(not chunk) then
return nil, "Compilation error in " .. file ": ".. (err or "unknown")
end
return execute_chunk(session, chunk)
end
local register_session = function(conn, msg, provided_sandbox)
local id = tostring(math.random(999999999))
local write = write_for(conn, msg)
local sandbox = provided_sandbox and sandbox_for(write, provided_sandbox)
sessions[id] = { conn = conn, write = write, print = print_for(write),
sandbox = sandbox, coros = {}, id = id}
return response_for(msg, {["new-session"]=id, status={"done"}})
end
local unregister_session = function(msg)
sessions[msg.session] = nil
return response_for(msg, {status={"done"}})
end
local describe = function(msg, handlers)
local ops = { "clone", "close", "describe", "eval", "load-file",
"ls-sessions", "complete", "stdin", "interrupt" }
for op in handlers do table.insert(ops, op) end
return response_for(msg, {ops=ops, status={"done"}})
end
local session_for = function(conn, msg, sandbox)
local s = sessions[msg.session] or register_session(conn, msg, sandbox)
s.write = write_for(conn, msg)
s.read = read_for(conn, msg)
return s
end
local complete = function(msg, sandbox)
local clone = function(t)
local n = {} for k,v in pairs(t) do n[k] = v end return n
end
local top_ctx = clone(sandbox or _G)
for k,v in pairs(msg.libs or {}) do
top_ctx[k] = require(v:sub(2,-2))
end
local function cpl_for(input_parts, ctx)
if type(ctx) ~= "table" then return {} end
if #input_parts == 0 and ctx ~= top_ctx then
return ctx
elseif #input_parts == 1 then
local matches = {}
for k in pairs(ctx) do
if k:find('^' .. input_parts[1]) then
table.insert(matches, k)
end
end
return matches
else
local token1 = table.remove(input_parts, 1)
return cpl_for(input_parts, ctx[token1])
end
end
local input_parts = {}
for i in string.gmatch(msg.input, "([^.%s]+)") do
table.insert(input_parts, i)
end
return response_for(msg, {completions = cpl_for(input_parts, top_ctx)})
end
-- see https://github.com/clojure/tools.nrepl/blob/master/doc/ops.md
local handle = function(conn, handlers, sandbox, msg)
if(handlers and handlers[msg.op]) then
d("Custom op:", msg.op)
handlers[msg.op](conn, msg, session_for(conn, msg, sandbox),
send, response_for)
elseif(msg.op == "clone") then
d("New session.")
send(conn, register_session(conn, msg, sandbox))
elseif(msg.op == "describe") then
d("Describe.")
send(conn, describe(msg, handlers))
elseif(msg.op == "eval") then
d("Evaluating", msg.code)
local value, err = eval(session_for(conn, msg, sandbox), msg.code, msg.pp)
d("Got", value, err)
-- monroe bug means you have to send done status separately
send(conn, response_for(msg, {value=value, ex=err}))
send(conn, response_for(msg, {status={"done"}}))
elseif(msg.op == "load-file") then
d("Loading file", msg.file)
local value, err = load_file(session_for(conn, msg, sandbox),
msg.file, msg.loader)
d("Got", value, err)
send(conn, response_for(msg, {value=value, ex=err, status={"done"}}))
elseif(msg.op == "ls-sessions") then
d("List sessions")
local session_ids = {}
for id in pairs(sessions) do table.insert(session_ids, id) end
send(conn, response_for(msg, {sessions=session_ids, status={"done"}}))
elseif(msg.op == "complete") then
d("Complete", msg.input)
local session_sandbox = session_for(conn, msg, sandbox).sandbox
send(conn, complete(msg, session_sandbox))
elseif(msg.op == "stdin") then
d("Stdin", serpent.block(msg))
sessions[msg.session].input = msg.stdin
send(conn, response_for(msg, {status={"done"}}))
return
elseif(msg.op ~= "interrupt") then -- silently ignore interrupt
send(conn, response_for(msg, {status={"unknown-op"}}))
print(" | Unknown op", serpent.block(msg))
end
end
local handler_coros = {}
local function receive(conn, partial)
local s, err = conn:receive(1) -- wow this is primitive
-- iterate backwards so we can safely remove
for i=#handler_coros, 1, -1 do
local ok, err2 = coroutine.resume(handler_coros[i])
if(coroutine.status(handler_coros[i]) ~= "suspended") then
if(not ok) then print(" | Handler error", err2) end
table.remove(handler_coros, i)
end
end
if(s) then
return receive(conn, (partial or "") .. s)
elseif(err == "timeout" and partial == nil) then
coroutine.yield()
return receive(conn)
elseif(err == "timeout") then
return partial
else
return nil, err
end
end
local function client_loop(conn, sandbox, handlers, middleware, partial)
local input, r_err = receive(conn, partial)
if(input) then
local decoded, d_err = bencode.decode(input)
if decoded and d_err < #input then
partial = input:sub(d_err + 1)
else
partial = nil
end
coroutine.yield()
if(decoded and decoded.op == "close") then
d("End session.")
return send(conn, unregister_session(decoded))
elseif(decoded and decoded.op ~= "close") then
-- If we don't spin up a coroutine here, we can't io.read, because
-- that requires waiting for a response from the client. But most
-- messages don't need to stick around.
local coro = coroutine.create(handle)
if(middleware) then
middleware(function(msg)
local ok, err = coroutine.resume(coro, conn, handlers,
sandbox, msg)
if(not ok) then print(" | Handler error", err) end
end, decoded)
else
local ok, err = coroutine.resume(coro, conn, handlers,
sandbox, decoded)
if(not ok) then print(" | Handler error", err) end
end
if(coroutine.status(coro) == "suspended") then
table.insert(handler_coros, coro)
end
else
print(" | Decoding error:", d_err)
end
return client_loop(conn, sandbox, handlers, middleware, partial)
else
return r_err
end
end
local connections = {}
local function loop(server, sandbox, handlers, middleware, foreground)
socket.sleep(timeout)
local conn, err = server:accept()
local stop = (not foreground) and (coroutine.yield() == "stop")
if(conn) then
conn:settimeout(timeout)
d("Connected.")
local coro = coroutine.create(function()
local _, h_err = pcall(client_loop, conn, sandbox, handlers, middleware)
if(h_err ~= "closed") then print("Connection closed: " .. h_err) end
end)
table.insert(connections, coro)
return loop(server, sandbox, handlers, middleware, foreground)
else
if(err ~= "timeout") then print(" | Socket error: " .. err) end
for _,c in ipairs(connections) do coroutine.resume(c) end
if(stop or err == "closed") then
server:close()
print("Server stopped.")
else
return loop(server, sandbox, handlers, middleware, foreground)
end
end
end
return {
-- Start an nrepl socket server on the given port. For opts you can pass a
-- table with foreground=true to run in the foreground, debug=true for
-- verbose logging, and sandbox={...} to evaluate all code in a sandbox. You
-- can also give an opts.handlers table keying ops to handler functions which
-- take the socket, the decoded message, and the optional sandbox table.
start = function(port, opts)
port = port or 7888
opts = opts or {}
opts.handlers = opts.handlers or {}
-- host should always be localhost on a PC, but not always on a micro
local server = assert(socket.bind(opts.host or "localhost", port))
if(opts.debug) then d = print end
if(opts.timeout) then timeout = tonumber(opts.timeout) end
if(opts.fennel) then
local fenneleval = require("jeejah.fenneleval")
opts.handlers.eval = fenneleval
opts.handlers.stdin = fenneleval
end
assert(not opts.sandbox or setfenv, "Can't use sandbox on 5.2+")
server:settimeout(timeout)
print("Server started on port " .. port .. "...")
if opts.foreground then
return loop(server, opts.sandbox, opts.handlers,
opts.middleware, opts.foreground)
else
return coroutine.create(function()
loop(server, opts.sandbox, opts.handlers, opts.middleware)
end)
end
end,
-- Pass in the coroutine from jeejah.start to this function to stop it.
stop = function(coro)
coroutine.resume(coro, "stop")
end,
broadcast = function(msg)
for _,session in pairs(sessions) do
send(session.conn, msg)
end
end,
}

77
vendor/jeejah/jeejah/fenneleval.lua vendored Normal file
View file

@ -0,0 +1,77 @@
local fennel = require("fennel")
local fennelview_ok, fennelview = pcall(require, "fennelview")
if not fennelview_ok then fennelview = fennel.dofile("fennelview.fnl") end
local d = os.getenv("DEBUG") and print or function(_) end
local repls = {}
local print_for = function(write)
return function(...)
local args = {...}
for i,x in ipairs(args) do args[i] = tostring(x) end
table.insert(args, "\n")
write(table.concat(args, " "))
end
end
local make_repl = function(session, repls)
local on_values = function(xs)
session.values(xs)
session.done({status={"done"}})
end
local read = function()
-- If we skip empty input, it confuses the client.
local input = coroutine.yield()
if(input:find("^%s*$")) then return "nil\n" else return input end
end
local err = function(errtype, msg)
session.write(table.concat({errtype, msg}, ": ")) session.done()
end
local env = session.sandbox
if not env then
env = {}
for k, v in pairs(_G) do env[k] = v end
env.io = {}
end
env.print = print_for(session.write)
env.io.write = session.write
env.io.read = function()
session.needinput()
local input, done = coroutine.yield()
done()
return input
end
local f = function()
return fennel.repl({readChunk = read,
onValues = on_values,
onError = err,
env = env,
pp = fennelview})
end
repls[session.id] = coroutine.wrap(f)
repls[session.id]()
return repls[session.id]
end
return function(conn, msg, session, send, response_for)
d("Evaluating", msg.code)
local repl = repls[session.id] or make_repl(session, repls)
if msg.op == "eval" then
session.values = function(xs)
send(conn, response_for(msg, {value=table.concat(xs, "\n") .. "\n"}))
end
session.done = function()
send(conn, response_for(msg, {status={"done"}}))
end
session.needinput = function()
send(conn, response_for(msg, {status={"need-input"}}))
end
repl(msg.code .. "\n")
elseif msg.op == "stdin" then
repl(msg.stdin,
function() send(conn, response_for(msg, {status={"done"}})) end)
end
end

89
vendor/jeejah/monroe-lua-complete.el vendored Normal file
View file

@ -0,0 +1,89 @@
;;; monroe-lua-complete.el --- Completion for Lua over Monroe connection
;; Copyright © 2016 Phil Hagelberg
;;
;; Author: Phil Hagelberg
;; URL: https://gitlab.com/technomancy/jeejah
;; Version: 0.1.0
;; Keywords: languages, nrepl, lua
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;; This file is not part of GNU Emacs.
;;; Commentary:
;; Provides live completion results for Lua by querying a Lua process
;; over an nREPL connection. Uses `completion-at-point' but can be
;; adapted for other completion methods.
;;; Installation:
;; Copy it to your load-path and (require 'monroe-lua-complete)
;;; Usage:
;; * Launch an nREPL server using jeejah.
;; * Connect to it with M-x monroe.
;; * Complete the expression at point with M-x completion-at-point
;; also bound to M-tab or C-M-i.
;;; Code:
(require 'lua-mode) ; requires a newer lua-mode that has lua-start-of-expr
(require 'monroe)
(defvar monroe-completion-candidates nil)
(defun monroe-completion-handler (response)
"Set `monroe-completion-candidates' based on response from Lua server.
Since monroe doesn't have any synchronous communication available, we
have to `sit-for' and hope a response has been returned and handled."
(monroe-dbind-response response (id completions status output)
(let ((process (get-buffer-process monroe-repl-buffer)))
(comint-output-filter process output)
(when completions
(setq monroe-completion-candidates completions))
(when status
(when (member "done" status)
(remhash id monroe-requests))))))
(defun monroe-lua-complete-function ()
"Completion function for `completion-at-point-functions'.
Queries over current lua connection for possible completions."
(let ((expr (buffer-substring-no-properties (lua-start-of-expr) (point))))
(monroe-send-request `("op" "complete"
"input" ,expr
;; TODO: at this time, monroe cannot bencode
;; nested values, only string->string dicts
;; "libs" ,(lua-local-libs)
"session" ,(monroe-current-session))
'monroe-completion-handler))
(sit-for 0.1)
(list (save-excursion (when (symbol-at-point) (backward-sexp)) (point))
(point)
monroe-completion-candidates))
;;;###autoload
(defun monroe-lua-hook ()
(make-local-variable 'completion-at-point-functions)
(add-to-list 'completion-at-point-functions 'monroe-lua-complete-function))
;;;###autoload
(eval-after-load 'lua-mode
'(add-to-list 'lua-mode-hook 'monroe-lua-hook))
;;; monroe-lua-complete.el ends here

View file

@ -0,0 +1,28 @@
-- -*- lua -*-
package = "jeejah"
version = "0.1.0-1"
source = {
url = "https://gitlab.com/technomancy/jeejah.git",
tag = "0.1.0",
}
description = {
summary = "An nREPL server",
detailed = [[
Implements a server that speaks the nREPL protocol and allows
clients to connect and evaluate code over a network connection.
]],
homepage = "https://gitlab.com/technomancy/jeejah.git",
license = "MIT/X11",
}
dependencies = {
"lua ~> 5.1",
"luasocket = 3.0rc1-2",
"serpent = 0.28-1",
"bencode = 2.2.0-1",
}
build = {
type = "builtin",
modules = { jeejah = "jeejah.lua", },
install = { bin = { "bin/jeejah" } },
}

View file

@ -0,0 +1,28 @@
-- -*- lua -*-
package = "jeejah"
version = "0.2.1-1"
source = {
url = "git+https://gitlab.com/technomancy/jeejah.git",
tag = "0.2.1",
}
description = {
summary = "An nREPL server",
detailed = [[
Implements a server that speaks the nREPL protocol and allows
clients to connect and evaluate code over a network connection.
]],
homepage = "https://gitlab.com/technomancy/jeejah",
license = "MIT/X11",
}
dependencies = {
"lua >= 5.1",
"luasocket = 3.0rc1-2",
"serpent = 0.28-1",
"bencode = 2.2.0-1",
}
build = {
type = "builtin",
modules = { jeejah = "jeejah.lua", },
install = { bin = { "bin/jeejah" } },
}

View file

@ -0,0 +1,28 @@
-- -*- lua -*-
package = "jeejah"
version = "0.2.1-4"
source = {
url = "git+https://gitlab.com/technomancy/jeejah.git",
tag = "0.2.4",
}
description = {
summary = "An nREPL server",
detailed = [[
Implements a server that speaks the nREPL protocol and allows
clients to connect and evaluate code over a network connection.
]],
homepage = "https://gitlab.com/technomancy/jeejah",
license = "MIT/X11",
}
dependencies = {
"lua >= 5.1",
"luasocket = 3.0rc1-2",
"serpent = 0.28-1",
"bencode = 2.2.0-1",
}
build = {
type = "builtin",
modules = { jeejah = "jeejah.lua", },
install = { bin = { "bin/jeejah" } },
}

View file

@ -0,0 +1,28 @@
-- -*- lua -*-
package = "jeejah"
version = "0.3.0-1"
source = {
url = "git+https://gitlab.com/technomancy/jeejah.git",
tag = "0.3.0",
}
description = {
summary = "An nREPL server",
detailed = [[
Implements a server that speaks the nREPL protocol and allows
clients to connect and evaluate code over a network connection.
]],
homepage = "https://gitlab.com/technomancy/jeejah",
license = "MIT/X11",
}
dependencies = {
"lua >= 5.1",
"luasocket = 3.0rc1-2",
"serpent = 0.28-1",
"bencode = 2.2.0-1",
}
build = {
type = "builtin",
modules = { jeejah = "jeejah.lua", },
install = { bin = { "bin/jeejah" } },
}

View file

@ -0,0 +1,28 @@
-- -*- lua -*-
package = "jeejah"
version = "0.3.1-1"
source = {
url = "git+https://gitlab.com/technomancy/jeejah.git",
tag = "0.3.1",
}
description = {
summary = "An nREPL server",
detailed = [[
Implements a server that speaks the nREPL protocol and allows
clients to connect and evaluate code over a network connection.
]],
homepage = "https://gitlab.com/technomancy/jeejah",
license = "MIT/X11",
}
dependencies = {
"lua >= 5.1",
"luasocket = 3.0rc1-2",
"serpent = 0.28-1",
"bencode = 2.2.0-1",
}
build = {
type = "builtin",
modules = { jeejah = "jeejah.lua", },
install = { bin = { "bin/jeejah" } },
}

View file

@ -0,0 +1,29 @@
-- -*- lua -*-
package = "jeejah"
version = "0.3.1-2"
source = {
url = "git+https://gitlab.com/technomancy/jeejah.git",
tag = "0.3.1",
}
description = {
summary = "An nREPL server",
detailed = [[
Implements a server that speaks the nREPL protocol and allows
clients to connect and evaluate code over a network connection.
]],
homepage = "https://gitlab.com/technomancy/jeejah",
license = "MIT/X11",
}
dependencies = {
"lua >= 5.1",
"luasocket = 3.0rc1-2",
"serpent = 0.28-1",
"bencode = 2.2.0-1",
}
build = {
type = "builtin",
modules = { jeejah = "jeejah.lua",
["jeejah.fenneleval"] = "jeejah/fenneleval.lua" },
install = { bin = { "bin/jeejah" } },
}

View file

@ -0,0 +1,30 @@
-- -*- lua -*-
package = "jeejah"
version = "0.3.1-4"
source = {
url = "git+https://gitlab.com/technomancy/jeejah.git",
tag = "0.3.1",
}
description = {
summary = "An nREPL server",
detailed = [[
Implements a server that speaks the nREPL protocol and allows
clients to connect and evaluate code over a network connection.
]],
homepage = "https://gitlab.com/technomancy/jeejah",
license = "MIT/X11",
}
dependencies = {
"lua >= 5.1",
"luasocket = 3.0rc1-2",
"serpent = 0.28-1",
}
build = {
type = "builtin",
modules = { jeejah = "jeejah.lua",
["jeejah.fenneleval"] = "jeejah/fenneleval.lua",
bencode = "bencode.lua",
},
install = { bin = { "bin/jeejah" } },
}

125
vendor/jeejah/serpent.lua vendored Normal file
View file

@ -0,0 +1,125 @@
local n, v = "serpent", 0.28 -- (C) 2012-15 Paul Kulchenko; MIT License
local c, d = "Paul Kulchenko", "Lua serializer and pretty printer"
local snum = {[tostring(1/0)]='1/0 --[[math.huge]]',[tostring(-1/0)]='-1/0 --[[-math.huge]]',[tostring(0/0)]='0/0'}
local badtype = {thread = true, userdata = true, cdata = true}
local keyword, globals, G = {}, {}, (_G or _ENV)
for _,k in ipairs({'and', 'break', 'do', 'else', 'elseif', 'end', 'false',
'for', 'function', 'goto', 'if', 'in', 'local', 'nil', 'not', 'or', 'repeat',
'return', 'then', 'true', 'until', 'while'}) do keyword[k] = true end
for k,v in pairs(G) do globals[v] = k end -- build func to name mapping
for _,g in ipairs({'coroutine', 'debug', 'io', 'math', 'string', 'table', 'os'}) do
for k,v in pairs(G[g] or {}) do globals[v] = g..'.'..k end end
local function s(t, opts)
local name, indent, fatal, maxnum = opts.name, opts.indent, opts.fatal, opts.maxnum
local sparse, custom, huge = opts.sparse, opts.custom, not opts.nohuge
local space, maxl = (opts.compact and '' or ' '), (opts.maxlevel or math.huge)
local iname, comm = '_'..(name or ''), opts.comment and (tonumber(opts.comment) or math.huge)
local seen, sref, syms, symn = {}, {'local '..iname..'={}'}, {}, 0
local function gensym(val) return '_'..(tostring(tostring(val)):gsub("[^%w]",""):gsub("(%d%w+)",
-- tostring(val) is needed because __tostring may return a non-string value
function(s) if not syms[s] then symn = symn+1; syms[s] = symn end return tostring(syms[s]) end)) end
local function safestr(s) return type(s) == "number" and tostring(huge and snum[tostring(s)] or s)
or type(s) ~= "string" and tostring(s) -- escape NEWLINE/010 and EOF/026
or ("%q"):format(s):gsub("\010","n"):gsub("\026","\\026") end
local function comment(s,l) return comm and (l or 0) < comm and ' --[['..tostring(s)..']]' or '' end
local function globerr(s,l) return globals[s] and globals[s]..comment(s,l) or not fatal
and safestr(select(2, pcall(tostring, s))) or error("Can't serialize "..tostring(s)) end
local function safename(path, name) -- generates foo.bar, foo[3], or foo['b a r']
local n = name == nil and '' or name
local plain = type(n) == "string" and n:match("^[%l%u_][%w_]*$") and not keyword[n]
local safe = plain and n or '['..safestr(n)..']'
return (path or '')..(plain and path and '.' or '')..safe, safe end
local alphanumsort = type(opts.sortkeys) == 'function' and opts.sortkeys or function(k, o, n) -- k=keys, o=originaltable, n=padding
local maxn, to = tonumber(n) or 12, {number = 'a', string = 'b'}
local function padnum(d) return ("%0"..tostring(maxn).."d"):format(tonumber(d)) end
table.sort(k, function(a,b)
-- sort numeric keys first: k[key] is not nil for numerical keys
return (k[a] ~= nil and 0 or to[type(a)] or 'z')..(tostring(a):gsub("%d+",padnum))
< (k[b] ~= nil and 0 or to[type(b)] or 'z')..(tostring(b):gsub("%d+",padnum)) end) end
local function val2str(t, name, indent, insref, path, plainindex, level)
local ttype, level, mt = type(t), (level or 0), getmetatable(t)
local spath, sname = safename(path, name)
local tag = plainindex and
((type(name) == "number") and '' or name..space..'='..space) or
(name ~= nil and sname..space..'='..space or '')
if seen[t] then -- already seen this element
sref[#sref+1] = spath..space..'='..space..seen[t]
return tag..'nil'..comment('ref', level) end
if type(mt) == 'table' and (mt.__serialize or mt.__tostring) then -- knows how to serialize itself
seen[t] = insref or spath
if mt.__serialize then t = mt.__serialize(t) else t = tostring(t) end
ttype = type(t) end -- new value falls through to be serialized
if ttype == "table" then
if level >= maxl then return tag..'{}'..comment('max', level) end
seen[t] = insref or spath
-- PNH: this breaks with our metatable monkeypatch to support iterators
-- if next(t) == nil then return tag..'{}'..comment(t, level) end -- table empty
local maxn, o, out = math.min(#t, maxnum or #t), {}, {}
for key = 1, maxn do o[key] = key end
if not maxnum or #o < maxnum then
local n = #o -- n = n + 1; o[n] is much faster than o[#o+1] on large tables
for key in pairs(t) do if o[key] ~= key then n = n + 1; o[n] = key end end end
if maxnum and #o > maxnum then o[maxnum+1] = nil end
if opts.sortkeys and #o > maxn then alphanumsort(o, t, opts.sortkeys) end
local sparse = sparse and #o > maxn -- disable sparsness if only numeric keys (shorter output)
for n, key in ipairs(o) do
local value, ktype, plainindex = t[key], type(key), n <= maxn and not sparse
if opts.valignore and opts.valignore[value] -- skip ignored values; do nothing
or opts.keyallow and not opts.keyallow[key]
or opts.valtypeignore and opts.valtypeignore[type(value)] -- skipping ignored value types
or sparse and value == nil then -- skipping nils; do nothing
elseif ktype == 'table' or ktype == 'function' or badtype[ktype] then
if not seen[key] and not globals[key] then
sref[#sref+1] = 'placeholder'
local sname = safename(iname, gensym(key)) -- iname is table for local variables
sref[#sref] = val2str(key,sname,indent,sname,iname,true) end
sref[#sref+1] = 'placeholder'
local path = seen[t]..'['..tostring(seen[key] or globals[key] or gensym(key))..']'
sref[#sref] = path..space..'='..space..tostring(seen[value] or val2str(value,nil,indent,path))
else
out[#out+1] = val2str(value,key,indent,insref,seen[t],plainindex,level+1)
end
end
local prefix = string.rep(indent or '', level)
local head = indent and '{\n'..prefix..indent or '{'
local body = table.concat(out, ','..(indent and '\n'..prefix..indent or space))
local tail = indent and "\n"..prefix..'}' or '}'
return (custom and custom(tag,head,body,tail) or tag..head..body..tail)..comment(t, level)
elseif badtype[ttype] then
seen[t] = insref or spath
return tag..globerr(t, level)
elseif ttype == 'function' then
seen[t] = insref or spath
local ok, res = pcall(string.dump, t)
local func = ok and ((opts.nocode and "function() --[[..skipped..]] end" or
"((loadstring or load)("..safestr(res)..",'@serialized'))")..comment(t, level))
return tag..(func or globerr(t, level))
else return tag..safestr(t) end -- handle all other types
end
local sepr = indent and "\n" or ";"..space
local body = val2str(t, name, indent) -- this call also populates sref
local tail = #sref>1 and table.concat(sref, sepr)..sepr or ''
local warn = opts.comment and #sref>1 and space.."--[[incomplete output with shared/self-references skipped]]" or ''
return not name and body..warn or "do local "..body..sepr..tail.."return "..name..sepr.."end"
end
local function deserialize(data, opts)
local env = (opts and opts.safe == false) and G
or setmetatable({}, {
__index = function(t,k) return t end,
__call = function(t,...) error("cannot call functions") end
})
local f, res = (loadstring or load)('return '..data, nil, nil, env)
if not f then f, res = (loadstring or load)(data, nil, nil, env) end
if not f then return f, res end
if setfenv then setfenv(f, env) end
return pcall(f)
end
local function merge(a, b) if b then for k,v in pairs(b) do a[k] = v end end; return a; end
return { _NAME = n, _COPYRIGHT = c, _DESCRIPTION = d, _VERSION = v, serialize = s,
load = deserialize,
dump = function(a, opts) return s(a, merge({name = '_', compact = true, sparse = true}, opts)) end,
line = function(a, opts) return s(a, merge({sortkeys = true, comment = true}, opts)) end,
block = function(a, opts) return s(a, merge({indent = ' ', sortkeys = true, comment = true}, opts)) end }

12
vendor/lite-plugins/.gitrepo vendored Normal file
View file

@ -0,0 +1,12 @@
; DO NOT EDIT (unless you know what you are doing)
;
; This subdirectory is a git "subrepo", and this file is maintained by the
; git-subrepo command. See https://github.com/git-commands/git-subrepo#readme
;
[subrepo]
remote = https://github.com/rxi/lite-plugins
branch = master
commit = de4227d55a5c821e3450554c952dfb3b1b192266
parent = c843deea3de5d5d8782fe4dadbdbd40422ab88f8
method = merge
cmdver = 0.4.2

86
vendor/lite-plugins/README.md vendored Normal file
View file

@ -0,0 +1,86 @@
Plugins for the [lite text editor](https://github.com/rxi/lite)
*Note: if you make a pull request, the table should be updated and kept in
alphabetical order. If your plugin is large (or you'd otherwise prefer it to
have its own repo), the table can simply be updated to add a link to the repo;
otherwise the plugin file itself can be submitted. If a plugin's link resolves
to something other than a raw file it should be marked with an asterisk.*
---
Plugin | Description
-------|-----------------------------------------
[`autoinsert`](plugins/autoinsert.lua?raw=1) | Automatically inserts closing brackets and quotes
[`autowrap`](plugins/autowrap.lua?raw=1) | Automatically hardwraps lines when typing
[`bigclock`](plugins/bigclock.lua?raw=1) | Shows the current time and date in a view with large text *([screenshot](https://user-images.githubusercontent.com/3920290/82752891-3318df00-9db9-11ea-803f-261d80d5cf53.png))*
[`black`](https://git.sr.ht/~tmpod/black-lite)* | Integrates the [black](https://github.com/psf/black) Python formatter with lite
[`bracketmatch`](plugins/bracketmatch.lua?raw=1) | Underlines matching pair for bracket under the caret *([screenshot](https://user-images.githubusercontent.com/3920290/80132745-0c863f00-8594-11ea-8875-c455c6fd7eae.png))*
[`centerdoc`](plugins/centerdoc.lua?raw=1) | Centers document's content on the screen *([screenshot](https://user-images.githubusercontent.com/3920290/82127896-bf6e4500-97ae-11ea-97fc-ba9a552bc9a4.png))*
[`colorpreview`](plugins/colorpreview.lua?raw=1) | Underlays color values (eg. `#ff00ff` or `rgb(255, 0, 255)`) with their resultant color. *([screenshot](https://user-images.githubusercontent.com/3920290/80743752-731bd780-8b15-11ea-97d3-847db927c5dc.png))*
[`console`](https://github.com/rxi/console)* | A console for running external commands and capturing their output *([gif](https://user-images.githubusercontent.com/3920290/81343656-49325a00-90ad-11ea-8647-ff39d8f1d730.gif))*
[`copyfilelocation`](plugins/copyfilelocation.lua?raw=1) | Copy file location to clipboard
[`datetimestamps`](plugins/datetimestamps.lua?raw=1) | Insert date-, time- and date-time-stamps
[`detectindent`](plugins/detectindent.lua?raw=1) | Automatically detects and uses the indentation size and tab type of a loaded file
[`dragdropselected`](plugins/dragdropselected.lua?raw=1) | Provides basic drag and drop of selected text (in same document)
[`drawwhitespace`](plugins/drawwhitespace.lua?raw=1) | Draws tabs and spaces *([screenshot](https://user-images.githubusercontent.com/3920290/80573013-22ae5800-89f7-11ea-9895-6362a1c0abc7.png))*
[`eofnewline`](https://github.com/bokunodev/lite_modules/blob/master/plugins/eofnewline.lua?raw=1) | Make sure the file ends with one blank line.
[`eval`](plugins/eval.lua?raw=1) | Replaces selected Lua code with its evaluated result
[`exec`](plugins/exec.lua?raw=1) | Runs selected text through shell command and replaces with result
[`ghmarkdown`](plugins/ghmarkdown.lua?raw=1) | Opens a preview of the current markdown file in a browser window *([screenshot](https://user-images.githubusercontent.com/3920290/82754898-f7394600-9dc7-11ea-8278-2305363ed372.png))*
[`gitstatus`](plugins/gitstatus.lua?raw=1) | Displays git branch and insert/delete count in status bar *([screenshot](https://user-images.githubusercontent.com/3920290/81107223-bcea3080-8f0e-11ea-8fc7-d03173f42e33.png))*
[`gofmt`](plugins/gofmt.lua?raw=1) | Auto-formats the current go file, adds the missing imports and the missing return cases
[`hidelinenumbers`](plugins/hidelinenumbers.lua?raw=1) | Hides the line numbers on the left of documents *([screenshot](https://user-images.githubusercontent.com/3920290/81692043-b8b19c00-9455-11ea-8d74-ad99be4b9c5f.png))*
[`hidestatus`](plugins/hidestatus.lua?raw=1) | Hides the status bar at the bottom of the window
[`inanimate`](plugins/inanimate.lua?raw=1) | Disables all transition animations
[`indentguide`](plugins/indentguide.lua?raw=1) | Adds indent guides *([screenshot](https://user-images.githubusercontent.com/3920290/79640716-f9860000-818a-11ea-9c3b-26d10dd0e0c0.png))*
[`language_angelscript`](plugins/language_angelscript.lua?raw=1) | Syntax for the [Angelscript](https://www.angelcode.com/angelscript/) programming language
[`language_batch`](plugins/language_batch.lua?raw=1) | Syntax for Windows [Batch Files](https://en.wikipedia.org/wiki/Batch_file)
[`language_cmake`](plugins/language_cmake.lua?raw=1) | Syntax for the CMake build system language
[`language_cpp`](plugins/language_cpp.lua?raw=1) | Syntax for the [C++](https://isocpp.org/) programming language
[`language_csharp`](plugins/language_csharp.lua?raw=1) | Syntax for the [C#](http://csharp.net) programming language
[`language_d`](plugins/language_d.lua?raw=1) | Syntax for the [D](https://dlang.org/) programming language
[`language_elixir`](plugins/language_elixir.lua?raw=1) | Syntax for the [Elixir](https://elixir-lang.org) programming language
[`language_elm`](plugins/language_elm.lua?raw=1) | Syntax for the [Elm](https://elm-lang.org) programming language
[`language_fe`](plugins/language_fe.lua?raw=1) | Syntax for the [fe](https://github.com/rxi/fe) programming language
[`language_fennel`](plugins/language_fennel.lua?raw=1) | Syntax for the [fennel](https://fennel-lang.org) programming language
[`language_gdscript`](plugins/language_gdscript.lua?raw=1) | Syntax for the [Godot Engine](https://godotengine.org/)'s GDScript scripting language
[`language_glsl`](plugins/language_glsl.lua?raw=1) | Syntax for the [GLSL](https://www.khronos.org/registry/OpenGL/specs/gl/) programming language
[`language_go`](plugins/language_go.lua?raw=1) | Syntax for the [Go](https://golang.org/) programming language
[`language_hlsl`](plugins/language_hlsl.lua?raw=1) | Syntax for the [HLSL](https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl) programming language
[`language_hs`](plugins/language_hs.lua?raw=1) | Syntax for the [Haskell](https://www.haskell.org/) programming language
[`language_java`](plugins/language_java.lua?raw=1) | Syntax for the [Java](https://en.wikipedia.org/wiki/Java_(programming_language)) programming language
[`language_jiyu`](plugins/language_jiyu.lua?raw=1) | Syntax for the [jiyu](https://github.com/machinamentum/jiyu) programming language
[`language_ksy`](https://raw.githubusercontent.com/whiteh0le/lite-plugins/main/plugins/language_ksy.lua?raw=1) | Syntax for [Kaitai](http://kaitai.io/) struct files
[`language_make`](plugins/language_make.lua?raw=1) | Syntax for the Make build system language
[`language_meson`](plugins/language_meson.lua?raw=1) | Syntax for the [Meson](https://mesonbuild.com) build system language
[`language_odin`](plugins/language_odin.lua?raw=1) | Syntax for the [Odin](https://github.com/odin-lang/Odin) programming language
[`language_php`](plugins/language_php.lua?raw=1) | Syntax for the [PHP](https://php.net) programming language
[`language_pico8`](plugins/language_pico8.lua?raw=1) | Syntax for [Pico-8](https://www.lexaloffle.com/pico-8.php) cartridge files
[`language_powershell`](plugins/language_powershell.lua?raw=1) | Syntax for [PowerShell](https://docs.microsoft.com/en-us/powershell) scripting language
[`language_psql`](plugins/language_psql.lua?raw=1) | Syntax for the postgresql database access language
[`language_rust`](plugins/language_rust.lua?raw=1) | Syntax for the [Rust](https://rust-lang.org/) programming language
[`language_sh`](plugins/language_sh.lua?raw=1) | Syntax for shell scripting language
[`language_tex`](plugins/language_tex.lua?raw=1) | Syntax for the [LaTeX](https://www.latex-project.org/) typesetting language
[`language_wren`](plugins/language_wren.lua?raw=1) | Syntax for the [Wren](http://wren.io/) programming language
[`lastproject`](plugins/lastproject.lua?raw=1) | Loads the last loaded project if lite is launched without any arguments
[`lfautoinsert`](plugins/lfautoinsert.lua?raw=1) | Automatically inserts indentation and closing bracket/text after newline
[`linecopypaste`](plugins/linecopypaste.lua?raw=1) | Copy, cut and paste the current line when nothing is selected
[`lineguide`](plugins/lineguide.lua?raw=1) | Displays a line-guide at the line limit offset *([screenshot](https://user-images.githubusercontent.com/3920290/81476159-2cf70000-9208-11ea-928b-9dae3884c477.png))*
[`linter`](https://github.com/drmargarido/linters)* | Linters for multiple languages
[`macmodkeys`](plugins/macmodkeys.lua?raw=1) | Remaps mac modkeys `command/option` to `ctrl/alt`
[`markers`](plugins/markers.lua?raw=1) | Add markers to docs and jump between them quickly *([screenshot](https://user-images.githubusercontent.com/3920290/82252149-5faaa200-9946-11ea-9199-bea2efb7ee23.png))*
[`motiontrail`](plugins/motiontrail.lua?raw=1) | Adds a motion-trail to the caret *([screenshot](https://user-images.githubusercontent.com/3920290/83256814-085ccb00-a1ab-11ea-9e35-e6633cbed1a9.gif))*
[`openfilelocation`](plugins/openfilelocation.lua?raw=1) | Opens the parent directory of the current file in the file manager
[`openselected`](plugins/openselected.lua?raw=1) | Opens the selected filename or url
[`projectmanager`](plugins/projectmanager.lua?raw=1) | Save projects and load/reload them quickly
[`scale`](plugins/scale.lua?raw=1) | Provides support for dynamically adjusting the scale of the code font / UI (`ctrl+-`, `ctrl+=`)
[`scalestatus`](plugins/scalestatus.lua?raw=1) | Displays current scale (zoom) in status view (depends on scale plugin)
[`selectionhighlight`](plugins/selectionhighlight.lua?raw=1) | Highlights regions of code that match the current selection *([screenshot](https://user-images.githubusercontent.com/3920290/80710883-5f597c80-8ae7-11ea-97f0-76dfacc08439.png))*
[`sort`](plugins/sort.lua?raw=1) | Sorts selected lines alphabetically
[`spellcheck`](plugins/spellcheck.lua?raw=1) | Underlines misspelt words *([screenshot](https://user-images.githubusercontent.com/3920290/79923973-9caa7400-842e-11ea-85d4-7a196a91ca50.png))* *— note: on Windows a [`words.txt`](https://github.com/dwyl/english-words/blob/master/words.txt) dictionary file must be placed beside the exe*
[`theme16`](https://github.com/monolifed/theme16)* | Theme manager with base16 themes
[`titleize`](plugins/titleize.lua?raw=1) | Titleizes selected string (`hello world` => `Hello World`)
[`todotreeview`](https://github.com/drmargarido/TodoTreeView)* | Todo tree viewer for annotations in code like `TODO`, `BUG`, `FIX`, `IMPROVEMENT`
[`togglesnakecamel`](plugins/togglesnakecamel.lua?raw=1) | Toggles symbols between `snake_case` and `camelCase`
[`unboundedscroll`](plugins/unboundedscroll.lua?raw=1) | Allows scrolling outside the bounds of a document
[`workspace`](plugins/workspace.lua?raw=1) | Retains project's layout and open documents between sessions

View file

@ -0,0 +1,114 @@
local core = require "core"
local translate = require "core.doc.translate"
local config = require "core.config"
local DocView = require "core.docview"
local command = require "core.command"
local keymap = require "core.keymap"
config.autoinsert_map = {
["["] = "]",
["{"] = "}",
["("] = ")",
['"'] = '"',
["'"] = "'",
["`"] = "`",
}
local function is_closer(chr)
for _, v in pairs(config.autoinsert_map) do
if v == chr then
return true
end
end
end
local function count_char(text, chr)
local count = 0
for _ in text:gmatch(chr) do
count = count + 1
end
return count
end
local on_text_input = DocView.on_text_input
function DocView:on_text_input(text)
local mapping = config.autoinsert_map[text]
-- prevents plugin from operating on `CommandView`
if getmetatable(self) ~= DocView then
return on_text_input(self, text)
end
-- wrap selection if we have a selection
if mapping and self.doc:has_selection() then
local l1, c1, l2, c2, swap = self.doc:get_selection(true)
self.doc:insert(l2, c2, mapping)
self.doc:insert(l1, c1, text)
self.doc:set_selection(l1, c1, l2, c2 + 2, swap)
return
end
-- skip inserting closing text
local chr = self.doc:get_char(self.doc:get_selection())
if text == chr and is_closer(chr) then
self.doc:move_to(1)
return
end
-- don't insert closing quote if we have a non-even number on this line
local line = self.doc:get_selection()
if text == mapping and count_char(self.doc.lines[line], text) % 2 == 1 then
return on_text_input(self, text)
end
-- auto insert closing bracket
if mapping and (chr:find("%s") or is_closer(chr) and chr ~= '"') then
on_text_input(self, text)
on_text_input(self, mapping)
self.doc:move_to(-1)
return
end
on_text_input(self, text)
end
local function predicate()
return getmetatable(core.active_view) == DocView
and not core.active_view.doc:has_selection()
end
command.add(predicate, {
["autoinsert:backspace"] = function()
local doc = core.active_view.doc
local l, c = doc:get_selection()
local chr = doc:get_char(l, c)
if config.autoinsert_map[doc:get_char(l, c - 1)] and is_closer(chr) then
doc:delete_to(1)
end
command.perform "doc:backspace"
end,
["autoinsert:delete-to-previous-word-start"] = function()
local doc = core.active_view.doc
local le, ce = translate.previous_word_start(doc, doc:get_selection())
while true do
local l, c = doc:get_selection()
if l == le and c == ce then
break
end
command.perform "autoinsert:backspace"
end
end,
})
keymap.add {
["backspace"] = "autoinsert:backspace",
["ctrl+backspace"] = "autoinsert:delete-to-previous-word-start",
["ctrl+shift+backspace"] = "autoinsert:delete-to-previous-word-start",
}

View file

@ -0,0 +1,35 @@
require "plugins.reflow"
local config = require "core.config"
local command = require "core.command"
local DocView = require "core.docview"
config.autowrap_files = { "%.md$", "%.txt$" }
local on_text_input = DocView.on_text_input
DocView.on_text_input = function(self, ...)
on_text_input(self, ...)
-- early-exit if the filename does not match a file type pattern
local filename = self.doc.filename or ""
local matched = false
for _, ptn in ipairs(config.autowrap_files) do
if filename:match(ptn) then
matched = true
break
end
end
if not matched then return end
-- do automatic reflow on line if we're typing at the end of the line and have
-- reached the line limit
local line, col = self.doc:get_selection()
local text = self.doc:get_text(line, 1, line, math.huge)
if #text >= config.line_limit and col > #text then
command.perform("doc:select-lines")
command.perform("reflow:reflow")
command.perform("doc:move-to-next-char")
command.perform("doc:move-to-previous-char")
end
end

View file

@ -0,0 +1,72 @@
local core = require "core"
local style = require "core.style"
local command = require "core.command"
local common = require "core.common"
local config = require "core.config"
local View = require "core.view"
config.bigclock_time_format = "%H:%M:%S"
config.bigclock_date_format = "%A, %d %B %Y"
config.bigclock_scale = 1
local ClockView = View:extend()
function ClockView:new()
ClockView.super.new(self)
self.time_text = ""
self.date_text = ""
end
function ClockView:get_name()
return "Big Clock"
end
function ClockView:update_fonts()
local size = math.floor(self.size.x * 0.15 / 15) * 15 * config.bigclock_scale
if self.font_size ~= size then
self.time_font = renderer.font.load(EXEDIR .. "/data/fonts/font.ttf", size)
self.date_font = renderer.font.load(EXEDIR .. "/data/fonts/font.ttf", size * 0.3)
self.font_size = size
collectgarbage()
end
return self.font
end
function ClockView:update()
local time_text = os.date(config.bigclock_time_format)
local date_text = os.date(config.bigclock_date_format)
if self.time_text ~= time_text or self.date_text ~= date_text then
core.redraw = true
self.time_text = time_text
self.date_text = date_text
end
ClockView.super.update(self)
end
function ClockView:draw()
self:update_fonts()
self:draw_background(style.background)
local x, y = self.position.x, self.position.y
local w, h = self.size.x, self.size.y
local _, y = common.draw_text(self.time_font, style.text, self.time_text, "center", x, y, w, h)
local th = self.date_font:get_height()
common.draw_text(self.date_font, style.dim, self.date_text, "center", x, y, w, th)
end
command.add(nil, {
["big-clock:open"] = function()
local node = core.root_view:get_active_node()
node:add_view(ClockView())
end,
})
return ClockView

View file

@ -0,0 +1,117 @@
local core = require "core"
local style = require "core.style"
local command = require "core.command"
local keymap = require "core.keymap"
local DocView = require "core.docview"
local bracket_maps = {
-- [ ] ( ) { }
{ [91] = 93, [40] = 41, [123] = 125, step = 1 },
-- ] [ ) ( } {
{ [93] = 91, [41] = 40, [125] = 123, step = -1 },
}
local function get_matching_bracket(doc, line, col, line_limit, open_byte, close_byte, step)
local end_line = line + line_limit * step
local depth = 0
while line ~= end_line do
local byte = doc.lines[line]:byte(col)
if byte == open_byte then
depth = depth + 1
elseif byte == close_byte then
depth = depth - 1
if depth == 0 then return line, col end
end
local prev_line, prev_col = line, col
line, col = doc:position_offset(line, col, step)
if line == prev_line and col == prev_col then
break
end
end
end
local state = {}
local function update_state(line_limit)
line_limit = line_limit or math.huge
-- reset if we don't have a document (eg. DocView isn't focused)
local doc = core.active_view.doc
if not doc then
state = {}
return
end
-- early exit if nothing has changed since the last call
local line, col = doc:get_selection()
local change_id = doc:get_change_id()
if state.doc == doc and state.line == line and state.col == col
and state.change_id == change_id and state.limit == line_limit then
return
end
-- find matching bracket if we're on a bracket
local line2, col2
for _, map in ipairs(bracket_maps) do
for i = 0, -1, -1 do
local line, col = doc:position_offset(line, col, i)
local open = doc.lines[line]:byte(col)
local close = map[open]
if close then
line2, col2 = get_matching_bracket(doc, line, col, line_limit, open, close, map.step)
goto found
end
end
end
::found::
-- update
state = {
change_id = change_id,
doc = doc,
line = line,
col = col,
line2 = line2,
col2 = col2,
limit = line_limit,
}
end
local update = DocView.update
function DocView:update(...)
update(self, ...)
update_state(100)
end
local draw_line_text = DocView.draw_line_text
function DocView:draw_line_text(idx, x, y)
draw_line_text(self, idx, x, y)
if self.doc == state.doc and idx == state.line2 then
local color = style.bracketmatch_color or style.syntax["function"]
local x1 = x + self:get_col_x_offset(idx, state.col2)
local x2 = x + self:get_col_x_offset(idx, state.col2 + 1)
local h = math.ceil(1 * SCALE)
renderer.draw_rect(x1, y + self:get_line_height() - h, x2 - x1, h, color)
end
end
command.add("core.docview", {
["bracket-match:move-to-matching"] = function()
update_state()
if state.line2 then
core.active_view.doc:set_selection(state.line2, state.col2)
end
end,
})
keymap.add { ["ctrl+m"] = "bracket-match:move-to-matching" }

View file

@ -0,0 +1,19 @@
local config = require "core.config"
local DocView = require "core.docview"
local draw_line_gutter = DocView.draw_line_gutter
local get_gutter_width = DocView.get_gutter_width
function DocView:draw_line_gutter(idx, x, y)
local offset = self:get_gutter_width() - get_gutter_width(self)
draw_line_gutter(self, idx, x + offset, y)
end
function DocView:get_gutter_width()
local real_gutter_width = get_gutter_width(self)
local width = real_gutter_width + self:get_font():get_width("n") * config.line_limit
return math.max((self.size.x - width) / 2, real_gutter_width)
end

View file

@ -0,0 +1,53 @@
local common = require "core.common"
local DocView = require "core.docview"
local white = { common.color "#ffffff" }
local black = { common.color "#000000" }
local tmp = {}
local function draw_color_previews(self, idx, x, y, ptn, base, nibbles)
local text = self.doc.lines[idx]
local s, e = 0, 0
while true do
s, e = text:find(ptn, e + 1)
if not s then break end
local str = text:sub(s, e)
local r, g, b = str:match(ptn)
r, g, b = tonumber(r, base), tonumber(g, base), tonumber(b, base)
-- #123 becomes #112233
if nibbles then
r = r * 16
g = g * 16
b = b * 16
end
local x1 = x + self:get_col_x_offset(idx, s)
local x2 = x + self:get_col_x_offset(idx, e + 1)
local oy = self:get_line_text_y_offset()
local text_color = math.max(r, g, b) < 128 and white or black
tmp[1], tmp[2], tmp[3] = r, g, b
local l1, _, l2, _ = self.doc:get_selection(true)
if not (self.doc:has_selection() and idx >= l1 and idx <= l2) then
renderer.draw_rect(x1, y, x2 - x1, self:get_line_height(), tmp)
renderer.draw_text(self:get_font(), str, x1, y + oy, text_color)
end
end
end
local draw_line_text = DocView.draw_line_text
function DocView:draw_line_text(idx, x, y)
draw_line_text(self, idx, x, y)
draw_color_previews(self, idx, x, y, "#(%x%x)(%x%x)(%x%x)%f[%W]", 16)
draw_color_previews(self, idx, x, y, "#(%x)(%x)(%x)%f[%W]", 16, true) -- support #fff css format
draw_color_previews(self, idx, x, y, "rgba?%((%d+)%D+(%d+)%D+(%d+).-%)", 10)
end

View file

@ -0,0 +1,17 @@
local core = require "core"
local command = require "core.command"
local config = require "core.config"
command.add("core.docview", {
["copy-file-location:copy-file-location"] = function()
local doc = core.active_view.doc
if not doc.filename then
core.error "Cannot copy location of unsaved doc"
return
end
local filename = system.absolute_path(doc.filename)
core.log("Copying to clipboard \"%s\"", filename)
system.set_clipboard(filename)
end
})

View file

@ -0,0 +1,60 @@
local core = require "core"
local config = require "core.config"
local command = require "core.command"
--[[
Date and time format placeholders
from https://www.lua.org/pil/22.1.html
%a abbreviated weekday name (e.g., Wed)
%A full weekday name (e.g., Wednesday)
%b abbreviated month name (e.g., Sep)
%B full month name (e.g., September)
%c date and time (e.g., 09/16/98 23:48:10)
%d day of the month (16) [01-31]
%H hour, using a 24-hour clock (23) [00-23]
%I hour, using a 12-hour clock (11) [01-12]
%M minute (48) [00-59]
%m month (09) [01-12]
%p either "am" or "pm" (pm)
%S second (10) [00-61]
%w weekday (3) [0-6 = Sunday-Saturday]
%x date (e.g., 09/16/98)
%X time (e.g., 23:48:10)
%Y full year (1998)
%y two-digit year (98) [00-99]
%% the character `%´
--]]
config.datetimestamps_format_datestamp = "%Y%m%d"
config.datetimestamps_format_datetimestamp = "%Y%m%d_%H%M%S"
config.datetimestamps_format_timestamp = "%H%M%S"
local function datestamp()
local sOut = os.date(config.datetimestamps_format_datestamp)
core.active_view.doc:text_input(sOut)
end
local function datetimestamp()
local sOut = os.date(config.datetimestamps_format_datetimestamp)
core.active_view.doc:text_input(sOut)
end
local function timestamp()
local sOut = os.date(config.datetimestamps_format_timestamp)
core.active_view.doc:text_input(sOut)
end
command.add("core.docview", {
["datetimestamps:insert-datestamp"] = datestamp,
["datetimestamps:insert-timestamp"] = timestamp,
["datetimestamps:insert-datetimestamp"] = datetimestamp
})

View file

@ -0,0 +1,64 @@
local core = require "core"
local command = require "core.command"
local config = require "core.config"
local DocView = require "core.docview"
local Doc = require "core.doc"
local cache = setmetatable({}, { __mode = "k" })
local function detect_indent(doc)
for _, text in ipairs(doc.lines) do
local str = text:match("^ +")
if str then return "soft", #str end
local str = text:match("^\t+")
if str then return "hard" end
end
end
local function update_cache(doc)
local type, size = detect_indent(doc)
if type then
cache[doc] = { type = type, size = size }
end
end
local new = Doc.new
function Doc:new(...)
new(self, ...)
update_cache(self)
end
local clean = Doc.clean
function Doc:clean(...)
clean(self, ...)
update_cache(self)
end
local function with_indent_override(doc, fn, ...)
local c = cache[doc]
if not c then
return fn(...)
end
local type, size = config.tab_type, config.indent_size
config.tab_type, config.indent_size = c.type, c.size or config.indent_size
local r1, r2, r3 = fn(...)
config.tab_type, config.indent_size = type, size
return r1, r2, r3
end
local perform = command.perform
function command.perform(...)
return with_indent_override(core.active_view.doc, perform, ...)
end
local draw = DocView.draw
function DocView:draw(...)
return with_indent_override(self.doc, draw, self, ...)
end

View file

@ -0,0 +1,112 @@
--[[
dragdropselected.lua
provides basic drag and drop of selected text (in same document)
version: 20200627_133351
originally by SwissalpS
TODO: use OS drag and drop events
TODO: change mouse cursor when duplicating
TODO: add dragging image
--]]
local DocView = require "core.docview"
local core = require "core"
local keymap = require "core.keymap"
-- helper function for on_mouse_pressed to determine if mouse down is in selection
-- iLine is line number where mouse down happened
-- iCol is column where mouse down happened
-- iSelLine1 is line number where selection starts
-- iSelCol1 is column where selection starts
-- iSelLine2 is line number where selection ends
-- iSelCol2 is column where selection ends
local function isInSelection(iLine, iCol, iSelLine1, iSelCol1, iSelLine2, iSelCol2)
if iLine < iSelLine1 then return false end
if iLine > iSelLine2 then return false end
if (iLine == iSelLine1) and (iCol < iSelCol1) then return false end
if (iLine == iSelLine2) and (iCol > iSelCol2) then return false end
return true
end -- isInSelection
-- override DocView:on_mouse_moved
local on_mouse_moved = DocView.on_mouse_moved
function DocView:on_mouse_moved(x, y, ...)
local sCursor = nil
-- make sure we only act if previously on_mouse_pressed was in selection
if self.bClickedIntoSelection then
-- show that we are dragging something
sCursor = 'hand'
-- check for modifier to duplicate
-- (may want to set a flag as this only needs to be done once)
-- TODO: make image to drag with and/or hand over to OS dnd event
if not keymap.modkeys['ctrl'] then
-- TODO: maybe check if moved at all and only delete then or
-- as some editors do, only when dropped. I do like it going
-- instantly as that reduces the travel-distance.
self.doc:delete_to(0)
--sCursor = 'arrowWithPlus' -- 'handWithPlus'
end
-- calculate line and column for current mouse position
local iLine, iCol = self:resolve_screen_position(x, y)
-- move text cursor
self.doc:set_selection(iLine, iCol)
-- update scroll position
self:scroll_to_line(iLine, true)
end -- if previously clicked into selection
-- hand off to 'old' on_mouse_moved()
on_mouse_moved(self, x, y, ...)
-- override cursor as needed
if sCursor then self.cursor = sCursor end
end -- DocView:on_mouse_moved
-- override DocView:on_mouse_pressed
local on_mouse_pressed = DocView.on_mouse_pressed
function DocView:on_mouse_pressed(button, x, y, clicks)
-- no need to proceed if not left button or has no selection
if ('left' ~= button)
or (not self.doc:has_selection())
or (1 < clicks) then
return on_mouse_pressed(self, button, x, y, clicks)
end
-- convert pixel coordinates to line and column coordinates
local iLine, iCol = self:resolve_screen_position(x, y)
-- get selection coordinates
local iSelLine1, iSelCol1, iSelLine2, iSelCol2 = self.doc:get_selection(true)
-- set flag for on_mouse_released and on_mouse_moved() methods to detect dragging
self.bClickedIntoSelection = isInSelection(iLine, iCol, iSelLine1, iSelCol1,
iSelLine2, iSelCol2)
if self.bClickedIntoSelection then
-- stash selection for inserting later
self.sDraggedText = self.doc:get_text(self.doc:get_selection())
else
-- let 'old' on_mouse_pressed() do whatever it needs to do
on_mouse_pressed(self, button, x, y, clicks)
end
end -- DocView:on_mouse_pressed
-- override DocView:on_mouse_released()
local on_mouse_released = DocView.on_mouse_released
function DocView:on_mouse_released(button)
if self.bClickedIntoSelection then
-- insert stashed selected text at current position
self.doc:text_input(self.sDraggedText)
-- unset stash and flag(s) TODO:
self.sDraggedText = ''
self.bClickedIntoSelection = nil
end
-- hand over to old handler
on_mouse_released(self, button)
end -- DocView:on_mouse_released

View file

@ -0,0 +1,37 @@
local common = require "core.common"
local config = require "core.config"
local style = require "core.style"
local DocView = require "core.docview"
local command = require "core.command"
-- originally written by luveti
config.whitespace_map = { [" "] = "·", ["\t"] = "»" }
config.draw_whitespace = true
local draw_line_text = DocView.draw_line_text
function DocView:draw_line_text(idx, x, y)
draw_line_text(self, idx, x, y)
if not config.draw_whitespace then return end
local text = self.doc.lines[idx]
local tx, ty = x, y + self:get_line_text_y_offset()
local font = self:get_font()
local color = style.whitespace or style.syntax.comment
local map = config.whitespace_map
for chr in common.utf8_chars(text) do
local rep = map[chr]
if rep then
renderer.draw_text(font, rep, tx, ty, color)
end
tx = tx + font:get_width(chr)
end
end
command.add("core.docview", {
["draw-whitespace:toggle"] = function() config.draw_whitespace = not config.draw_whitespace end,
["draw-whitespace:disable"] = function() config.draw_whitespace = false end,
["draw-whitespace:enable"] = function() config.draw_whitespace = true end,
})

23
vendor/lite-plugins/plugins/eval.lua vendored Normal file
View file

@ -0,0 +1,23 @@
local core = require "core"
local command = require "core.command"
local function eval(str)
local fn, err = load("return " .. str)
if not fn then fn, err = load(str) end
assert(fn, err)
return tostring(fn())
end
command.add("core.docview", {
["eval:insert"] = function()
core.command_view:enter("Evaluate And Insert Result", function(cmd)
core.active_view.doc:text_input(eval(cmd))
end)
end,
["eval:replace"] = function()
core.active_view.doc:replace(eval)
end,
})

45
vendor/lite-plugins/plugins/exec.lua vendored Normal file
View file

@ -0,0 +1,45 @@
local core = require "core"
local command = require "core.command"
local function exec(cmd, keep_newline)
local fp = io.popen(cmd, "r")
local res = fp:read("*a")
fp:close()
return keep_newline and res or res:gsub("%\n$", "")
end
local function shell_quote(str)
return "'" .. str:gsub("'", "'\\''") .. "'"
end
local printfb_sub = {
["\\"] = "\\\\",
["\0"] = "\\0000",
["'"] = "'\\''",
}
local function printfb_quote(str)
return "'" .. str:gsub(".", printfb_sub) .. "'"
end
command.add("core.docview", {
["exec:insert"] = function()
core.command_view:enter("Insert Result Of Command", function(cmd)
core.active_view.doc:text_input(exec(cmd))
end)
end,
["exec:replace"] = function()
core.command_view:enter("Replace With Result Of Command", function(cmd)
core.active_view.doc:replace(function(str)
return exec(
"printf %b " .. printfb_quote(str:gsub("%\n$", "") .. "\n") .. " | eval '' " .. shell_quote(cmd),
str:find("%\n$")
)
end)
end)
end,
})

View file

@ -0,0 +1,73 @@
local core = require "core"
local command = require "core.command"
local keymap = require "core.keymap"
local html = [[
<html>
<style>
body {
margin:80 auto 100 auto;
max-width: 750px;
line-height: 1.6;
font-family: Open Sans, Arial;
color: #444;
padding: 0 10px;
}
h1, h2, h3 { line-height: 1.2; padding-top: 14px; }
hr { border: 0px; border-top: 1px solid #ddd; }
code, pre { background: #f3f3f3; padding: 8px; }
code { padding: 4px; }
a { text-decoration: none; color: #0366d6; }
a:hover { text-decoration: underline; }
table { border-collapse: collapse; }
table, th, td { border: 1px solid #ddd; padding: 6px; }
</style>
<head>
<title>${title}</title>
<head>
<body>
<script>
var xhr = new XMLHttpRequest;
xhr.open("POST", "https://api.github.com/markdown/raw");
xhr.setRequestHeader("Content-Type", "text/plain");
xhr.onload = function() { document.body.innerHTML = xhr.responseText; };
xhr.send("${content}");
</script>
</body>
</html>
]]
command.add("core.docview", {
["ghmarkdown:show-preview"] = function()
local dv = core.active_view
local content = dv.doc:get_text(1, 1, math.huge, math.huge)
local esc = { ['"'] = '\\"', ["\n"] = '\\n' }
local text = html:gsub("${(.-)}", {
title = dv:get_name(),
content = content:gsub(".", esc)
})
local htmlfile = core.temp_filename(".html")
local fp = io.open(htmlfile, "w")
fp:write(text)
fp:close()
core.log("Opening markdown preview for \"%s\"", dv:get_name())
if PLATFORM == "Windows" then
system.exec("start " .. htmlfile)
else
system.exec(string.format("xdg-open %q", htmlfile))
end
core.add_thread(function()
coroutine.yield(5)
os.remove(htmlfile)
end)
end
})
keymap.add { ["ctrl+shift+m"] = "ghmarkdown:show-preview" }

View file

@ -0,0 +1,69 @@
local core = require "core"
local config = require "core.config"
local style = require "core.style"
local StatusView = require "core.statusview"
local git = {
branch = nil,
inserts = 0,
deletes = 0,
}
local function exec(cmd, wait)
local tempfile = core.temp_filename()
system.exec(string.format("%s > %q", cmd, tempfile))
coroutine.yield(wait)
local fp = io.open(tempfile)
local res = fp:read("*a")
fp:close()
os.remove(tempfile)
return res
end
core.add_thread(function()
while true do
if system.get_file_info(".git") then
-- get branch name
git.branch = exec("git rev-parse --abbrev-ref HEAD", 1):match("[^\n]*")
-- get diff
local line = exec("git diff --stat", 1):match("[^\n]*%s*$")
git.inserts = tonumber(line:match("(%d+) ins")) or 0
git.deletes = tonumber(line:match("(%d+) del")) or 0
else
git.branch = nil
end
coroutine.yield(config.project_scan_rate)
end
end)
local get_items = StatusView.get_items
function StatusView:get_items()
if not git.branch then
return get_items(self)
end
local left, right = get_items(self)
local t = {
style.dim, self.separator,
(git.inserts ~= 0 or git.deletes ~= 0) and style.accent or style.text,
git.branch,
style.dim, " ",
git.inserts ~= 0 and style.accent or style.text, "+", git.inserts,
style.dim, " / ",
git.deletes ~= 0 and style.accent or style.text, "-", git.deletes,
}
for _, item in ipairs(t) do
table.insert(right, item)
end
return left, right
end

49
vendor/lite-plugins/plugins/gofmt.lua vendored Normal file
View file

@ -0,0 +1,49 @@
local core = require "core"
local command = require "core.command"
local keymap = require "core.keymap"
local function exec(cmd)
local fp = io.popen(cmd, "r")
local res = fp:read("*a")
local success = fp:close()
return res:gsub("%\n$", ""), success
end
local function get_cmd_text(cmd, doc)
local active_filename = doc and system.absolute_path(doc.filename or "")
return exec(string.format("%s %s", cmd, active_filename))
end
local function update_doc(cmd, doc)
local text, success = get_cmd_text(cmd, doc)
if success == nil then
local err_text = "Command '%s' not found in the system"
core.error(string.format(err_text, cmd))
return
end
local sel = { doc:get_selection() }
doc:remove(1, 1, math.huge, math.huge)
doc:insert(1, 1, text)
doc:set_selection(table.unpack(sel))
end
command.add("core.docview", {
["gofmt:gofmt"] = function()
update_doc("gofmt", core.active_view.doc)
end,
["gofmt:goimports"] = function()
update_doc("goimports", core.active_view.doc)
end,
["gofmt:goreturns"] = function()
update_doc("goreturns", core.active_view.doc)
end,
})
keymap.add {
["ctrl+i"] = "gofmt:gofmt",
["ctrl+h"] = "gofmt:goimports",
["ctrl+u"] = "gofmt:goreturns",
}

View file

@ -0,0 +1,5 @@
local style = require "core.style"
local DocView = require "core.docview"
DocView.draw_line_gutter = function() end
DocView.get_gutter_width = function() return style.padding.x end

View file

@ -0,0 +1,18 @@
local command = require "core.command"
local StatusView = require "core.statusview"
local visible = false
local funcs = {
[true] = StatusView.update,
[false] = function(self) self.size.y = 0 end,
}
function StatusView:update(...)
funcs[visible](self, ...)
end
command.add(nil, {
["hide-status:toggle"] = function() visible = not visible end,
["hide-status:hide"] = function() visible = false end,
["hide-status:show"] = function() visible = true end,
})

View file

@ -0,0 +1,12 @@
local core = require "core"
local View = require "core.view"
function View:move_towards(t, k, dest)
if type(t) ~= "table" then
return self:move_towards(self, t, k, dest)
end
if t[k] ~= dest then
core.redraw = true
end
t[k] = dest
end

View file

@ -0,0 +1,45 @@
local style = require "core.style"
local config = require "core.config"
local DocView = require "core.docview"
local function get_line_spaces(doc, idx, dir)
local text = doc.lines[idx]
if not text then
return 0
end
local s, e = text:find("^%s*")
if e == #text then
return get_line_spaces(doc, idx + dir, dir)
end
local n = 0
for i = s, e do
n = n + (text:byte(i) == 9 and config.indent_size or 1)
end
return n
end
local function get_line_indent_guide_spaces(doc, idx)
if doc.lines[idx]:find("^%s*\n") then
return math.max(
get_line_spaces(doc, idx - 1, -1),
get_line_spaces(doc, idx + 1, 1))
end
return get_line_spaces(doc, idx)
end
local draw_line_text = DocView.draw_line_text
function DocView:draw_line_text(idx, x, y)
local spaces = get_line_indent_guide_spaces(self.doc, idx)
local sw = self:get_font():get_width(" ")
local w = math.ceil(1 * SCALE)
local h = self:get_line_height()
for i = 0, spaces - 1, config.indent_size do
local color = style.guide or style.selection
renderer.draw_rect(x + sw * i, y, w, h, color)
end
draw_line_text(self, idx, x, y)
end

View file

@ -0,0 +1,86 @@
local syntax = require "core.syntax"
syntax.add {
files = { "%.as$", "%.asc$" },
comment = "//",
patterns = {
{ pattern = "//.-\n", type = "comment" },
{ pattern = { "/%*", "%*/" }, type = "comment" },
{ pattern = { "#", "[^\\]\n" }, type = "comment" },
{ pattern = { '"', '"', '\\' }, type = "string" },
{ pattern = { "'", "'", '\\' }, type = "string" },
{ pattern = "-?0[xX]%x+", type = "number" },
{ pattern = "-?0[bB][0-1]+", type = "number" },
{ pattern = "-?0[oO][0-7]+", type = "number" },
{ pattern = "-?%d+[%d%.eE]*f?", type = "number" },
{ pattern = "-?%.?%d+f?", type = "number" },
{ pattern = "&inout", type = "keyword" },
{ pattern = "&in", type = "keyword" },
{ pattern = "&out", type = "keyword" },
{ pattern = "[%a_][%w_]*@", type = "keyword2" },
{ pattern = "[%-%+!~@%?:&|%^<>%*/=%%]", type = "operator" },
{ pattern = "[%a_][%w_]*%f[(]", type = "function" },
{ pattern = "[%a_][%w_]*", type = "symbol" },
},
symbols = {
-- Common
["shared"] = "keyword",
["external"] = "keyword",
["private"] = "keyword",
["protected"] = "keyword",
["const"] = "keyword",
["final"] = "keyword",
["abstract"] = "keyword",
["class"] = "keyword",
["typedef"] = "keyword",
["namespace"] = "keyword",
["interface"] = "keyword",
["import"] = "keyword",
["enum"] = "keyword",
["funcdef"] = "keyword",
["get"] = "keyword",
["set"] = "keyword",
["mixin"] = "keyword",
["void"] = "keyword2",
["int"] = "keyword2",
["int8"] = "keyword2",
["int16"] = "keyword2",
["int32"] = "keyword2",
["int64"] = "keyword2",
["uint"] = "keyword2",
["uint8"] = "keyword2",
["uint16"] = "keyword2",
["uint32"] = "keyword2",
["uint64"] = "keyword2",
["float"] = "keyword2",
["double"] = "keyword2",
["bool"] = "keyword2",
["auto"] = "keyword",
["override"] = "keyword",
["explicit"] = "keyword",
["property"] = "keyword",
["break"] = "keyword",
["continue"] = "keyword",
["return"] = "keyword",
["switch"] = "keyword",
["case"] = "keyword",
["default"] = "keyword",
["for"] = "keyword",
["while"] = "keyword",
["do"] = "keyword",
["if"] = "keyword",
["else"] = "keyword",
["try"] = "keyword",
["catch"] = "keyword",
["cast"] = "keyword",
["function"] = "keyword",
["true"] = "literal",
["false"] = "literal",
["null"] = "literal",
["is"] = "operator",
["and"] = "operator",
["or"] = "operator",
["xor"] = "operator",
},
}

View file

@ -0,0 +1,61 @@
local syntax = require "core.syntax"
-- batch syntax for lite <liqube>
-- windows batch files use caseless matching for symbols
local symtable = {
["keyword"] = {
"if", "else", "elsif", "not", "for", "do", "in",
"equ", "neq", "lss", "leq", "gtr", "geq", -- == != < <= > >=
"nul", "con", "prn", "prn", "lpt1", "com1", "com2", "com3", "com4",
"exist", "defined",
"errorlevel", "cmdextversion",
"goto", "call", "verify",
},
["function"] = {
"set", "setlocal", "endlocal", "enabledelayedexpansion",
"echo", "type",
"cd", "chdir",
"md", "mkdir",
"pause", "choice", "exit",
"del", "rd", "rmdir",
"copy", "xcopy",
"move", "ren",
"find", "findstr",
"sort", "shift", "attrib",
"cmd", "command",
"forfiles",
},
}
-- prepare a mixed symbol list
local function prepare_symbols(symtable)
local symbols = { }
for symtype, symlist in pairs(symtable) do
for _, symname in ipairs(symlist) do
symbols[symname:lower()] = symtype
symbols[symname:upper()] = symtype
end
end
return symbols
end
syntax.add {
files = { "%.bat$", "%.cmd$" },
comment = "rem",
patterns = {
{ pattern = "@echo off\n", type = "keyword" },
{ pattern = "@echo on\n", type = "keyword" },
{ pattern = "rem.-\n", type = "comment" }, -- rem comment line, rem, rem.
{ pattern = "REM.-\n", type = "comment" },
{ pattern = "%s*:[%w%-]+", type = "symbol" }, -- :labels
{ pattern = "%:%:.-\n", type = "comment" }, -- :: comment line
{ pattern = "%%%w+%%", type = "symbol" }, -- %variable%
{ pattern = "%%%%?~?[%w:]+", type = "symbol" }, -- %1, %~dpn1, %~1:2, %%i, %%~i
{ pattern = "[!=()%>&%^/\\@]", type = "operator" }, -- operators
{ pattern = "-?%.?%d+f?", type = "number" }, -- integer numbers
{ pattern = { '"', '"', '\\' }, type = "string" }, -- "strings"
{ pattern = "[%a_][%w_]*", type = "normal" },
{ pattern = ":eof", type = "keyword" }, -- not quite as intended, but ok for now
},
symbols = prepare_symbols(symtable),
}

View file

@ -0,0 +1,15 @@
local syntax = require "core.syntax"
syntax.add {
files = { "%.cmake$", "CMakeLists.txt$" },
comment = "//",
patterns = {
{ pattern = { "#", "[^\\]\n" }, type = "comment" },
{ pattern = { '"', '"', '\\' }, type = "string" },
{ pattern = { "'", "'", '\\' }, type = "string" },
{ pattern = "[%a_][%w_]*%f[(]", type = "function" },
{ pattern = "[%a_][%w_]*", type = "normal" },
{ pattern = "%${[%a_][%w_]*%}", type = "operator" },
},
symbols = {},
}

View file

@ -0,0 +1,121 @@
pcall(require, "plugins.language_c")
local syntax = require "core.syntax"
syntax.add {
files = {
"%.h$", "%.inl$", "%.cpp$", "%.cc$", "%.C$", "%.cxx$",
"%.c++$", "%.hh$", "%.H$", "%.hxx$", "%.hpp$", "%.h++$"
},
comment = "//",
patterns = {
{ pattern = "//.-\n", type = "comment" },
{ pattern = { "/%*", "%*/" }, type = "comment" },
{ pattern = { "#", "[^\\]\n" }, type = "comment" },
{ pattern = { '"', '"', '\\' }, type = "string" },
{ pattern = { "'", "'", '\\' }, type = "string" },
{ pattern = "-?0x%x+", type = "number" },
{ pattern = "-?%d+[%d%.eE]*f?", type = "number" },
{ pattern = "-?%.?%d+f?", type = "number" },
{ pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" },
{ pattern = "[%a_][%w_]*%f[(]", type = "function" },
{ pattern = "[%a_][%w_]*", type = "symbol" },
},
symbols = {
["alignof"] = "keyword",
["alignas"] = "keyword",
["and"] = "keyword",
["and_eq"] = "keyword",
["not"] = "keyword",
["not_eq"] = "keyword",
["or"] = "keyword",
["or_eq"] = "keyword",
["xor"] = "keyword",
["xor_eq"] = "keyword",
["private"] = "keyword",
["protected"] = "keyword",
["public"] = "keyword",
["register"] = "keyword",
["nullptr"] = "keyword",
["operator"] = "keyword",
["asm"] = "keyword",
["bitand"] = "keyword",
["bitor"] = "keyword",
["catch"] = "keyword",
["throw"] = "keyword",
["try"] = "keyword",
["class"] = "keyword",
["compl"] = "keyword",
["explicit"] = "keyword",
["export"] = "keyword",
["concept"] = "keyword",
["consteval"] = "keyword",
["constexpr"] = "keyword",
["constinit"] = "keyword",
["const_cast"] = "keyword",
["dynamic_cast"] = "keyword",
["reinterpret_cast"] = "keyword",
["static_cast"] = "keyword",
["static_assert"] = "keyword",
["template"] = "keyword",
["this"] = "keyword",
["thread_local"] = "keyword",
["requires"] = "keyword",
["co_wait"] = "keyword",
["co_return"] = "keyword",
["co_yield"] = "keyword",
["decltype"] = "keyword",
["delete"] = "keyword",
["export"] = "keyword",
["friend"] = "keyword",
["typeid"] = "keyword",
["typename"] = "keyword",
["mutable"] = "keyword",
["virtual"] = "keyword",
["using"] = "keyword",
["namespace"] = "keyword",
["new"] = "keyword",
["noexcept"] = "keyword",
["if"] = "keyword",
["then"] = "keyword",
["else"] = "keyword",
["elseif"] = "keyword",
["do"] = "keyword",
["while"] = "keyword",
["for"] = "keyword",
["break"] = "keyword",
["continue"] = "keyword",
["return"] = "keyword",
["goto"] = "keyword",
["struct"] = "keyword",
["union"] = "keyword",
["typedef"] = "keyword",
["enum"] = "keyword",
["extern"] = "keyword",
["static"] = "keyword",
["volatile"] = "keyword",
["const"] = "keyword",
["inline"] = "keyword",
["switch"] = "keyword",
["case"] = "keyword",
["default"] = "keyword",
["auto"] = "keyword",
["const"] = "keyword",
["void"] = "keyword",
["int"] = "keyword2",
["short"] = "keyword2",
["long"] = "keyword2",
["float"] = "keyword2",
["double"] = "keyword2",
["char"] = "keyword2",
["unsigned"] = "keyword2",
["bool"] = "keyword2",
["true"] = "keyword2",
["false"] = "keyword2",
["wchar_t"] = "keyword2",
["char8_t"] = "keyword2",
["char16_t"] = "keyword2",
["char32_t"] = "keyword2",
["NULL"] = "literal",
},
}

View file

@ -0,0 +1,112 @@
local syntax = require "core.syntax"
syntax.add {
files = "%.cs$",
comment = "//",
patterns = {
{ pattern = "//.-\n", type = "comment" },
{ pattern = { "/%*", "%*/" }, type = "comment" },
{ pattern = { '"', '"', '\\' }, type = "string" },
{ pattern = { "[%$%@]?\"", '"', '\\' }, type = "string" }, -- string interpolation and verbatim
{ pattern = "'\\x%x?%x?%x?%x'", type = "string" }, -- character hexadecimal escape sequence
{ pattern = "'\\u%x%x%x%x'", type = "string" }, -- character unicode escape sequence
{ pattern = "'\\?.'", type = "string" }, -- character literal
{ pattern = "-?0x%x+", type = "number" },
{ pattern = "-?%d+[%d%.eE]*f?", type = "number" },
{ pattern = "-?%.?%d+f?", type = "number" },
{ pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" },
{ pattern = "%?%?", type = "operator" }, -- ?? null-coalescing
{ pattern = "%?%.", type = "operator" }, -- ?. null-conditional
{ pattern = "[%a_][%w_]*%f[(]", type = "function" },
{ pattern = "[%a_][%w_]*", type = "symbol" },
},
symbols = {
-- keywords
["abstract"] = "keyword",
["as"] = "keyword",
["await"] = "keyword",
["base"] = "keyword",
["break"] = "keyword",
["case"] = "keyword",
["catch"] = "keyword",
["checked"] = "keyword",
["class"] = "keyword",
["const"] = "keyword",
["continue"] = "keyword",
["default"] = "keyword",
["delegate"] = "keyword",
["do"] = "keyword",
["else"] = "keyword",
["enum"] = "keyword",
["event"] = "keyword",
["explicit"] = "keyword",
["extern"] = "keyword",
["finally"] = "keyword",
["fixed"] = "keyword",
["for"] = "keyword",
["foreach"] = "keyword",
["get"] = "keyword",
["goto"] = "keyword",
["if"] = "keyword",
["implicit"] = "keyword",
["in"] = "keyword",
["interface"] = "keyword",
["internal"] = "keyword",
["is"] = "keyword",
["lock"] = "keyword",
["namespace"] = "keyword",
["new"] = "keyword",
["operator"] = "keyword",
["out"] = "keyword",
["override"] = "keyword",
["params"] = "keyword",
["private"] = "keyword",
["protected"] = "keyword",
["public"] = "keyword",
["readonly"] = "keyword",
["ref"] = "keyword",
["return"] = "keyword",
["sealed"] = "keyword",
["set"] = "keyword",
["sizeof"] = "keyword",
["stackalloc"] = "keyword",
["static"] = "keyword",
["struct"] = "keyword",
["switch"] = "keyword",
["this"] = "keyword",
["throw"] = "keyword",
["try"] = "keyword",
["typeof"] = "keyword",
["unchecked"] = "keyword",
["unsafe"] = "keyword",
["using"] = "keyword",
["var"] = "keyword",
["virtual"] = "keyword",
["void"] = "keyword",
["volatile"] = "keyword",
["where"] = "keyword",
["while"] = "keyword",
["yield"] = "keyword",
-- types
["bool"] = "keyword2",
["byte"] = "keyword2",
["char"] = "keyword2",
["decimal"] = "keyword2",
["double"] = "keyword2",
["float"] = "keyword2",
["int"] = "keyword2",
["long"] = "keyword2",
["object"] = "keyword2",
["sbyte"] = "keyword2",
["short"] = "keyword2",
["string"] = "keyword2",
["uint"] = "keyword2",
["ulong"] = "keyword2",
["ushort"] = "keyword2",
-- literals
["true"] = "literal",
["false"] = "literal",
["null"] = "literal",
},
}

View file

@ -0,0 +1,135 @@
local syntax = require "core.syntax"
syntax.add {
files = { "%.d$", "%.di$" },
comment = "//",
patterns = {
{ pattern = "//.-\n", type = "comment" },
{ pattern = { "/%*", "%*/" }, type = "comment" },
{ pattern = { "/%+", "%+/" }, type = "comment" },
{ pattern = { '`', '`', '\\' }, type = "string" },
{ pattern = { '"', '"', '\\' }, type = "string" },
{ pattern = { "'", "'", '\\' }, type = "string" },
{ pattern = "-?0x%x+", type = "number" },
{ pattern = "-?%d+[%d%.eE]*f?", type = "number" },
{ pattern = "-?%.?%d+f?", type = "number" },
{ pattern = "[%+%-=/%*%^%%<>!~|&%$]+", type = "operator" },
{ pattern = "[%a_][%w_]*!", type = "function" }, -- highlight templates
{ pattern = "[%a_][%w_]*", type = "symbol" },
{ pattern = "@safe", type = "keyword" },
{ pattern = "@trusted", type = "keyword" },
{ pattern = "@nogc", type = "keyword" },
},
symbols = {
["abstract"] = "keyword",
["alias"] = "keyword",
["align"] = "keyword",
["asm"] = "keyword",
["assert"] = "keyword",
["auto"] = "keyword",
["body"] = "keyword",
["bool"] = "keyword2",
["break"] = "keyword",
["byte"] = "keyword2",
["case"] = "keyword",
["cast"] = "keyword",
["catch"] = "keyword",
["cdouble"] = "keyword2",
["cent"] = "keyword2",
["cfloat"] = "keyword2",
["char"] = "keyword2",
["class"] = "keyword",
["const"] = "keyword",
["continue"] = "keyword",
["creal"] = "keyword2",
["dchar"] = "keyword2",
["debug"] = "keyword",
["default"] = "keyword",
["delegate"] = "keyword",
["deprecated"] = "keyword",
["do"] = "keyword",
["double"] = "keyword2",
["else"] = "keyword",
["enum"] = "keyword",
["export"] = "keyword",
["extern"] = "keyword",
["false"] = "literal",
["final"] = "keyword",
["finally"] = "keyword",
["float"] = "keyword2",
["for"] = "keyword",
["foreach"] = "keyword",
["foreach_reverse"] = "keyword",
["function"] = "keyword",
["goto"] = "keyword",
["idouble"] = "keyword2",
["if"] = "keyword",
["ifloat"] = "keyword2",
["immutable"] = "keyword",
["import"] = "keyword",
["in"] = "keyword",
["inout"] = "keyword",
["int"] = "keyword2",
["interface"] = "keyword",
["invariant"] = "keyword",
["ireal"] = "keyword2",
["is"] = "keyword",
["lazy"] = "keyword",
["long"] = "keyword2",
["macro"] = "keyword",
["mixin"] = "keyword",
["module"] = "keyword",
["new"] = "keyword",
["nothrow"] = "keyword",
["null"] = "literal",
["out"] = "keyword",
["override"] = "keyword",
["package"] = "keyword",
["pragma"] = "keyword",
["private"] = "keyword",
["protected"] = "keyword",
["public"] = "keyword",
["pure"] = "keyword",
["real"] = "keyword2",
["ref"] = "keyword",
["return"] = "keyword",
["scope"] = "keyword",
["shared"] = "keyword",
["short"] = "keyword2",
["static"] = "keyword",
["struct"] = "keyword",
["super"] = "keyword",
["switch"] = "keyword",
["synchronized"] = "keyword",
["template"] = "keyword",
["this"] = "keyword",
["throw"] = "keyword",
["true"] = "literal",
["try"] = "keyword",
["typeid"] = "keyword",
["typeof"] = "keyword",
["ubyte"] = "keyword2",
["ucent"] = "keyword2",
["uint"] = "keyword2",
["ulong"] = "keyword2",
["union"] = "keyword",
["unittest"] = "keyword",
["ushort"] = "keyword2",
["version"] = "keyword",
["void"] = "keyword",
["wchar"] = "keyword2",
["while"] = "keyword",
["with"] = "keyword",
["__FILE__"] = "keyword",
["__FILE_FULL_PATH__"] = "keyword",
["__MODULE__"] = "keyword",
["__LINE__"] = "keyword",
["__FUNCTION__"] = "keyword",
["__PRETTY_FUNCTION__"] = "keyword",
["__gshared"] = "keyword",
["__traits"] = "keyword",
["__vector"] = "keyword",
["__parameters"] = "keyword",
},
}

View file

@ -0,0 +1,92 @@
local syntax = require "core.syntax"
syntax.add {
files = { "%.ex$", "%.exs$"},
comment = "#",
patterns = {
{ pattern = "#.*\n", type = "comment" },
{ pattern = { ':"', '"', '\\' }, type = "number" },
{ pattern = { '"""', '"""', '\\' }, type = "string" },
{ pattern = { '"', '"', '\\' }, type = "string" },
{ pattern = { "'", "'", '\\' }, type = "string" },
{ pattern = { '~%a[/"|\'%(%[%{<]', '[/"|\'%)%]%}>]', '\\' }, type = "string"},
{ pattern = "-?0x%x+", type = "number" },
{ pattern = "-?%d+[%d%.eE]*f?", type = "number" },
{ pattern = "-?%.?%d+f?", type = "number" },
{ pattern = ':"?[%a_][%w_]*"?', type = "number" },
{ pattern = "[%a][%w_!?]*%f[(]", type = "function" },
{ pattern = "%u%w+", type = "normal" },
{ pattern = "@[%a_][%w_]*", type = "keyword2" },
{ pattern = "_%a[%w_]*", type = "keyword2" },
{ pattern = "[%+%-=/%*<>!|&]", type = "operator" },
{ pattern = "[%a_][%w_]*", type = "symbol" },
},
symbols = {
["def"] = "keyword",
["defp"] = "keyword",
["defguard"] = "keyword",
["defguardp"] = "keyword",
["defmodule"] = "keyword",
["defprotocol"] = "keyword",
["defimpl"] = "keyword",
["defrecord"] = "keyword",
["defrecordp"] = "keyword",
["defmacro"] = "keyword",
["defmacrop"] = "keyword",
["defdelegate"] = "keyword",
["defoverridable"] = "keyword",
["defexception"] = "keyword",
["defcallback"] = "keyword",
["defstruct"] = "keyword",
["for"] = "keyword",
["case"] = "keyword",
["when"] = "keyword",
["with"] = "keyword",
["cond"] = "keyword",
["if"] = "keyword",
["unless"] = "keyword",
["try"] = "keyword",
["receive"] = "keyword",
["after"] = "keyword",
["raise"] = "keyword",
["rescue"] = "keyword",
["catch"] = "keyword",
["else"] = "keyword",
["quote"] = "keyword",
["unquote"] = "keyword",
["super"] = "keyword",
["unquote_splicing"] = "keyword",
["do"] = "keyword",
["end"] = "keyword",
["fn"] = "keyword",
["import"] = "keyword2",
["alias"] = "keyword2",
["use"] = "keyword2",
["require"] = "keyword2",
["and"] = "operator",
["or"] = "operator",
["true"] = "literal",
["false"] = "literal",
["nil"] = "literal",
},
}
syntax.add {
files = { "%.l?eex$" },
patterns = {
{ pattern = { "<!%-%-", "%-%->" }, type = "comment" },
{ pattern = { '%f[^>][^<]', '%f[<]' }, type = "normal" },
{ pattern = { '<%%=?', '%%>' }, type = "normal" },
{ pattern = { '"', '"', '\\' }, type = "string" },
{ pattern = { "'", "'", '\\' }, type = "string" },
{ pattern = "0x[%da-fA-F]+", type = "number" },
{ pattern = "-?%d+[%d%.]*f?", type = "number" },
{ pattern = "-?%.?%d+f?", type = "number" },
{ pattern = "%f[^<]![%a_][%w_]*", type = "keyword2" },
{ pattern = "%f[^<][%a_][%w_]*", type = "function" },
{ pattern = "%f[^<]/[%a_][%w_]*", type = "function" },
{ pattern = "[%a_][%w_]*", type = "keyword" },
{ pattern = "[/<>=]", type = "operator" },
},
symbols = {},
}

View file

@ -0,0 +1,47 @@
local syntax = require "core.syntax"
syntax.add {
files = { "%.elm$" },
comment = "%-%-",
patterns = {
{ pattern = {"%-%-", "\n"}, type = "comment" },
{ pattern = { "{%-", "%-}" }, type = "comment" },
{ pattern = { '"', '"', '\\' }, type = "string" },
{ pattern = { '"""', '"""', '\\' }, type = "string" },
{ pattern = { "'", "'", '\\' }, type = "string" },
{ pattern = "-?0x%x+", type = "number" },
{ pattern = "-?%d+[%d%.eE]*f?", type = "number" },
{ pattern = "-?%.?%d+f?", type = "number" },
{ pattern = "%.%.", type = "operator" },
{ pattern = "[=:|&<>%+%-%*\\/%^%%]", type = "operator" },
{ pattern = "[%a_'][%w_']*", type = "symbol" },
},
symbols = {
["as"] = "keyword",
["case"] = "keyword",
["of"] = "keyword",
["if"] = "keyword",
["then"] = "keyword",
["else"] = "keyword",
["import"] = "keyword",
["module"] = "keyword",
["exposing"] = "keyword",
["let"] = "keyword",
["in"] = "keyword",
["type"] = "keyword",
["alias"] = "keyword",
["port"] = "keyword",
["and"] = "keyword",
["or"] = "keyword",
["xor"] = "keyword",
["not"] = "keyword",
["number"] = "keyword2",
["Bool"] = "keyword2",
["Char"] = "keyword2",
["Float"] = "keyword2",
["Int"] = "keyword2",
["String"] = "keyword2",
["True"] = "literal",
["False"] = "literal",
},
}

View file

@ -0,0 +1,33 @@
local syntax = require "core.syntax"
syntax.add {
files = "%.fe$",
comment = ";",
patterns = {
{ pattern = ";.-\n", type = "comment" },
{ pattern = { '"', '"', '\\' }, type = "string" },
{ pattern = "0x[%da-fA-F]+", type = "number" },
{ pattern = "-?%d+[%d%.]*", type = "number" },
{ pattern = "-?%.?%d+", type = "number" },
{ pattern = "'", type = "symbol" },
{ pattern = "%f[^(][^()'%s\"]+", type = "function" },
{ pattern = "[^()'%s\"]+", type = "symbol" },
},
symbols = {
["if"] = "keyword2",
["let"] = "keyword2",
["do"] = "keyword2",
["fn"] = "keyword2",
["mac"] = "keyword2",
["'"] = "keyword2",
["print"] = "keyword",
["while"] = "keyword",
["car"] = "keyword",
["cdr"] = "keyword",
["not"] = "keyword",
["setcdr"] = "keyword",
["setcar"] = "keyword",
["nil"] = "literal",
["t"] = "literal",
}
}

View file

@ -0,0 +1,100 @@
-- Support for the Fennel programming language: https://fennel-lang.org
-- Covers all the keywords up to Fennel version 0.4.0
-- Currently only covers highlighting, not indentation, delimiter
-- matching, or evaluation.
local syntax = require "core.syntax"
syntax.add {
files = "%.fnl$",
comment = ";",
patterns = {
{ pattern = ";.-\n", type = "comment" },
{ pattern = { '"', '"', '\\' }, type = "string" },
{ pattern = "0x[%da-fA-F]+", type = "number" },
{ pattern = "-?%d+[%d%.]*", type = "number" },
{ pattern = "-?%.?%d+", type = "number" },
{ pattern = "%f[^(][^()'%s\"]+", type = "function" },
{ pattern = "[^()'%s\"]+", type = "symbol" },
},
symbols = {
["eval-compiler"] = "keyword2",
["doc"] = "keyword2",
["lua"] = "keyword2",
["hashfn"] = "keyword2",
["macro"] = "keyword2",
["macros"] = "keyword2",
["import-macros"] = "keyword2",
["do"] = "keyword2",
["values"] = "keyword2",
["if"] = "keyword2",
["when"] = "keyword2",
["each"] = "keyword2",
["for"] = "keyword2",
["fn"] = "keyword2",
["lambda"] = "keyword2",
["λ"] = "keyword2",
["partial"] = "keyword2",
["while"] = "keyword2",
["set"] = "keyword2",
["global"] = "keyword2",
["var"] = "keyword2",
["local"] = "keyword2",
["let"] = "keyword2",
["tset"] = "keyword2",
["set-forcibly!"] = "keyword2",
["doto"] = "keyword2",
["match"] = "keyword2",
["or"] = "keyword2",
["and"] = "keyword2",
["not"] = "keyword2",
["not="] = "keyword2",
["pick-args"] = "keyword2",
["pick-values"] = "keyword2",
["macrodebug"] = "keyword2",
["."] = "keyword",
["+"] = "keyword",
[".."] = "keyword",
["^"] = "keyword",
["-"] = "keyword",
["*"] = "keyword",
["%"] = "keyword",
["/"] = "keyword",
[">"] = "keyword",
["<"] = "keyword",
[">="] = "keyword",
["<="] = "keyword",
["="] = "keyword",
["#"] = "keyword",
["..."] = "keyword",
[":"] = "keyword",
["->"] = "keyword",
["->>"] = "keyword",
["-?>"] = "keyword",
["-?>>"] = "keyword",
["$"] = "keyword",
["$1"] = "keyword",
["$2"] = "keyword",
["$3"] = "keyword",
["$4"] = "keyword",
["$5"] = "keyword",
["$6"] = "keyword",
["$7"] = "keyword",
["$8"] = "keyword",
["$9"] = "keyword",
["lshift"] = "keyword",
["rshift"] = "keyword",
["bor"] = "keyword",
["band"] = "keyword",
["bnot"] = "keyword",
["bxor"] = "keyword",
["nil"] = "literal",
["true"] = "literal",
["false"] = "literal",
}
}

View file

@ -0,0 +1,99 @@
-- Support for the GDScript programming language: https://godotengine.org/
-- Covers the most used keywords up to Godot version 3.2.x
local syntax = require "core.syntax"
syntax.add {
files = { "%.gd$" },
comment = "#",
patterns = {
{ pattern = "#.-\n", type = "comment" },
{ pattern = { '"', '"', '\\' }, type = "string" },
{ pattern = { "'", "'", '\\' }, type = "string" },
{ pattern = "-?0x%x*", type = "number" },
{ pattern = "-?%d+[%d%.e]*", type = "number" },
{ pattern = "-?%.?%d+", type = "number" },
{ pattern = "[%+%:%-=/%*%^%%<>!~|&]", type = "operator" },
{ pattern = "[%a_][%w_]*%f[(]", type = "function" },
{ pattern = "[%a_][%w_]*", type = "symbol" },
},
symbols = {
-- keywords
["if"] = "keyword",
["elif"] = "keyword",
["else"] = "keyword",
["for"] = "keyword",
["while"] = "keyword",
["match"] = "keyword",
["break"] = "keyword",
["continue"] = "keyword",
["pass"] = "keyword",
["return"] = "keyword",
["class"] = "keyword",
["class_name"] = "keyword",
["extends"] = "keyword",
["is"] = "keyword",
["in"] = "keyword",
["as"] = "keyword",
["and"] = "keyword",
["or"] = "keyword",
["not"] = "keyword",
["self"] = "keyword",
["tool"] = "keyword",
["signal"] = "keyword",
["func"] = "keyword",
["static"] = "keyword",
["const"] = "keyword",
["enum"] = "keyword",
["var"] = "keyword",
["onready"] = "keyword",
["export"] = "keyword",
["setget"] = "keyword",
["breakpoint"] = "keyword",
["preload"] = "keyword",
["yield"] = "keyword",
["assert"] = "keyword",
["remote"] = "keyword",
["master"] = "keyword",
["puppet"] = "keyword",
["remotesync"] = "keyword",
["mastersync"] = "keyword",
["puppetsync"] = "keyword",
-- types
["void"] = "keyword2",
["int"] = "keyword2",
["float"] = "keyword2",
["bool"] = "keyword2",
["String"] = "keyword2",
["Vector2"] = "keyword2",
["Rect2"] = "keyword2",
["Vector3"] = "keyword2",
["Transform2D"] = "keyword2",
["Plane"] = "keyword2",
["Quat"] = "keyword2",
["AABB"] = "keyword2",
["Basis"] = "keyword2",
["Transform"] = "keyword2",
["Color"] = "keyword2",
["NodePath"] = "keyword2",
["RID"] = "keyword2",
["Object"] = "keyword2",
["Array"] = "keyword2",
["PoolByteArray"] = "keyword2",
["PoolIntArray"] = "keyword2",
["PoolRealArray"] = "keyword2",
["PoolStringArray"] = "keyword2",
["PoolVector2Array"] = "keyword2",
["PoolVector3Array"] = "keyword2",
["PoolColorArray"] = "keyword2",
["Dictionary"] = "keyword2",
-- literals
["null"] = "literal",
["true"] = "literal",
["false"] = "literal",
["PI"] = "literal",
["TAU"] = "literal",
["INF"] = "literal",
["NAN"] = "literal",
},
}

View file

@ -0,0 +1,387 @@
local style = require "core.style"
local common = require "core.common"
local syntax = require "core.syntax"
syntax.add {
files = { "%.glsl$", "%.frag$", "%.vert$", },
comment = "//",
patterns = {
{ pattern = "//.-\n", type = "comment" },
{ pattern = { "/%*", "%*/" }, type = "comment" },
{ pattern = { "#", "[^\\]\n" }, type = "comment" },
{ pattern = { '"', '"', '\\' }, type = "string" },
{ pattern = { "'", "'", '\\' }, type = "string" },
{ pattern = "-?0x%x+", type = "number" },
{ pattern = "-?%d+[%d%.eE]*f?", type = "number" },
{ pattern = "-?%.?%d+f?", type = "number" },
{ pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" },
{ pattern = "ivec[2-4]", type = "keyword2" },
{ pattern = "bvec[2-4]", type = "keyword2" },
{ pattern = "uvec[2-4]", type = "keyword2" },
{ pattern = "vec[2-4]", type = "keyword2" },
{ pattern = "dmat[2-4]x[2-4]", type = "keyword2" },
{ pattern = "dmat[2-4]", type = "keyword2" },
{ pattern = "mat[2-4]x[2-4]", type = "keyword2" },
{ pattern = "mat[2-4]", type = "keyword2" },
{ pattern = "[%a_][%w_]*%f[(]", type = "function" },
{ pattern = "[%a_][%w_]*", type = "symbol" },
},
symbols = {
--https://www.khronos.org/registry/OpenGL/specs/gl/GLSLangSpec.4.60.pdf
--The symbols are added here in the order they appear in the spec
["if"] = "keyword",
["else"] = "keyword",
["do"] = "keyword",
["while"] = "keyword",
["for"] = "keyword",
["break"] = "keyword",
["continue"] = "keyword",
["return"] = "keyword",
["const"] = "keyword",
["switch"] = "keyword",
["case"] = "keyword",
["default"] = "keyword",
["const"] = "keyword",
["void"] = "keyword",
["bool"] = "keyword2",
["int"] = "keyword2",
["uint"] = "keyword2",
["float"] = "keyword2",
["double"] = "keyword2",
["true"] = "literal",
["false"] = "literal",
["NULL"] = "literal",
["attribute"] = "keyword",
["varying"] = "keyword",
["uniform"] = "keyword",
["buffer"] = "keyword",
["shared"] = "keyword",
["layout"] = "keyword",
["centroid"] = "keyword",
["flat"] = "keyword",
["smooth"] = "keyword",
["noperspective"]= "keyword",
["patch"] = "keyword",
["sample"] = "keyword",
["in"] = "keyword",
["out"] = "keyword",
["inout"] = "keyword",
["invariant"] = "keyword",
["precise"] = "keyword",
["lowp"] = "keyword",
["mediump"] = "keyword",
["highp"] = "keyword",
["precision"] = "keyword",
["struct"] = "keyword",
["subroutine"] = "keyword",
["coherent"] = "keyword",
["volatile"] = "keyword",
["readonly"] = "keyword",
["writeonly"] = "keyword",
["sampler1D"] = "keyword2",
["sampler2D"] = "keyword2",
["sampler3D"] = "keyword2",
["samplerCube"] = "keyword2",
["sampler1DShadow"] = "keyword2",
["sampler2DShadow"] = "keyword2",
["samplerCubeShadow"] = "keyword2",
["sampler1DArray"] = "keyword2",
["sampler2DArray"] = "keyword2",
["samplerCubeArray"] = "keyword2",
["sampler1DArrayShadow"] = "keyword2",
["sampler2DArrayShadow"] = "keyword2",
["samplerCubeArrayShadow"]= "keyword2",
["isampler1D"] = "keyword2",
["isampler2D"] = "keyword2",
["isampler3D"] = "keyword2",
["isamplerCube"] = "keyword2",
["sampler2DMS"] = "keyword2",
["isampler2DMS"] = "keyword2",
["usampler2DMS"] = "keyword2",
["sampler2DMSArray"] = "keyword2",
["isampler2DMSArray"] = "keyword2",
["usampler2DMSArray"] = "keyword2",
["isampler1DArray"] = "keyword2",
["isampler2DArray"] = "keyword2",
["usampler1D"] = "keyword2",
["usampler2D"] = "keyword2",
["usampler3D"] = "keyword2",
["usamplerCube"] = "keyword2",
["usampler1DArray"] = "keyword2",
["usampler2DArray"] = "keyword2",
["sampler2DRect"] = "keyword2",
["sampler2DRectShadow"] = "keyword2",
["isampler2DRect"] = "keyword2",
["usampler2DRect"] = "keyword2",
["samplerBuffer"] = "keyword2",
["isamplerBuffer"] = "keyword2",
["usamplerBuffer"] = "keyword2",
["image1D"] = "keyword2",
["iimage1D"] = "keyword2",
["uimage1D"] = "keyword2",
["image1DArray"] = "keyword2",
["iimage1DArray"] = "keyword2",
["uimage1DArray"] = "keyword2",
["image2D"] = "keyword2",
["iimage2D"] = "keyword2",
["uimage2D"] = "keyword2",
["image2DArray"] = "keyword2",
["iimage2DArray"] = "keyword2",
["uimage2DArray"] = "keyword2",
["image2DRect"] = "keyword2",
["iimage2DRect"] = "keyword2",
["uimage2DRect"] = "keyword2",
["image2DMS"] = "keyword2",
["iimage2DMS"] = "keyword2",
["uimage2DMS"] = "keyword2",
["image2DMSArray"] = "keyword2",
["iimage2DMSArray"]= "keyword2",
["uimage2DMSArray"]= "keyword2",
["image3D"] = "keyword2",
["iimage3D"] = "keyword2",
["uimage3D"] = "keyword2",
["imageCube"] = "keyword2",
["iimageCube"] = "keyword2",
["uimageCube"] = "keyword2",
["imageCubeArray"] = "keyword2",
["iimageCubeArray"]= "keyword2",
["uimageCubeArray"]= "keyword2",
["imageBuffer"] = "keyword2",
["iimageBuffer"] = "keyword2",
["uimageBuffer"] = "keyword2",
["atomic_uint"] = "keyword2",
["radians"] = "keyword",
["degrees"] = "keyword",
["sin"] = "keyword",
["cos"] = "keyword",
["tan"] = "keyword",
["asin"] = "keyword",
["acos"] = "keyword",
["atan"] = "keyword",
["sinh"] = "keyword",
["cosh"] = "keyword",
["tanh"] = "keyword",
["asinh"] = "keyword",
["acosh"] = "keyword",
["pow"] = "keyword",
["exp"] = "keyword",
["exp2"] = "keyword",
["log2"] = "keyword",
["sqrt"] = "keyword",
["inversesqrt"] = "keyword",
["abs"] = "keyword",
["sign"] = "keyword",
["floor"] = "keyword",
["trunc"] = "keyword",
["round"] = "keyword",
["roundEven"] = "keyword",
["ceil"] = "keyword",
["fract"] = "keyword",
["mod"] = "keyword",
["modf"] = "keyword",
["min"] = "keyword",
["max"] = "keyword",
["clamp"] = "keyword",
["mix"] = "keyword",
["step"] = "keyword",
["smoothstep"] = "keyword",
["isnan"] = "keyword",
["isinf"] = "keyword",
["floatBitsToInt"] = "keyword",
["floatBitsToUint"] = "keyword",
["intBitsToFloat"] = "keyword",
["uintBitsToFloat"] = "keyword",
["fma"] = "keyword",
["frexp"] = "keyword",
["ldexp"] = "keyword",
["packUnorm2x16"] = "keyword",
["packSnorm2x16"] = "keyword",
["packUnorm4x8"] = "keyword",
["packSnorm4x8"] = "keyword",
["unpackUnorm2x16"] = "keyword",
["unpackSnorm2x16"] = "keyword",
["unpackUnorm4x8"] = "keyword",
["unpackSnorm4x8"] = "keyword",
["packHalf2x16"] = "keyword",
["unpackHalf2x16"] = "keyword",
["packDouble2x32"] = "keyword",
["unpackDouble2x32"] = "keyword",
["length"] = "keyword",
["distance"] = "keyword",
["dot"] = "keyword",
["cross"] = "keyword",
["normalize"] = "keyword",
["ftransform"] = "keyword",
["faceforward"] = "keyword",
["reflect"] = "keyword",
["refract"] = "keyword",
["matrixCompMult"] = "keyword",
["outerProduct"] = "keyword",
["transpose"] = "keyword",
["determinant"] = "keyword",
["inverse"] = "keyword",
["lessThan"] = "keyword",
["lessThanEqual"] = "keyword",
["greaterThan"] = "keyword",
["greaterThanEqual"] = "keyword",
["equal"] = "keyword",
["notEqual"] = "keyword",
["any"] = "keyword",
["all"] = "keyword",
["not"] = "keyword",
["uaddCarry"] = "keyword",
["usubBorrow"] = "keyword",
["umulExtended"] = "keyword",
["imulExtended"] = "keyword",
["bitfieldExtract"] = "keyword",
["bitfieldInsert"] = "keyword",
["bitfieldReverse"] = "keyword",
["bitCount"] = "keyword",
["findLSB"] = "keyword",
["findMSB"] = "keyword",
["textureSize"] = "keyword",
["textureQueryLod"] = "keyword",
["textureQueryLevels"] = "keyword",
["textureSamples"] = "keyword",
["texture"] = "keyword",
["textureProj"] = "keyword",
["textureLod"] = "keyword",
["textureOffset"] = "keyword",
["texelFetch"] = "keyword",
["texelFetchOffset"] = "keyword",
["textureProjOffset"] = "keyword",
["textureLodOffset"] = "keyword",
["textureProjLod"] = "keyword",
["textureProjLodOffset"] = "keyword",
["textureGrad"] = "keyword",
["textureGradOffset"] = "keyword",
["textureProjGrad"] = "keyword",
["textureProjGradOffset"]= "keyword",
["textureGather"] = "keyword",
["textureGatherOffset"] = "keyword",
["textureGatherOffsets"] = "keyword",
--Atomic Counter Functions
["atomicCounterIncrement"]= "keyword",
["atomicCounterDecrement"]= "keyword",
["atomicCounter"] = "keyword",
["atomicCounterAdd"] = "keyword",
["atomicCounterSubtract"] = "keyword",
["atomicCounterMin"] = "keyword",
["atomicCounterMax"] = "keyword",
["atomicCounterAnd"] = "keyword",
["atomicCounterOr"] = "keyword",
["atomicCounterXor"] = "keyword",
["atomicCounterExchange"] = "keyword",
["atomicCounterCompSwap"] = "keyword",
--Atomic Memory Functions
["atomicAdd"] = "keyword",
["atomicMin"] = "keyword",
["atomicMax"] = "keyword",
["atomicAnd"] = "keyword",
["atomicOr"] = "keyword",
["atomicXor"] = "keyword",
["atomicExchange"]= "keyword",
["atomicCompSwap"]= "keyword",
--Image Functions
["imageSize"] = "keyword",
["imageSamples"] = "keyword",
["imageLoad"] = "keyword",
["imageStore"] = "keyword",
["imageAtomicAdd"] = "keyword",
["imageAtomicMin"] = "keyword",
["imageAtomicMax"] = "keyword",
["imageAtomicAnd"] = "keyword",
["imageAtomicOr"] = "keyword",
["imageAtomicXor"] = "keyword",
["imageAtomicExchange"]= "keyword",
["imageAtomicCompSwap"]= "keyword",
--Geometry Shader Functions
["EmitStreamVertex"] = "keyword",
["EndStreamPrimitive"] = "keyword",
["EmitVertex"] = "keyword",
["EndPrimitive"] = "keyword",
--Fragment Processing Functions
["dFdx"] = "keyword",
["dFdy"] = "keyword",
["dFdxFine"] = "keyword",
["dFdyFine"] = "keyword",
["dFdxCoarse"] = "keyword",
["dFdyCoarse"] = "keyword",
["fwidth"] = "keyword",
["fwidthFine"] = "keyword",
["fwidthCoarse"] = "keyword",
["interpolateAtCentroid"]= "keyword",
["interpolateAtSample"] = "keyword",
["interpolateAtOffset"] = "keyword",
--Shader Invocation Control Functions
["barrier"] = "keyword",
--Shader Memory Control Functions
["memoryBarrier"] = "keyword",
["memoryBarrierAtomicCounter"]= "keyword",
["memoryBarrierBuffer"] = "keyword",
["memoryBarrierShared"] = "keyword",
["memoryBarrierImage"] = "keyword",
["groupMemoryBarrier"] = "keyword",
--Subpass-Input Functions
["subpassLoad"] = "keyword",
--Shader Invocation Group Functions
["anyInvocation"] = "keyword",
["allInvocations"] = "keyword",
["allInvocationsEqual"]= "keyword",
--"In addition, when targeting Vulkan, the following keywords also exist:"
["texture1D"] = "keyword",
["texture1DArray"] = "keyword",
["itexture1D"] = "keyword",
["itexture1DArray"] = "keyword",
["utexture1D"] = "keyword",
["utexture1DArray"] = "keyword",
["texture2D"] = "keyword",
["texture2DArray"] = "keyword",
["itexture2D"] = "keyword",
["itexture2DArray"] = "keyword",
["utexture2D"] = "keyword",
["utexture2DArray"] = "keyword",
["texture2DRect"] = "keyword",
["itexture2DRect"] = "keyword",
["utexture2DRect"] = "keyword",
["texture2DMS"] = "keyword",
["itexture2DMS"] = "keyword",
["utexture2DMS"] = "keyword",
["texture2DMSArray"] = "keyword",
["itexture2DMSArray"]= "keyword",
["utexture2DMSArray"]= "keyword",
["texture3D"] = "keyword",
["itexture3D"] = "keyword",
["utexture3D"] = "keyword",
["textureCube"] = "keyword",
["itextureCube"] = "keyword",
["utextureCube"] = "keyword",
["textureCubeArray"] = "keyword",
["itextureCubeArray"]= "keyword",
["utextureCubeArray"]= "keyword",
["textureBuffer"] = "keyword",
["itextureBuffer"] = "keyword",
["utextureBuffer"] = "keyword",
["sampler"] = "keyword2",
["samplerShadow"] = "keyword2",
["subpassInput"] = "keyword2",
["isubpassInput"] = "keyword2",
["usubpassInput"] = "keyword2",
["subpassInputMS"] = "keyword2",
["isubpassInputMS"] = "keyword2",
["usubpassInputMS"] = "keyword2",
},
}

View file

@ -0,0 +1,71 @@
local syntax = require "core.syntax"
syntax.add {
files = { "%.go$" },
comment = "//",
patterns = {
{ pattern = "//.-\n", type = "comment" },
{ pattern = { "/%*", "%*/" }, type = "comment" },
{ pattern = { '"', '"', '\\' }, type = "string" },
{ pattern = { "`", "`", '\\' }, type = "string" },
{ pattern = "0[oO_][0-7]+", type = "number" },
{ pattern = "-?0x[%x_]+", type = "number" },
{ pattern = "-?%d+_%d", type = "number" },
{ pattern = "-?%d+[%d%.eE]*f?", type = "number" },
{ pattern = "-?%.?%d+f?", type = "number" },
{ pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" },
{ pattern = ":=", type = "operator" },
{ pattern = "[%a_][%w_]*%f[(]", type = "function" },
{ pattern = "[%a_][%w_]*", type = "symbol" },
},
symbols = {
["if"] = "keyword",
["else"] = "keyword",
["elseif"] = "keyword",
["for"] = "keyword",
["continue"] = "keyword",
["return"] = "keyword",
["struct"] = "keyword",
["switch"] = "keyword",
["case"] = "keyword",
["default"] = "keyword",
["const"] = "keyword",
["package"] = "keyword",
["import"] = "keyword",
["func"] = "keyword",
["var"] = "keyword",
["type"] = "keyword",
["interface"] = "keyword",
["select"] = "keyword",
["break"] = "keyword",
["range"] = "keyword",
["chan"] = "keyword",
["defer"] = "keyword",
["go"] = "keyword",
["int"] = "keyword2",
["int64"] = "keyword2",
["int32"] = "keyword2",
["int16"] = "keyword2",
["int8"] = "keyword2",
["uint"] = "keyword2",
["uint64"] = "keyword2",
["uint32"] = "keyword2",
["uint16"] = "keyword2",
["uint8"] = "keyword2",
["uintptr"] = "keyword2",
["float64"] = "keyword2",
["float32"] = "keyword2",
["map"] = "keyword2",
["string"] = "keyword2",
["rune"] = "keyword2",
["bool"] = "keyword2",
["byte"] = "keyword2",
["error"] = "keyword2",
["complex64"] = "keyword2",
["complex128"] = "keyword2",
["true"] = "literal",
["false"] = "literal",
["nil"] = "literal",
},
}

View file

@ -0,0 +1,275 @@
local style = require "core.style"
local common = require "core.common"
local syntax = require "core.syntax"
syntax.add {
files = { "%.hlsl$", },
comment = "//",
patterns = {
{ pattern = "//.-\n", type = "comment" },
{ pattern = { "/%*", "%*/" }, type = "comment" },
{ pattern = { "#", "[^\\]\n" }, type = "comment" },
{ pattern = { '"', '"', '\\' }, type = "string" },
{ pattern = { "'", "'", '\\' }, type = "string" },
{ pattern = "-?0x%x+", type = "number" },
{ pattern = "-?%d+[%d%.eE]*f?", type = "number" },
{ pattern = "-?%.?%d+f?", type = "number" },
{ pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" },
{ pattern = "int[1-9]x[1-9]", type = "keyword2" },
{ pattern = "int1[0-6]x[1-9]", type = "keyword2" },
{ pattern = "int[1-9]x1[0-6]", type = "keyword2" },
{ pattern = "int1[0-6]x1[0-6]", type = "keyword2" },
{ pattern = "int[1-4]", type = "keyword2" },
{ pattern = "uint[1-9]x[1-9]", type = "keyword2" },
{ pattern = "uint1[0-6]x[1-9]", type = "keyword2" },
{ pattern = "uint[1-9]x1[0-6]", type = "keyword2" },
{ pattern = "uint1[0-6]x1[0-6]", type = "keyword2" },
{ pattern = "uint[1-4]", type = "keyword2" },
{ pattern = "dword[1-9]x[1-9]", type = "keyword2" },
{ pattern = "dword1[0-6]x[1-9]", type = "keyword2" },
{ pattern = "dword[1-9]x1[0-6]", type = "keyword2" },
{ pattern = "dword1[0-6]x1[0-6]", type = "keyword2" },
{ pattern = "dword[1-4]", type = "keyword2" },
{ pattern = "half[1-9]x[1-9]", type = "keyword2" },
{ pattern = "half1[0-6]x[1-9]", type = "keyword2" },
{ pattern = "half[1-9]x1[0-6]", type = "keyword2" },
{ pattern = "half1[0-6]x1[0-6]", type = "keyword2" },
{ pattern = "half[1-4]", type = "keyword2" },
{ pattern = "float[1-9]x[1-9]", type = "keyword2" },
{ pattern = "float1[0-6]x[1-9]", type = "keyword2" },
{ pattern = "float[1-9]x1[0-6]", type = "keyword2" },
{ pattern = "float1[0-6]x1[0-6]", type = "keyword2" },
{ pattern = "float[1-4]", type = "keyword2" },
{ pattern = "double[1-9]x[1-9]", type = "keyword2" },
{ pattern = "double1[0-6]x[1-9]", type = "keyword2" },
{ pattern = "double[1-9]x1[0-6]", type = "keyword2" },
{ pattern = "double1[0-6]x1[0-6]", type = "keyword2" },
{ pattern = "double[1-4]", type = "keyword2" },
{ pattern = "[%a_][%w_]*%f[(]", type = "function" },
{ pattern = "[%a_][%w_]*", type = "symbol" },
},
symbols = {
--https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-appendix-keywords
--The symbols are added in the order they appear on this webpage, which is alphabetically
["AppendStructuredBuffer"]= "keyword",
["asm"] = "keyword",
["asm_fragment"] = "keyword",
["BlendState"] = "keyword2",
["bool"] = "keyword2",
["break"] = "keyword",
["Buffer"] = "keyword2",
["ByteAddressBuffer"]= "keyword2",
["case"] = "keyword",
["cbuffer"] = "keyword2",
["centroid"] = "keyword2",
["class"] = "keyword",
["column_major"] = "keyword",
["compile"] = "keyword",
["compile_fragment"] = "keyword",
["CompileShader"] = "keyword",
["const"] = "keyword",
["continue"] = "keyword",
["ComputeShader"] = "keyword",
["ConsumeStructuredBuffer"]= "keyword",
["default"] = "keyword",
["DepthStencilState"]= "keyword",
["DepthStencilView"] = "keyword",
["discard"] = "keyword",
["do"] = "keyword",
["double"] = "keyword2",
["DomainShader"] = "keyword2",
["dword"] = "keyword2",
["else"] = "keyword",
["export"] = "keyword",
["extern"] = "keyword",
["false"] = "literal",
["float"] = "keyword2",
["for"] = "keyword",
["fxgroup"] = "keyword2",
["GeometryShader"] = "keyword2",
["groupshared"] = "keyword",
["half"] = "keyword2",
["HullShader"] = "keyword2",
["if"] = "keyword",
["in"] = "keyword",
["inline"] = "keyword",
["inout"] = "keyword",
["InputPatch"] = "keyword2",
["int"] = "keyword2",
["interface"] = "keyword",
["line"] = "keyword2",
["lineadj"] = "keyword2",
["linear"] = "keyword",
["LineStream"] = "keyword2",
["matrix"] = "keyword2",
["min16float"] = "keyword2",
["min10float"] = "keyword2",
["min16int"] = "keyword2",
["min12int"] = "keyword2",
["min16uint"] = "keyword2",
["namespace"] = "keyword",
["nointerpolation"] = "keyword",
["noperspective"] = "keyword",
["NULL"] = "literal",
["out"] = "keyword",
["OutputPatch"] = "keyword2",
["packoffset"] = "keyword",
["pass"] = "keyword",
["pixelfragment"] = "keyword",
["PixelShader"] = "keyword2",
["point"] = "keyword2",
["PointStream"] = "keyword2",
["precise"] = "keyword",
["RasterizerState"] = "keyword2",
["RenderTargetView"] = "keyword2",
["return"] = "keyword",
["register"] = "keyword",
["row_major"] = "keyword",
["RWBuffer"] = "keyword2",
["RWByteAddressBuffer"]= "keyword2",
["RWStructuredBuffer"]= "keyword2",
["RWTexture1D"] = "keyword2",
["RWTexture1DArray"] = "keyword2",
["RWTexture2D"] = "keyword2",
["RWTexture2DArray"] = "keyword2",
["RWTexture3D"] = "keyword2",
["sample"] = "keyword",
["sampler"] = "keyword2",
["SamplerState"] = "keyword2",
["SamplerComparisonState"]= "keyword2",
["shared"] = "keyword",
["snorm"] = "keyword",
["stateblock"] = "keyword",
["stateblock_state"] = "keyword",
["static"] = "keyword",
["string"] = "keyword2",
["struct"] = "keyword",
["switch"] = "keyword",
["StructuredBuffer"] = "keyword2",
["tbuffer"] = "keyword2",
["technique"] = "keyword2",
["technique10"] = "keyword2",
["technique11"] = "keyword2",
["texture"] = "keyword2",
["Texture1D"] = "keyword2",
["Texture1DArray"] = "keyword2",
["Texture2D"] = "keyword2",
["Texture2DArray"] = "keyword2",
["Texture2DMS"] = "keyword2",
["Texture2DMSArray"] = "keyword2",
["Texture3D"] = "keyword2",
["TextureCube"] = "keyword2",
["TextureCubeArray"] = "keyword2",
["true"] = "literal",
["typedef"] = "keyword",
["triangle"] = "keyword2",
["triangleadj"] = "keyword2",
["TriangleStream"] = "keyword2",
["uint"] = "keyword2",
["uniform"] = "keyword",
["unorm"] = "keyword",
["unsigned"] = "keyword",
["vector"] = "keyword2",
["vertexfragment"] = "keyword2",
["VertexShader"] = "keyword2",
["void"] = "keyword",
["volatile"] = "keyword",
["while"] = "keyword",
--https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-intrinsic-functions
--The symbols are added in the order they appear on this webpage, which is alphabetically
["abort"] = "keyword",
["abs"] = "keyword",
["acos"] = "keyword",
["all"] = "keyword",
["any"] = "keyword",
["asdouble"] = "keyword",
["asfloat"] = "keyword",
["asin"] = "keyword",
["asint"] = "keyword",
["asuint"] = "keyword",
["atan"] = "keyword",
["atan2"] = "keyword",
["ceil"] = "keyword",
["clamp"] = "keyword",
["clip"] = "keyword",
["cos"] = "keyword",
["cosh"] = "keyword",
["countbits"] = "keyword",
["cross"] = "keyword",
["ddx"] = "keyword",
["ddx_coarse"] = "keyword",
["ddx_fine"] = "keyword",
["ddy"] = "keyword",
["ddy_coarse"] = "keyword",
["ddy_fine"] = "keyword",
["degrees"] = "keyword",
["determinant"] = "keyword",
["distance"] = "keyword",
["dot"] = "keyword",
["dst"] = "keyword",
["errorf"] = "keyword",
["exp"] = "keyword",
["exp2"] = "keyword",
["f16tof32"] = "keyword",
["f32tof16"] = "keyword",
["faceforward"] = "keyword",
["firstbithigh"]= "keyword",
["firstbitlow"] = "keyword",
["floor"] = "keyword",
["fma"] = "keyword",
["fmod"] = "keyword",
["frac"] = "keyword",
["frexp"] = "keyword",
["fwidth"] = "keyword",
["isfinite"] = "keyword",
["isinf"] = "keyword",
["isnan"] = "keyword",
["ldexp"] = "keyword",
["length"] = "keyword",
["lerp"] = "keyword",
["lit"] = "keyword",
["log"] = "keyword",
["log10"] = "keyword",
["log2"] = "keyword",
["mad"] = "keyword",
["max"] = "keyword",
["min"] = "keyword",
["modf"] = "keyword",
["msad4"] = "keyword",
["mul"] = "keyword",
["noise"] = "keyword",
["normalize"] = "keyword",
["pow"] = "keyword",
["printf"] = "keyword",
["radians"] = "keyword",
["rcp"] = "keyword",
["reflect"] = "keyword",
["refract"] = "keyword",
["reversebits"] = "keyword",
["round"] = "keyword",
["rsqrt"] = "keyword",
["saturate"] = "keyword",
["sign"] = "keyword",
["sin"] = "keyword",
["sincos"] = "keyword",
["sinh"] = "keyword",
["smoothstep"] = "keyword",
["sqrt"] = "keyword",
["step"] = "keyword",
["tan"] = "keyword",
["tanh"] = "keyword",
["transpose"] = "keyword",
["trunc"] = "keyword",
},
}

View file

@ -0,0 +1,45 @@
local syntax = require "core.syntax"
syntax.add {
files = { "%.hs$" },
comment = "%-%-",
patterns = {
{ pattern = {"%-%-", "\n"}, type = "comment" },
{ pattern = { "{%-", "%-}" }, type = "comment" },
{ pattern = { '"', '"', '\\' }, type = "string" },
{ pattern = { "'", "'", '\\' }, type = "string" },
{ pattern = "-?0x%x+", type = "number" },
{ pattern = "-?%d+[%d%.eE]*f?", type = "number" },
{ pattern = "-?%.?%d+f?", type = "number" },
{ pattern = "[!%#%$%%&*+./%<=>%?@\\%^|%-~:]", type = "operator" },
{ pattern = "[%a_'][%w_']*", type = "symbol" },
},
symbols = {
["as"] = "keyword",
["case"] = "keyword",
["of"] = "keyword",
["class"] = "keyword",
["data"] = "keyword",
["default"] = "keyword",
["deriving"] = "keyword",
["do"] = "keyword",
["forall"] = "keyword",
["foreign"] = "keyword",
["hiding"] = "keyword",
["if"] = "keyword",
["then"] = "keyword",
["else"] = "keyword",
["import"] = "keyword",
["infix"] = "keyword",
["infixl"] = "keyword",
["infixr"] = "keyword",
["let"] = "keyword",
["in"] = "keyword",
["mdo"] = "keyword",
["module"] = "keyword",
["newtype"] = "keyword",
["qualified"] = "keyword",
["type"] = "keyword",
["where"] = "keyword",
},
}

View file

@ -0,0 +1,75 @@
local syntax = require "core.syntax"
syntax.add {
files = { "%.java$" },
comment = "//",
patterns = {
{ pattern = "//.-\n", type = "comment" },
{ pattern = { "/%*", "%*/" }, type = "comment" },
{ pattern = { '"', '"', '\\' }, type = "string" },
{ pattern = { "'", "'", '\\' }, type = "string" },
{ pattern = "'\\x%x?%x?%x?%x'", type = "string" }, -- character hexadecimal escape sequence
{ pattern = "'\\u%x%x%x%x'", type = "string" }, -- character unicode escape sequence
{ pattern = "'\\?.'", type = "string" }, -- character literal
{ pattern = "-?0x%x+", type = "number" },
{ pattern = "-?%d+[%d%.eE]*f?", type = "number" },
{ pattern = "-?%.?%d+f?", type = "number" },
{ pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" },
{ pattern = "[%a_][%w_]*%f[(]", type = "function" },
{ pattern = "[%a_][%w_]*", type = "symbol" },
},
symbols = {
["if"] = "keyword",
["then"] = "keyword",
["else"] = "keyword",
["else if"] = "keyword",
["do"] = "keyword",
["while"] = "keyword",
["for"] = "keyword",
["new"] = "keyword",
["break"] = "keyword",
["continue"] = "keyword",
["return"] = "keyword",
["goto"] = "keyword",
["class"] = "keyword",
["implements"] = "keyword",
["extends"] = "keyword",
["private"] = "keyword",
["protected"] = "keyword",
["public"] = "keyword",
["abstract"] = "keyword",
["interface"] = "keyword",
["assert"] = "keyword",
["import"] = "keyword",
["native"] = "keyword",
["package"] = "keyword",
["super"] = "keyword",
["synchronized"] = "keyword",
["instanceof"] = "keyword",
["enum"] = "keyword",
["catch"] = "keyword",
["throw"] = "keyword",
["throws"] = "keyword",
["try"] = "keyword",
["transient"] = "keyword",
["finally"] = "keyword",
["static"] = "keyword",
["volatile"] = "keyword",
["final"] = "keyword",
["switch"] = "keyword",
["case"] = "keyword",
["default"] = "keyword",
["void"] = "keyword",
["int"] = "keyword2",
["short"] = "keyword2",
["byte"] = "keyword2",
["long"] = "keyword2",
["float"] = "keyword2",
["double"] = "keyword2",
["char"] = "keyword2",
["boolean"] = "keyword2",
["true"] = "literal",
["false"] = "literal",
["null"] = "literal",
},
}

View file

@ -0,0 +1,91 @@
local syntax = require "core.syntax"
syntax.add {
files = { "%.jiyu$", "%.jyu$" },
comment = "//",
patterns = {
{ pattern = "//.-\n", type = "comment" },
{ pattern = { "/%*", "%*/" }, type = "comment" },
{ pattern = { "\"\"\"", "\"\"\"" }, type = "string" },
{ pattern = { '"', '"', '\\' }, type = "string" },
{ pattern = { "'", "'", '\\' }, type = "string" },
{ pattern = "0b[0-1]+", type = "number" },
{ pattern = "0x[%da-fA-F]+", type = "number" },
{ pattern = "-?%d+[%d%.]*", type = "number" },
{ pattern = "-?%.?%d+?", type = "number" },
{ pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" },
{ pattern = "[<>~=+-*/]=", type = "operator" },
{ pattern = "[..]", type = "operator" },
{ pattern = "[%a_][%w_]*%f[(]", type = "function" },
{ pattern = "[#@]?[%a_][%w_]*", type = "symbol" },
},
symbols = {
-- Keywords
["func"] = "keyword",
["if"] = "keyword",
["else"] = "keyword",
["for"] = "keyword",
["while"] = "keyword",
["defer"] = "keyword",
["return"] = "keyword",
["switch"] = "keyword",
["case"] = "keyword",
["break"] = "keyword",
["continue"] = "keyword",
["fallthrough"] = "keyword",
["struct"] = "keyword",
["union"] = "keyword",
["enum"] = "keyword",
["using"] = "keyword",
["var"] = "keyword",
["let"] = "keyword",
["typealias"] = "keyword",
["library"] = "keyword",
["framework"] = "keyword",
["temporary_c_vararg"] = "keyword2";
-- Builtin procedures and directives
["cast"] = "keyword2",
["sizeof"] = "keyword2",
["alignof"] = "keyword2",
["strideof"] = "keyword2",
["offsetof"] = "keyword2",
["type_of"] = "keyword2",
["type_info"] = "keyword2",
["#if"] = "keyword2",
["#load"] = "keyword2",
["#import"] = "keyword2",
["#clang_import"] = "keyword2",
["#file"] = "keyword2",
["#filepath"] = "keyword2",
["#line"] = "keyword2",
["@c_function"] = "keyword2",
["@export"] = "keyword2",
["@flags"] = "keyword2",
["@metaprogram"] = "keyword2",
-- Types
["string"] = "keyword2",
["int"] = "keyword2",
["uint"] = "keyword2",
["uint8"] = "keyword2",
["uint16"] = "keyword2",
["uint32"] = "keyword2",
["uint64"] = "keyword2",
["uint128"] = "keyword2",
["int8"] = "keyword2",
["int16"] = "keyword2",
["int32"] = "keyword2",
["int64"] = "keyword2",
["int128"] = "keyword2",
["float"] = "keyword2",
["double"] = "keyword2",
["void"] = "keyword2",
["bool"] = "keyword2",
["Type"] = "keyword2",
-- Literals
["true"] = "literal",
["false"] = "literal",
["null"] = "literal",
}
}

View file

@ -0,0 +1,17 @@
local syntax = require "core.syntax"
syntax.add {
files = { "Makefile", "makefile", "%.mk$" },
comment = "#",
patterns = {
{ pattern = "#.*\n", type = "comment" },
{ pattern = [[\.]], type = "normal" },
{ pattern = "$[@^<%%?+|*]", type = "keyword2" },
{ pattern = "$%(.-%)", type = "variable" },
{ pattern = "%f[%w_][%d%.]+%f[^%w_]", type = "number" },
{ pattern = "%..*:", type = "keyword2" },
{ pattern = ".*:", type = "function" },
},
symbols = {
},
}

View file

@ -0,0 +1,35 @@
local syntax = require "core.syntax"
syntax.add {
files = "meson.build$",
comment = "#",
patterns = {
{ pattern = { "#", "\n" }, type = "comment" },
{ pattern = { '"', '"', '\\' }, type = "string" },
{ pattern = { "'", "'", '\\' }, type = "string" },
{ pattern = { "'''", "'''" }, type = "string" },
{ pattern = "0x[%da-fA-F]+", type = "number" },
{ pattern = "-?%d+%d*", type = "number" },
{ pattern = "[%+%-=/%%%*!]", type = "operator" },
{ pattern = "[%a_][%w_]*%f[(]", type = "function" },
{ pattern = "[%a_][%w_]*", type = "symbol" },
},
symbols = {
["if"] = "keyword",
["then"] = "keyword",
["else"] = "keyword",
["elif"] = "keyword",
["endif"] = "keyword",
["foreach"] = "keyword",
["endforeach"] = "keyword",
["break"] = "keyword",
["continue"] = "keyword",
["and"] = "keyword",
["not"] = "keyword",
["or"] = "keyword",
["in"] = "keyword",
["true"] = "literal",
["false"] = "literal",
},
}

View file

@ -0,0 +1,157 @@
local syntax = require "core.syntax"
syntax.add {
files = "%.odin$",
comment = "//",
patterns = {
{ pattern = "//.-\n", type = "comment" },
{ pattern = { "/%*", "%*/" }, type = "comment" },
{ pattern = { '"', '"', '\\' }, type = "string" },
{ pattern = { "'", "'", '\\' }, type = "string" },
{ pattern = { "`", "`" }, type = "string" },
{ pattern = "0b[01_]+", type = "number" },
{ pattern = "0o[0-7_]+", type = "number" },
{ pattern = "0[dz][%d_]+", type = "number" },
{ pattern = "0x[%da-fA-F_]+", type = "number" },
{ pattern = "-?%d+[%d%._e]*i?", type = "number" },
{ pattern = "-?%.?[%d_]+i?", type = "number" },
{ pattern = "[<>~=+-*/]=", type = "operator" },
{ pattern = "[::][:=]", type = "operator" },
{ pattern = "[%+%-=/%*%^%%<>!~|&:]", type = "operator" },
{ pattern = "%$[%a_][%w_]*", type = "operator" },
{ pattern = "[%a_][%w_]*%f[(]", type = "function" },
{ pattern = "[#@]?[%a_][%w_]*", type = "symbol" },
},
symbols = {
-- Keywords
["package"] = "keyword",
["import"] = "keyword",
["foreign"] = "keyword",
["when"] = "keyword",
["if"] = "keyword",
["else"] = "keyword",
["for"] = "keyword",
["defer"] = "keyword",
["return"] = "keyword",
["switch"] = "keyword",
["case"] = "keyword",
["in"] = "keyword",
["notin"] = "keyword",
["do"] = "keyword",
["break"] = "keyword",
["continue"] = "keyword",
["fallthrough"] = "keyword",
["proc"] = "keyword",
["struct"] = "keyword",
["union"] = "keyword",
["enum"] = "keyword",
["bit_set"] = "keyword",
["map"] = "keyword",
["dynamic"] = "keyword",
["using"] = "keyword",
["inline"] = "keyword",
["no_inline"] = "keyword",
["context"] = "keyword",
["distinct"] = "keyword",
["opaque"] = "keyword",
["macro"] = "keyword", -- Reserved, not yet used
["const"] = "keyword", -- Reserved, not yet used
-- Builtin procedures and directives
["cast"] = "keyword2",
["auto_cast"] = "keyword2",
["transmute"] = "keyword2",
["len"] = "keyword2",
["cap"] = "keyword2",
["size_of"] = "keyword2",
["align_of"] = "keyword2",
["offset_of"] = "keyword2",
["typeid_of"] = "keyword2",
["type_of"] = "keyword2",
["type_info_of"] = "keyword2",
["type_info_base"] = "keyword2",
["swizzle"] = "keyword2",
["complex"] = "keyword2",
["real"] = "keyword2",
["imag"] = "keyword2",
["conj"] = "keyword2",
["min"] = "keyword2",
["max"] = "keyword2",
["abs"] = "keyword2",
["clamp"] = "keyword2",
["assert"] = "keyword2",
["#assert"] = "keyword2",
["#location"] = "keyword2",
["#caller_location"] = "keyword2",
["#packed"] = "keyword2",
["#raw_union"] = "keyword2",
["#align"] = "keyword2",
["#no_nil"] = "keyword2",
["#complete"] = "keyword2",
["#no_alias"] = "keyword2",
["#align"] = "keyword2",
["#load"] = "keyword2",
["#location"] = "keyword2",
["#file"] = "keyword2",
["#line"] = "keyword2",
["#procedure"] = "keyword2",
["#defined"] = "keyword2",
["#no_bounds_check"] = "keyword2",
["#bounds_check"] = "keyword2",
["#type"] = "keyword2",
["@private"] = "keyword2",
-- Types
["rawptr"] = "keyword2",
["typeid"] = "keyword2",
["any"] = "keyword2",
["string"] = "keyword2",
["cstring"] = "keyword2",
["int"] = "keyword2",
["uint"] = "keyword2",
["uintptr"] = "keyword2",
["rune"] = "keyword2",
["byte"] = "keyword2",
["u8"] = "keyword2",
["u16"] = "keyword2",
["u32"] = "keyword2",
["u64"] = "keyword2",
["u128"] = "keyword2",
["i8"] = "keyword2",
["i16"] = "keyword2",
["i32"] = "keyword2",
["i64"] = "keyword2",
["i128"] = "keyword2",
["f16"] = "keyword2",
["f32"] = "keyword2",
["f64"] = "keyword2",
["u16le"] = "keyword2",
["u32le"] = "keyword2",
["u64le"] = "keyword2",
["u128le"] = "keyword2",
["i16le"] = "keyword2",
["i32le"] = "keyword2",
["i64le"] = "keyword2",
["i128le"] = "keyword2",
["u16be"] = "keyword2",
["u32be"] = "keyword2",
["u64be"] = "keyword2",
["u128be"] = "keyword2",
["i16be"] = "keyword2",
["i32be"] = "keyword2",
["i64be"] = "keyword2",
["i128be"] = "keyword2",
["complex32"] = "keyword2",
["complex64"] = "keyword2",
["complex128"] = "keyword2",
["quaternion128"] = "keyword2",
["quaternion256"] = "keyword2",
["bool"] = "keyword2",
["b8"] = "keyword2",
["b32"] = "keyword2",
["b64"] = "keyword2",
["b128"] = "keyword2",
-- Literals
["true"] = "literal",
["false"] = "literal",
["nil"] = "literal",
}
}

View file

@ -0,0 +1,99 @@
local syntax = require "core.syntax"
syntax.add {
files = { "%.php$", "%.phtml" },
headers = "^<%?php",
comment = "//",
patterns = {
{ pattern = "//.-\n", type = "comment" },
{ pattern = "#.-\n", type = "comment" },
{ pattern = { "/%*", "%*/" }, type = "comment" },
-- I dont know why the '//' are needed but I leave it here for now
{ pattern = { '"', '"', '\\' }, type = "string" },
{ pattern = { "'", "'", '\\' }, type = "string" },
{ pattern = "%\\x[%da-fA-F]+", type = "number" },
{ pattern = "-?%d+[%d%.eE]*", type = "number" },
{ pattern = "-?%.?%d+", type = "number" },
{ pattern = "[%.%+%-=/%*%^%%<>!~|&]", type = "operator" },
{ pattern = "[%a_][%w_]*%f[(]", type = "function" },
{ pattern = "[%a_][%w_]*", type = "symbol" },
-- To indicate variables.
{ pattern = "%$", type = "operator" },
},
symbols = {
["return"] = "keyword",
["if"] = "keyword",
["else"] = "keyword",
["elseif"] = "keyword",
["endif"] = "keyword",
["declare"] = "keyword",
["enddeclare"] = "keyword",
["switch"] = "keyword",
["endswitch"] = "keyword",
["as"] = "keyword",
["do"] = "keyword",
["for"] = "keyword",
["endfor"] = "keyword",
["foreach"] = "keyword",
["endforeach"] = "keyword",
["while"] = "keyword",
["endwhile"] = "keyword",
["switch"] = "keyword",
["case"] = "keyword",
["continue"] = "keyword",
["default"] = "keyword",
["break"] = "keyword",
["exit"] = "keyword",
["goto"] = "keyword",
["catch"] = "keyword",
["throw"] = "keyword",
["try"] = "keyword",
["finally"] = "keyword",
["class"] = "keyword",
["trait"] = "keyword",
["interface"] = "keyword",
["public"] = "keyword",
["static"] = "keyword",
["protected"] = "keyword",
["private"] = "keyword",
["abstract"] = "keyword",
["final"] = "keyword",
["function"] = "keyword2",
["global"] = "keyword2",
["var"] = "keyword2",
["const"] = "keyword2",
["bool"] = "keyword2",
["boolean"] = "keyword2",
["int"] = "keyword2",
["integer"] = "keyword2",
["real"] = "keyword2",
["double"] = "keyword2",
["float"] = "keyword2",
["string"] = "keyword2",
["array"] = "keyword2",
["object"] = "keyword2",
["callable"] = "keyword2",
["iterable"] = "keyword2",
["namespace"] = "keyword2",
["extends"] = "keyword2",
["implements"] = "keyword2",
["instanceof"] = "keyword2",
["require"] = "keyword2",
["require_once"] = "keyword2",
["include"] = "keyword2",
["include_once"] = "keyword2",
["use"] = "keyword2",
["new"] = "keyword2",
["clone"] = "keyword2",
["true"] = "literal",
["false"] = "literal",
["NULL"] = "literal",
["parent"] = "literal",
["self"] = "literal",
},
}

View file

@ -0,0 +1,51 @@
local syntax = require "core.syntax"
syntax.add {
files = "%.p8$",
headers = "^pico-8 cartridge",
comment = "--",
patterns = {
{ pattern = { 'pico%-8 cartridge', '__lua__' }, type = "comment" },
{ pattern = { '__gfx__\n', '%z' }, type = "comment" },
{ pattern = { '"', '"', '\\' }, type = "string" },
{ pattern = { "'", "'", '\\' }, type = "string" },
{ pattern = { "%[%[", "%]%]" }, type = "string" },
{ pattern = { "%-%-%[%[", "%]%]"}, type = "comment" },
{ pattern = "%-%-.-\n", type = "comment" },
{ pattern = "-?0x%x+", type = "number" },
{ pattern = "-?%d+[%d%.eE]*", type = "number" },
{ pattern = "-?%.?%d+", type = "number" },
{ pattern = "%.%.%.?", type = "operator" },
{ pattern = "[<>~=&|]=", type = "operator" },
{ pattern = "[%+%-=/%*%^%%#<>]", type = "operator" },
{ pattern = "[%a_][%w_]*%s*%f[(\"{]", type = "function" },
{ pattern = "[%a_][%w_]*", type = "symbol" },
{ pattern = "::[%a_][%w_]*::", type = "function" },
},
symbols = {
["if"] = "keyword",
["then"] = "keyword",
["else"] = "keyword",
["elseif"] = "keyword",
["end"] = "keyword",
["do"] = "keyword",
["function"] = "keyword",
["repeat"] = "keyword",
["until"] = "keyword",
["while"] = "keyword",
["for"] = "keyword",
["break"] = "keyword",
["return"] = "keyword",
["local"] = "keyword",
["in"] = "keyword",
["not"] = "keyword",
["and"] = "keyword",
["or"] = "keyword",
["goto"] = "keyword",
["self"] = "keyword2",
["true"] = "literal",
["false"] = "literal",
["nil"] = "literal",
},
}

View file

@ -0,0 +1,72 @@
local syntax = require "core.syntax"
syntax.add {
files = {"%.ps1$", "%.psm1$", "%.psd1$", "%.ps1xml$", "%.pssc$", "%.psrc$", "%.cdxml$"},
comment = "#",
patterns = {
{pattern = "#.*\n", type = "comment"},
{pattern = [[\.]], type = "normal"},
{pattern = {'"', '"'}, type = "string"},
{pattern = {"'", "'"}, type = "string"},
{pattern = "%f[%w_][%d%.]+%f[^%w_]", type = "number"},
{pattern = "[%+=/%*%^%%<>!~|&,:]+", type = "operator"},
{pattern = "%f[%S]%-[%w%-_]+", type = "function"},
{pattern = "[%u][%a]+[%-][%u][%a]+", type = "function"},
{pattern = "${.*}", type = "symbol"},
{pattern = "$[%a_@*][%w_]*", type = "keyword2"},
{pattern = "$[%$][%a]+", type = "keyword2"},
{pattern = "[%a_][%w_]*", type = "symbol"}
},
symbols = {
["if"] = "keyword",
["else"] = "keyword",
["elseif"] = "keyword",
["switch"] = "keyword",
["default"] = "keyword",
["function"] = "keyword",
["filter"] = "keyword",
["workflow"] = "keyword",
["configuration"] = "keyword",
["class"] = "keyword",
["enum"] = "keyword",
["Parameter"] = "keyword",
["ValidateScript"] = "keyword",
["CmdletBinding"] = "keyword",
["try"] = "keyword",
["catch"] = "keyword",
["finally"] = "keyword",
["throw"] = "keyword",
["while"] = "keyword",
["for"] = "keyword",
["do"] = "keyword",
["until"] = "keyword",
["break"] = "keyword",
["continue"] = "keyword",
["foreach"] = "keyword",
["in"] = "keyword",
["return"] = "keyword",
["where"] = "function",
["select"] = "function",
["filter"] = "keyword",
["in"] = "keyword",
["trap"] = "keyword",
["param"] = "keyword",
["data"] = "keyword",
["dynamicparam"] = "keyword",
["begin"] = "function",
["process"] = "function",
["end"] = "function",
["exit"] = "function",
["inlinescript"] = "function",
["parallel"] = "function",
["sequence"] = "function",
["true"] = "literal",
["false"] = "literal",
["TODO"] = "comment",
["FIXME"] = "comment",
["XXX"] = "comment",
["TBD"] = "comment",
["HACK"] = "comment",
["NOTE"] = "comment"
}
}

View file

@ -0,0 +1,90 @@
local syntax = require "core.syntax"
-- In sql symbols can be lower case and upper case
local keywords = {
"CREATE", "SELECT", "INSERT", "INTO", "UPDATE",
"DELETE", "TABLE", "DROP", "VALUES", "NOT",
"NULL", "PRIMARY", "KEY", "REFERENCES",
"DEFAULT", "UNIQUE", "CONSTRAINT", "CHECK",
"ON", "EXCLUDE", "WITH", "USING", "WHERE",
"GROUP", "BY", "HAVING", "DISTINCT", "LIMIT",
"OFFSET", "ONLY", "CROSS", "JOIN", "INNER",
"LEFT", "RIGHT", "FULL", "OUTER", "NATURAL",
"AND", "OR", "AS", "ORDER", "ORDINALITY",
"UNNEST", "FROM", "VIEW", "RETURNS", "SETOF",
"LANGUAGE", "SQL", "LIKE", "LATERAL",
"INTERVAL", "PARTITION", "UNION", "INTERSECT",
"EXCEPT", "ALL", "ASC", "DESC", "NULLS",
"FIRST", "LAST", "IN", "RECURSIVE", "ARRAY",
"RETURNING", "SET", "ALSO", "INSTEAD",
"ALTER", "SEQUENCE", "OWNED", "AT", "ZONE",
"WITHOUT", "TO", "TIMEZONE", "TYPE", "ENUM",
"DOCUMENT", "XMLPARSE", "XMLSERIALIZE",
"CONTENT", "OPTION", "INDEX", "ANY",
"EXTENSION", "ISNULL", "NOTNULL", "UNKNOWN",
"CASE", "THEN", "WHEN", "ELSE", "END",
"ROWS", "BETWEEN", "UNBOUNDED", "PRECEDING",
"UNBOUNDED", "FOLLOWING", "EXISTS", "SOME",
"COLLATION", "FOR", "TRIGGER", "BEFORE",
"EACH", "ROW", "EXECUTE", "PROCEDURE",
"FUNCTION", "DECLARE", "BEGIN", "LOOP",
"RAISE", "NOTICE", "LOOP", "EVENT",
"OPERATOR", "DOMAIN", "VARIADIC", "FOREIGN"
}
local types = {
"BIGINT", "INT8", "BIGSERIAL", "SERIAL8",
"BIT", "VARBIT", "BOOLEAN", "BOOL", "BOX",
"BYTEA", "CHARACTER", "CHAR", "VARCHAR",
"CIDR", "CIRCLE", "DATE", "DOUBLE",
"PRECISION", "FLOAT8", "INET", "INTEGER",
"INT", "INT4", "INTERVAL", "JSON", "JSONB",
"LINE", "LSEG", "MACADDR", "MONEY", "NUMERIC",
"DECIMAL", "PATH", "POINT", "POLYGON", "REAL",
"FLOAT4", "INT2", "SMALLINT", "SMALLSERIAL",
"SERIAL2", "SERIAL", "SERIAL4", "TEXT",
"TIME", "TIMEZ", "TIMESTAMP", "TIMESTAMPZ",
"TSQUERY", "TSVECTOR", "TXID_SNAPSHOT",
"UUID", "XML", "INT4RANGE", "INT8RANGE",
"NUMRANGE", "TSRANGE", "TSTZRANGE",
"DATERANGE", "PG_LSN"
}
local literals = {
"FALSE", "TRUE", "CURRENT_TIMESTAMP",
"CURRENT_TIME", "CURRENT_DATE", "LOCALTIME",
"LOCALTIMESTAMP"
}
local symbols = {}
for _, keyword in ipairs(keywords) do
symbols[keyword:lower()] = "keyword"
symbols[keyword] = "keyword"
end
for _, type in ipairs(types) do
symbols[type:lower()] = "keyword2"
symbols[type] = "keyword2"
end
for _, literal in ipairs(literals) do
symbols[literal:lower()] = "literal"
symbols[literal] = "literal"
end
syntax.add {
files = { "%.sql$", "%.psql$" },
comment = "--",
patterns = {
{ pattern = "%-%-.-\n", type = "comment" },
{ pattern = { "/%*", "%*/" }, type = "comment" },
{ pattern = { "'", "'", '\\' }, type = "string" },
{ pattern = "-?%d+[%d%.eE]*f?", type = "number" },
{ pattern = "-?%.?%d+f?", type = "number" },
{ pattern = "[%+%-=/%*%%<>!~|&@%?$#]", type = "operator" },
{ pattern = "[%a_][%w_]*%f[(]", type = "function" },
{ pattern = "[%a_][%w_]*", type = "symbol" },
},
symbols = symbols,
}

View file

@ -0,0 +1,84 @@
local syntax = require "core.syntax"
syntax.add {
files = { "%.rs$" },
comment = "//",
patterns = {
{ pattern = "//.-\n", type = "comment" },
{ pattern = { "/%*", "%*/" }, type = "comment" },
{ pattern = { '"', '"', '\\' }, type = "string" },
{ pattern = { "`", "`", '\\' }, type = "string" },
{ pattern = "0[oO_][0-7]+", type = "number" },
{ pattern = "-?0x[%x_]+", type = "number" },
{ pattern = "-?%d+_%d", type = "number" },
{ pattern = "-?%d+[%d%.eE]*f?", type = "number" },
{ pattern = "-?%.?%d+f?", type = "number" },
{ pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" },
{ pattern = "[%a_][%w_]*%f[(]", type = "function" },
{ pattern = "[%a_][%w_]*", type = "symbol" },
},
symbols = {
["as"] = "keyword",
["async"] = "keyword",
["await"] = "keyword",
["break"] = "keyword",
["const"] = "keyword",
["continue"] = "keyword",
["crate"] = "keyword",
["dyn"] = "keyword",
["else"] = "keyword",
["enum"] = "keyword",
["extern"] = "keyword",
["false"] = "keyword",
["fn"] = "keyword",
["for"] = "keyword",
["if"] = "keyword",
["impl"] = "keyword",
["in"] = "keyword",
["let"] = "keyword",
["loop"] = "keyword",
["match"] = "keyword",
["mod"] = "keyword",
["move"] = "keyword",
["mut"] = "keyword",
["pub"] = "keyword",
["ref"] = "keyword",
["return"] = "keyword",
["Self"] = "keyword",
["self"] = "keyword",
["static"] = "keyword",
["struct"] = "keyword",
["super"] = "keyword",
["trait"] = "keyword",
["true"] = "keyword",
["type"] = "keyword",
["unsafe"] = "keyword",
["use"] = "keyword",
["where"] = "keyword",
["while"] = "keyword",
["i32"] = "keyword2",
["i64"] = "keyword2",
["i128"] = "keyword2",
["i16"] = "keyword2",
["i8"] = "keyword2",
["u16"] = "keyword2",
["u32"] = "keyword2",
["u64"] = "keyword2",
["usize"] = "keyword2",
["isize"] = "keyword2",
["f32"] = "keyword2",
["f64"] = "keyword2",
["f128"] = "keyword2",
["String"] = "keyword2",
["&str"] = "keyword2",
["bool"] = "keyword2",
["true"] = "literal",
["false"] = "literal",
["None"] = "literal",
["Some"] = "literal",
["Option"] = "literal",
["Result"] = "literal",
},
}

View file

@ -0,0 +1,42 @@
local syntax = require "core.syntax"
syntax.add {
files = { "%.sh$" },
headers = "^#!.*bin.*sh\n",
comment = "#",
patterns = {
{ pattern = "#.*\n", type = "comment" },
{ pattern = [[\.]], type = "normal" },
{ pattern = { '"', '"', '\\' }, type = "string" },
{ pattern = { "'", "'", '\\' }, type = "string" },
{ pattern = { '`', '`', '\\' }, type = "string" },
{ pattern = "%f[%w_][%d%.]+%f[^%w_]", type = "number" },
{ pattern = "[!<>|&%[%]=*]", type = "operator" },
{ pattern = "%f[%S]%-[%w%-_]+", type = "function" },
{ pattern = "${.*}", type = "keyword2" },
{ pattern = "$[%a_@*][%w_]*", type = "keyword2" },
{ pattern = "[%a_][%w_]*", type = "symbol" },
},
symbols = {
["case"] = "keyword",
["do"] = "keyword",
["done"] = "keyword",
["elif"] = "keyword",
["else"] = "keyword",
["esac"] = "keyword",
["fi"] = "keyword",
["for"] = "keyword",
["function"] = "keyword",
["if"] = "keyword",
["in"] = "keyword",
["select"] = "keyword",
["then"] = "keyword",
["time"] = "keyword",
["until"] = "keyword",
["while"] = "keyword",
["echo"] = "keyword",
["true"] = "literal",
["false"] = "literal",
},
}

View file

@ -0,0 +1,16 @@
local syntax = require "core.syntax"
syntax.add {
files = { "%.tex$" },
comment = "%%",
patterns = {
{ pattern = {"%%", "\n"}, type = "comment" },
{ pattern = "&", type = "operator" },
{ pattern = "\\\\", type = "operator" },
{ pattern = {"%$", "%$"}, type = "operator" },
{ pattern = {"\\%[", "\\]"}, type = "operator" },
{ pattern = {"{", "}"}, type = "keyword" },
{ pattern = "\\%w*", type = "keyword2" },
},
symbols = {}
}

View file

@ -0,0 +1,43 @@
local syntax = require "core.syntax"
syntax.add {
files = { "%.wren$" },
comment = "//",
patterns = {
{ pattern = "//.-\n", type = "comment" },
{ pattern = { "/%*", "%*/" }, type = "comment" },
{ pattern = { '"', '"', '\\' }, type = "string" },
{ pattern = { "'", "'", '\\' }, type = "string" },
{ pattern = "-?%.?%d+", type = "number" },
{ pattern = "%.%.%.?", type = "operator" },
{ pattern = "[<>!=]=", type = "operator" },
{ pattern = "[%+%-=/%*%^%%<>!~|&?:]", type = "operator" },
{ pattern = "[%a_][%w_]*%s*%f[(\"{]", type = "function" },
{ pattern = "[%a_][%w_]*", type = "symbol" },
},
symbols = {
["break"] = "keyword",
["class"] = "keyword",
["construct"] = "keyword",
["else"] = "keyword",
["false"] = "keyword",
["for"] = "keyword",
["foreign"] = "keyword",
["if"] = "keyword",
["import"] = "keyword",
["in"] = "keyword",
["is"] = "keyword",
["null"] = "keyword",
["return"] = "keyword",
["static"] = "keyword",
["super"] = "keyword",
["this"] = "keyword",
["true"] = "keyword",
["var"] = "keyword",
["while"] = "keyword",
["this"] = "keyword2",
["true"] = "literal",
["false"] = "literal",
["null"] = "literal",
},
}

View file

@ -0,0 +1,26 @@
local core = require "core"
local last_project_filename = EXEDIR .. PATHSEP .. ".lite_last_project"
-- load last project path
local fp = io.open(last_project_filename)
local project_path
if fp then
project_path = fp:read("*a")
fp:close()
end
-- save current project path
local fp = io.open(last_project_filename, "w")
fp:write(system.absolute_path ".")
fp:close()
-- restart using last project path if we had no commandline arguments and could
-- find a last-project file
if #ARGS == 1 and project_path then
system.exec(string.format("%s %q", EXEFILE, project_path))
core.quit(true)
end

View file

@ -0,0 +1,64 @@
local core = require "core"
local command = require "core.command"
local config = require "core.config"
local keymap = require "core.keymap"
config.lfautoinsert_map = {
["{%s*\n"] = "}",
["%(%s*\n"] = ")",
["%f[[]%[%s*\n"] = "]",
["%[%[%s*\n"] = "]]",
["=%s*\n"] = false,
[":%s*\n"] = false,
["^#if.*\n"] = "#endif",
["^#else.*\n"] = "#endif",
["%f[%w]do%s*\n"] = "end",
["%f[%w]then%s*\n"] = "end",
["%f[%w]else%s*\n"] = "end",
["%f[%w]repeat%s*\n"] = "until",
["%f[%w]function.*%)%s*\n"] = "end",
["^%s*<([^/][^%s>]*)[^>]*>%s*\n"] = "</$TEXT>",
}
local function indent_size(doc, line)
local text = doc.lines[line] or ""
local s, e = text:find("^[\t ]*")
return e - s
end
command.add("core.docview", {
["autoinsert:newline"] = function()
command.perform("doc:newline")
local doc = core.active_view.doc
local line, col = doc:get_selection()
local text = doc.lines[line - 1]
for ptn, close in pairs(config.lfautoinsert_map) do
local s, _, str = text:find(ptn)
if s then
if close
and col == #doc.lines[line]
and indent_size(doc, line + 1) <= indent_size(doc, line - 1)
then
close = str and close:gsub("$TEXT", str) or close
command.perform("doc:newline")
core.active_view:on_text_input(close)
command.perform("doc:move-to-previous-line")
if doc.lines[line+1] == doc.lines[line+2] then
doc:remove(line+1, 1, line+2, 1)
end
elseif col < #doc.lines[line] then
command.perform("doc:newline")
command.perform("doc:move-to-previous-line")
end
command.perform("doc:indent")
end
end
end
})
keymap.add {
["return"] = { "command:submit", "autoinsert:newline" }
}

45
vendor/lite-plugins/plugins/linecopypaste.lua vendored Executable file
View file

@ -0,0 +1,45 @@
local core = require "core"
local command = require "core.command"
local function doc()
return core.active_view.doc
end
local line_in_clipboard = false
local doc_copy = command.map["doc:copy"].perform
command.map["doc:copy"].perform = function()
if doc():has_selection() then
doc_copy()
line_in_clipboard = false
else
local line = doc():get_selection()
system.set_clipboard(doc().lines[line])
line_in_clipboard = true
end
end
local doc_cut = command.map["doc:cut"].perform
command.map["doc:cut"].perform = function()
if doc():has_selection() then
doc_cut()
line_in_clipboard = false
else
local line = doc():get_selection()
system.set_clipboard(doc().lines[line])
doc():remove(line, 1, line+1, 1)
doc():set_selection(line, 1)
line_in_clipboard = true
end
end
local doc_paste = command.map["doc:paste"].perform
command.map["doc:paste"].perform = function()
if line_in_clipboard == false then
doc_paste()
else
local line, col = doc():get_selection()
doc():insert(line, 1, system.get_clipboard():gsub("\r", ""))
doc():set_selection(line+1, col)
end
end

View file

@ -0,0 +1,18 @@
local config = require "core.config"
local style = require "core.style"
local DocView = require "core.docview"
local draw = DocView.draw
function DocView:draw(...)
draw(self, ...)
local offset = self:get_font():get_width("n") * config.line_limit
local x = self:get_line_screen_position(1) + offset
local y = self.position.y
local w = math.ceil(SCALE * 1)
local h = self.size.y
local color = style.guide or style.selection
renderer.draw_rect(x, y, w, h, color)
end

Some files were not shown because too many files have changed in this diff Show more