From 536a0ce054319d2ea92c665510afe8a388b043ca Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Thu, 8 Apr 2021 16:21:43 +0200 Subject: More validated plugins --- plugins/centerdoc.lua | 1 + plugins/closeconfirmx.lua | 54 ------------------------------------- plugins/colorpreview.lua | 1 + plugins/copyfilelocation.lua | 8 +++--- plugins/datetimestamps.lua | 1 + plugins/detectindent.lua | 64 -------------------------------------------- plugins/dragdropselected.lua | 1 + plugins/drawwhitespace.lua | 38 -------------------------- 8 files changed, 8 insertions(+), 160 deletions(-) delete mode 100644 plugins/closeconfirmx.lua delete mode 100644 plugins/detectindent.lua delete mode 100644 plugins/drawwhitespace.lua (limited to 'plugins') diff --git a/plugins/centerdoc.lua b/plugins/centerdoc.lua index 1921467..ee4bb2b 100644 --- a/plugins/centerdoc.lua +++ b/plugins/centerdoc.lua @@ -1,3 +1,4 @@ +-- lite-xl 1.16 local config = require "core.config" local DocView = require "core.docview" diff --git a/plugins/closeconfirmx.lua b/plugins/closeconfirmx.lua deleted file mode 100644 index 805fe3b..0000000 --- a/plugins/closeconfirmx.lua +++ /dev/null @@ -1,54 +0,0 @@ --- 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/colorpreview.lua b/plugins/colorpreview.lua index dca419c..1289357 100644 --- a/plugins/colorpreview.lua +++ b/plugins/colorpreview.lua @@ -1,3 +1,4 @@ +-- lite-xl 1.16 local common = require "core.common" local DocView = require "core.docview" diff --git a/plugins/copyfilelocation.lua b/plugins/copyfilelocation.lua index d365240..48520b8 100644 --- a/plugins/copyfilelocation.lua +++ b/plugins/copyfilelocation.lua @@ -1,3 +1,4 @@ +-- lite-xl 1.16 local core = require "core" local command = require "core.command" local config = require "core.config" @@ -6,12 +7,11 @@ 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 + if not doc.abs_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) + core.log("Copying to clipboard \"%s\"", doc.abs_filename) + system.set_clipboard(doc.abs_filename) end }) diff --git a/plugins/datetimestamps.lua b/plugins/datetimestamps.lua index 518f0a9..e1d7d3b 100644 --- a/plugins/datetimestamps.lua +++ b/plugins/datetimestamps.lua @@ -1,3 +1,4 @@ +-- lite-xl 1.16 local core = require "core" local config = require "core.config" local command = require "core.command" diff --git a/plugins/detectindent.lua b/plugins/detectindent.lua deleted file mode 100644 index 9c473b5..0000000 --- a/plugins/detectindent.lua +++ /dev/null @@ -1,64 +0,0 @@ -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 - diff --git a/plugins/dragdropselected.lua b/plugins/dragdropselected.lua index a2ce67f..5364fa4 100644 --- a/plugins/dragdropselected.lua +++ b/plugins/dragdropselected.lua @@ -1,3 +1,4 @@ +-- lite-xl 1.16 --[[ dragdropselected.lua provides basic drag and drop of selected text (in same document) diff --git a/plugins/drawwhitespace.lua b/plugins/drawwhitespace.lua deleted file mode 100644 index 4e2e109..0000000 --- a/plugins/drawwhitespace.lua +++ /dev/null @@ -1,38 +0,0 @@ -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 font = self:get_font() - local ss = font:subpixel_scale() - local tx, ty = ss * x, y + self:get_line_text_y_offset() - 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_subpixel(font, rep, tx, ty, color) - end - tx = tx + font:get_width_subpixel(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, -}) -- cgit v1.2.3