diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/closeconfirmx.lua | 54 | ||||
-rw-r--r-- | plugins/inanimate.lua | 12 | ||||
-rw-r--r-- | plugins/language_csharp.lua | 10 | ||||
-rw-r--r-- | plugins/projectmanager.lua | 128 | ||||
-rw-r--r-- | plugins/workspace.lua | 164 |
5 files changed, 63 insertions, 305 deletions
diff --git a/plugins/closeconfirmx.lua b/plugins/closeconfirmx.lua new file mode 100644 index 0000000..805fe3b --- /dev/null +++ b/plugins/closeconfirmx.lua @@ -0,0 +1,54 @@ +-- CloseConfirmX plugin for lite text editor +-- implementation by chekoopa + +local core = require "core" +local config = require "core.config" + +config.closeconfirmx_use_legacy = false +config.closeconfirmx_use_short_name = true + +local legacy_confirm = core.confirm_close_all + +local function commandful_confirm() + local dirty_count = 0 + local dirty_name + for _, doc in ipairs(core.docs) do + if doc:is_dirty() then + dirty_count = dirty_count + 1 + dirty_name = doc:get_name() + end + end + if dirty_count > 0 then + local text + if dirty_count == 1 then + if config.closeconfirmx_use_short_name then + dirty_name = dirty_name:match("[^/%\\]*$") + end + text = string.format("Unsaved changes in \"%s\"; Confirm Exit", dirty_name) + else + text = string.format("Unsaved changes in %d docs; Confirm Exit", dirty_count) + end + core.command_view:enter(text, function(_, item) + if item.text:match("^[cC]") then + core.quit(true) + end + end, function(text) + local items = {} + if not text:find("^[^sS]") then table.insert(items, "Stay here") end + if not text:find("^[^cC]") then table.insert(items, "Close Without Saving") end + return items + end) + -- as we delegate a choice inside the callback, + return false + end + return true +end + +function core.confirm_close_all() + if config.closeconfirmx_use_legacy then + return legacy_confirm() + else + return commandful_confirm() + end +end + diff --git a/plugins/inanimate.lua b/plugins/inanimate.lua deleted file mode 100644 index a01aa40..0000000 --- a/plugins/inanimate.lua +++ /dev/null @@ -1,12 +0,0 @@ -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 diff --git a/plugins/language_csharp.lua b/plugins/language_csharp.lua index 5e790e3..c40009c 100644 --- a/plugins/language_csharp.lua +++ b/plugins/language_csharp.lua @@ -21,9 +21,10 @@ syntax.add { { pattern = "[%a_][%w_]*", type = "symbol" }, }, symbols = { - -- keywords + -- keywords and contextual keywords ["abstract"] = "keyword", ["as"] = "keyword", + ["add"] = "keyword", ["await"] = "keyword", ["base"] = "keyword", ["break"] = "keyword", @@ -31,6 +32,7 @@ syntax.add { ["catch"] = "keyword", ["checked"] = "keyword", ["class"] = "keyword", + ["record"] = "keyword", ["const"] = "keyword", ["continue"] = "keyword", ["default"] = "keyword", @@ -59,9 +61,12 @@ syntax.add { ["operator"] = "keyword", ["out"] = "keyword", ["override"] = "keyword", + ["remove"] = "keyword", ["params"] = "keyword", + ["partial"] = "keyword", ["private"] = "keyword", ["protected"] = "keyword", + ["dynamic"] = "keyword", ["public"] = "keyword", ["readonly"] = "keyword", ["ref"] = "keyword", @@ -81,10 +86,13 @@ syntax.add { ["unsafe"] = "keyword", ["using"] = "keyword", ["var"] = "keyword", + ["value"] = "keyword", + ["global"] = "keyword", ["virtual"] = "keyword", ["void"] = "keyword", ["volatile"] = "keyword", ["where"] = "keyword", + ["when"] = "keyword", ["while"] = "keyword", ["yield"] = "keyword", -- types diff --git a/plugins/projectmanager.lua b/plugins/projectmanager.lua deleted file mode 100644 index b5a66e3..0000000 --- a/plugins/projectmanager.lua +++ /dev/null @@ -1,128 +0,0 @@ -local project_manager = {} - -local core = require "core" -local command = require "core.command" -local common = require "core.common" -local keymap = require "core.keymap" - -local projects_file = ".lite_projects.lua" - -project_manager.projects = {} - -local function load_projects() - local ok, t = pcall(dofile, EXEDIR .. "/" .. projects_file) - if ok then project_manager.projects = t end -end - -load_projects() - -local function serialize(val) - if type(val) == "string" then - return string.format("%q", val) - elseif type(val) == "table" then - local t = {} - for k, v in pairs(val) do - table.insert(t, "[" .. serialize(k) .. "]=" .. serialize(v)) - end - return "{" .. table.concat(t, ",") .. "}" - end - return tostring(val) -end - -local function save_projects() - local fp = io.open(EXEDIR .. "/" .. projects_file, "w") - if fp then - fp:write("return ", serialize(project_manager.projects), "\n") - fp:close() - end -end - -local function path_base_name(str) - local pattern = "[\\/]?([^\\/]+)[\\/]?$" - return str:match(pattern) -end - -function project_manager.add_project() - local proj_dir = system.absolute_path(".") - local proj_name = path_base_name(proj_dir) - core.command_view:set_text(proj_name) - core.command_view:enter("Project Name", - function(text) - if text then - project_manager.projects[text] = proj_dir - save_projects() - end - end) -end - -local function get_project_names() - local t = {} - for k, v in pairs(project_manager.projects) do table.insert(t, k) end - return t -end - -local function project_lister(func) - local projects = get_project_names(); - core.command_view:enter("Open Project", func, function(text) - local res = common.fuzzy_match(projects, text) - for i, name in ipairs(res) do - res[i] = { - text = name, - info = project_manager.projects[name], - } - end - return res - end) -end - -function project_manager.rename_project(func) - project_lister(function(text, item) - if item then - core.command_view:set_text(item.text) - core.command_view:enter("Rename ".. item.text, - function(_text) - if _text then - project_manager.projects[_text] = project_manager.projects[item.text] - project_manager.projects[item.text] = nil - save_projects() - end - end) - end - end) -end - -function project_manager.open_project() - project_lister(function(text, item) - if item then - system.exec(string.format("%q %q", EXEFILE, item.info)) - end - end) -end - -function project_manager.switch_project() - project_lister(function(text, item) - if item then - system.exec(string.format("%q %q", EXEFILE, item.info)) - os.exit() - end - end) -end - -function project_manager.remove_project() - project_lister(function(text, item) - if item then - project_manager.projects[item.text] = nil - save_projects() - end - end) -end - -command.add(nil, { - ["project-manager:open-project"] = project_manager.open_project, - ["project-manager:switch-project"] = project_manager.switch_project, - ["project-manager:add-project"] = project_manager.add_project, - ["project-manager:remove-project"] = project_manager.remove_project, - ["project-manager:rename-project"] = project_manager.rename_project, - }) - -return project_manager diff --git a/plugins/workspace.lua b/plugins/workspace.lua deleted file mode 100644 index 822291b..0000000 --- a/plugins/workspace.lua +++ /dev/null @@ -1,164 +0,0 @@ -local core = require "core" -local DocView = require "core.docview" - -local workspace_filename = ".lite_workspace.lua" - - -local function serialize(val) - if type(val) == "string" then - return string.format("%q", val) - elseif type(val) == "table" then - local t = {} - for k, v in pairs(val) do - table.insert(t, "[" .. serialize(k) .. "]=" .. serialize(v)) - end - return "{" .. table.concat(t, ",") .. "}" - end - return tostring(val) -end - - -local function has_no_locked_children(node) - if node.locked then return false end - if node.type == "leaf" then return true end - return has_no_locked_children(node.a) and has_no_locked_children(node.b) -end - - -local function get_unlocked_root(node) - if node.type == "leaf" then - return not node.locked and node - end - if has_no_locked_children(node) then - return node - end - return get_unlocked_root(node.a) or get_unlocked_root(node.b) -end - - -local function save_view(view) - local mt = getmetatable(view) - if mt == DocView then - return { - type = "doc", - active = (core.active_view == view), - filename = view.doc.filename, - selection = { view.doc:get_selection() }, - scroll = { x = view.scroll.to.x, y = view.scroll.to.y }, - text = not view.doc.filename and view.doc:get_text(1, 1, math.huge, math.huge) - } - end - for name, mod in pairs(package.loaded) do - if mod == mt then - return { - type = "view", - active = (core.active_view == view), - module = name - } - end - end -end - - -local function load_view(t) - if t.type == "doc" then - local ok, doc = pcall(core.open_doc, t.filename) - if not ok then - return DocView(core.open_doc()) - end - local dv = DocView(doc) - if t.text then doc:insert(1, 1, t.text) end - doc:set_selection(table.unpack(t.selection)) - dv.last_line, dv.last_col = doc:get_selection() - dv.scroll.x, dv.scroll.to.x = t.scroll.x, t.scroll.x - dv.scroll.y, dv.scroll.to.y = t.scroll.y, t.scroll.y - return dv - end - return require(t.module)() -end - - -local function save_node(node) - local res = {} - res.type = node.type - if node.type == "leaf" then - res.views = {} - for _, view in ipairs(node.views) do - local t = save_view(view) - if t then - table.insert(res.views, t) - if node.active_view == view then - res.active_view = #res.views - end - end - end - else - res.divider = node.divider - res.a = save_node(node.a) - res.b = save_node(node.b) - end - return res -end - - -local function load_node(node, t) - if t.type == "leaf" then - local res - for _, v in ipairs(t.views) do - local view = load_view(v) - if v.active then res = view end - node:add_view(view) - end - if t.active_view then - node:set_active_view(node.views[t.active_view]) - end - return res - else - node:split(t.type == "hsplit" and "right" or "down") - node.divider = t.divider - local res1 = load_node(node.a, t.a) - local res2 = load_node(node.b, t.b) - return res1 or res2 - end -end - - -local function save_workspace() - local root = get_unlocked_root(core.root_view.root_node) - local fp = io.open(workspace_filename, "w") - if fp then - fp:write("return ", serialize(save_node(root)), "\n") - fp:close() - end -end - - -local function load_workspace() - local ok, t = pcall(dofile, workspace_filename) - os.remove(workspace_filename) - if ok then - local root = get_unlocked_root(core.root_view.root_node) - local active_view = load_node(root, t) - if active_view then - core.set_active_view(active_view) - end - end -end - - -local run = core.run - -function core.run(...) - if #core.docs == 0 then - core.try(load_workspace) - - local original_on_quit = core.on_quit - function core.on_quit() - save_workspace() - original_on_quit() - end - end - - core.run = run - return core.run(...) -end |