diff options
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | plugins/autoinsert.lua | 27 | ||||
-rw-r--r-- | plugins/workspace.lua | 23 |
3 files changed, 44 insertions, 7 deletions
@@ -33,6 +33,7 @@ Plugin | Description [`language_batch`](plugins/language_batch.lua?raw=1) | Syntax for Windows [Batch Files](https://en.wikipedia.org/wiki/Batch_file) [`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_java`](plugins/language_java.lua?raw=1) | Syntax for the [Java](https://en.wikipedia.org/wiki/Java_(programming_language)) programming language [`language_d`](plugins/language_d.lua?raw=1) | Syntax for the [D](https://dlang.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 diff --git a/plugins/autoinsert.lua b/plugins/autoinsert.lua index a3c8f98..0bf5a5a 100644 --- a/plugins/autoinsert.lua +++ b/plugins/autoinsert.lua @@ -1,4 +1,5 @@ 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" @@ -60,7 +61,13 @@ function DocView:on_text_input(text) end -command.add("core.docview", { + +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() @@ -70,6 +77,22 @@ command.add("core.docview", { 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" } +keymap.add { + ["backspace"] = "autoinsert:backspace", + ["ctrl+backspace"] = "autoinsert:delete-to-previous-word-start", + ["ctrl+shift+backspace"] = "autoinsert:delete-to-previous-word-start", +} diff --git a/plugins/workspace.lua b/plugins/workspace.lua index b40ab4b..8f8dfcc 100644 --- a/plugins/workspace.lua +++ b/plugins/workspace.lua @@ -41,6 +41,7 @@ local function save_view(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 }, @@ -49,7 +50,11 @@ local function save_view(view) end for name, mod in pairs(package.loaded) do if mod == mt then - return { type = "view", module = name } + return { + type = "view", + active = (core.active_view == view), + module = name + } end end end @@ -98,17 +103,22 @@ end local function load_node(node, t) if t.type == "leaf" then + local res for _, v in ipairs(t.views) do - node:add_view(load_view(v)) + 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 - load_node(node.a, t.a) - load_node(node.b, t.b) + local res1 = load_node(node.a, t.a) + local res2 = load_node(node.b, t.b) + return res1 or res2 end end @@ -126,7 +136,10 @@ local function load_workspace() os.remove(workspace_filename) if ok then local root = get_unlocked_root(core.root_view.root_node) - load_node(root, t) + local active_view = load_node(root, t) + if active_view then + core.set_active_view(active_view) + end end end |