diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/ephemeraldocviews.lua | 45 | ||||
-rw-r--r-- | plugins/language_bib.lua | 22 | ||||
-rw-r--r-- | plugins/language_po.lua | 20 | ||||
-rw-r--r-- | plugins/language_tcl.lua | 68 | ||||
-rw-r--r-- | plugins/lfautoinsert.lua | 60 | ||||
-rw-r--r-- | plugins/navigate.lua | 60 | ||||
-rw-r--r-- | plugins/pdfview.lua | 45 | ||||
-rw-r--r-- | plugins/texcompile.lua | 44 |
8 files changed, 339 insertions, 25 deletions
diff --git a/plugins/ephemeraldocviews.lua b/plugins/ephemeraldocviews.lua new file mode 100644 index 0000000..37b3a3b --- /dev/null +++ b/plugins/ephemeraldocviews.lua @@ -0,0 +1,45 @@ +-- mod-version:1 -- lite-xl 1.16 +local core = require "core" +local command = require "core.command" +local RootView = require "core.rootview" +local DocView = require "core.docview" +local Doc = require "core.doc" + +local open_doc = RootView.open_doc +function RootView:open_doc(doc) + local node = self:get_active_node_default() + local ephemeral, existing_ephemeral = node.views, nil + for i, view in ipairs(node.views) do + if view.doc == doc then + ephemeral = false + end + if view.doc and view.doc.ephemeral then + existing_ephemeral = view + end + end + if ephemeral and existing_ephemeral then + node:close_view(self.root_node, existing_ephemeral) + end + local view = open_doc(self, doc) + if ephemeral then + view.doc.ephemeral = #node.views > 1 + end + return view +end + +local get_name = DocView.get_name +function DocView:get_name() + return self.doc and self.doc.ephemeral and ("-- " .. get_name(self) .. " --") or get_name(self) +end + +local doc_insert = Doc.insert +function Doc:insert(...) + doc_insert(self, ...) + self.ephemeral = false +end + +local doc_remove = Doc.remove +function Doc:remove(...) + doc_remove(self, ...) + self.ephemeral = false +end diff --git a/plugins/language_bib.lua b/plugins/language_bib.lua new file mode 100644 index 0000000..08a5662 --- /dev/null +++ b/plugins/language_bib.lua @@ -0,0 +1,22 @@ +-- mod-version:1 -- lite-xl 1.16 +local syntax = require "core.syntax" + +syntax.add { + files = { "%.bib$" }, + comment = "%%", + patterns = { + { pattern = {"%%", "\n"}, type = "comment" }, + { pattern = "@%a+", type = "keyword" }, + { pattern = "%a+%s=", type = "keyword2" }, + }, + symbols = { + ["author"] = "keyword", + ["doi"] = "keyword", + ["issue"] = "keyword", + ["journal"] = "keyword", + ["month"] = "keyword", + ["numpages"] = "keyword", + ["pages"] = "keyword", + ["publisher"] = "keyword", + } +} diff --git a/plugins/language_po.lua b/plugins/language_po.lua new file mode 100644 index 0000000..0f07d40 --- /dev/null +++ b/plugins/language_po.lua @@ -0,0 +1,20 @@ +-- mod-version:1 -- lite-xl 1.16 +local syntax = require "core.syntax" + +syntax.add { + files = { "%.po$", "%.pot$" }, + comment = "#", + patterns = { + { pattern = { "#", "\n"}, type = "comment" }, + { pattern = { '"', '"', '\\' }, type = "string" }, + { pattern = "[%[%]]", type = "operator" }, + { pattern = "%d+", type = "number" }, + { pattern = "[%a_][%w_]*", type = "symbol" }, + }, + symbols = { + ["msgctxt"] = "keyword", + ["msgid"] = "keyword", + ["msgid_plural"] = "keyword", + ["msgstr"] = "keyword", + }, +} diff --git a/plugins/language_tcl.lua b/plugins/language_tcl.lua new file mode 100644 index 0000000..31efa84 --- /dev/null +++ b/plugins/language_tcl.lua @@ -0,0 +1,68 @@ +-- mod-version:1 -- lite-xl 1.16 +local syntax = require "core.syntax" + +syntax.add { + files = { "%.tcl$" }, + comment = "#", + patterns = { + { pattern = "#.-\n", type = "comment" }, + { pattern = { '"', '"', '\\' }, type = "string" }, + { pattern = "0x%x+", type = "number" }, + { pattern = "%d+[%d%.eE]*f?", type = "number" }, + { pattern = "%.?%d+f?", type = "number" }, + { pattern = "%$[%a_][%w_]*", type = "literal" }, + { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" }, + { pattern = "::[%a_][%w_]*", type = "function" }, + { pattern = "[%a_][%w_]*%f[:]", type = "function" }, + { pattern = "[%a_][%w_]*", type = "symbol" }, + }, + symbols = { + ["set"] = "keyword", + ["unset"] = "keyword", + ["rename"] = "keyword", + ["upvar"] = "keyword", + ["incr"] = "keyword", + ["source"] = "keyword", + ["expr"] = "keyword", + ["gets"] = "keyword", + ["puts"] = "keyword", + ["package"] = "keyword", + ["list"] = "keyword", + ["dict"] = "keyword", + ["split"] = "join", + ["concat"] = "join", + ["lappend"] = "keyword", + ["lset"] = "keyword", + ["lassign"] = "keyword", + ["lindex"] = "keyword", + ["llength"] = "keyword", + ["lsearch"] = "keyword", + ["lrange"] = "keyword", + ["linsert"] = "keyword", + ["lreplace"] = "keyword", + ["lrepeat"] = "keyword", + ["lsort"] = "keyword", + ["lreverse"] = "keyword", + ["array"] = "keyword", + ["concat"] = "keyword", + ["regexp"] = "keyword", + ["for"] = "keyword", + ["foreach"] = "keyword", + ["while"] = "keyword", + ["case"] = "keyword", + ["proc"] = "keyword", + ["if"] = "keyword", + ["else"] = "keyword", + ["elseif"] = "keyword", + ["break"] = "keyword", + ["continue"] = "keyword", + ["return"] = "keyword", + ["eval"] = "keyword", + ["try"] = "keyword2", + ["on"] = "keyword2", + ["finally"] = "keyword2", + ["throw"] = "keyword2", + ["error"] = "keyword2", + }, +} + diff --git a/plugins/lfautoinsert.lua b/plugins/lfautoinsert.lua index 99f7e45..0534aa8 100644 --- a/plugins/lfautoinsert.lua +++ b/plugins/lfautoinsert.lua @@ -1,6 +1,7 @@ -- mod-version:1 -- lite-xl 1.16 local core = require "core" local command = require "core.command" +local common = require "core.common" local config = require "core.config" local keymap = require "core.keymap" @@ -8,20 +9,52 @@ 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*\n"] = false, ["^%s*<([^/][^%s>]*)[^>]*>%s*\n"] = "</$TEXT>", ["/%*%s*\n"] = "*/", + ["c/c++"] = { + file_patterns = { + "%.c$", "%.h$", "%.inl$", "%.cpp$", "%.hpp$", + "%.cc$", "%.C$", "%.cxx$", "%.c++$", "%.hh$", + "%.H$", "%.hxx$", "%.h++$" + }, + map = { + ["^#if.*\n"] = "#endif", + ["^#else.*\n"] = "#endif", + } + }, + ["lua"] = { + file_patterns = { "%.lua$" }, + map = { + ["%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*\n"] = "]]" + } + }, } +local function get_autoinsert_map(filename) + local map = {} + for pattern, closing in pairs(config.lfautoinsert_map) do + if type(closing) == "table" then + if common.match_pattern(filename, closing.file_patterns) then + for p, e in pairs(closing.map) do + map[p] = e + end + end + else + map[pattern] = closing + end + end + + return map +end + local function indent_size(doc, line) local text = doc.lines[line] or "" @@ -37,7 +70,7 @@ command.add("core.docview", { local line, col = doc:get_selection() local text = doc.lines[line - 1] - for ptn, close in pairs(config.lfautoinsert_map) do + for ptn, close in pairs(get_autoinsert_map(doc.filename)) do local s, _, str = text:find(ptn) if s then if close @@ -64,3 +97,12 @@ command.add("core.docview", { keymap.add { ["return"] = { "command:submit", "autoinsert:newline" } } + +return { + add = function(file_patterns, map) + table.insert( + config.lfautoinsert_map, + { file_patterns = file_patterns, map=map } + ) + end +} diff --git a/plugins/navigate.lua b/plugins/navigate.lua index 2bf4396..dd985b5 100644 --- a/plugins/navigate.lua +++ b/plugins/navigate.lua @@ -3,8 +3,8 @@ local core = require "core" local common = require "core.common" local command = require "core.command" -local config = require "core.config" local keymap = require "core.keymap" +local Doc = require "core.doc" local DocView = require "core.docview" local navigate = { @@ -23,15 +23,37 @@ local function get_active_view() return nil end +-- Solution to safely remove elements from array table: +-- found at https://stackoverflow.com/a/53038524 +local function array_remove(t, fnKeep) + local j, n = 1, #t; + + for i=1, n do + if (fnKeep(t, i, j)) then + if (i ~= j) then + t[j] = t[i]; + t[i] = nil; + end + j = j + 1; + else + t[i] = nil; + end + end + + return t; +end + local function add(doc) -- Make new navigation point last in list if navigate.index > 0 and navigate.index < #navigate.list then - local list_len = #navigate.list - for index=navigate.index+1, list_len, 1 do - if navigate.list[index] then - table.remove(navigate.list, index) + local remove_start = navigate.index + 1 + local remove_end = #navigate.list + array_remove(navigate.list, function(_, i) + if i >= remove_start and i <= remove_end then + return false end - end + return true + end) end local line, col = doc:get_selection() @@ -106,17 +128,23 @@ core.add_thread(function() end end) -core.add_close_hook(function(doc) - local filename = doc.filename - local list = {table.unpack(navigate.list)} - for index, position in ipairs(list) do - if position.filename == filename then - if navigate.list[index] then - table.remove(navigate.list, index) - end +-- +-- Patching +-- +local doc_on_close = Doc.on_close + +function Doc:on_close() + local filename = self.filename + -- remove all positions referencing closed file + array_remove(navigate.list, function(t, i) + if t[i].filename == filename then + return false end - end -end) + return true + end) + + doc_on_close(self) +end -- -- Commands diff --git a/plugins/pdfview.lua b/plugins/pdfview.lua new file mode 100644 index 0000000..743c6ec --- /dev/null +++ b/plugins/pdfview.lua @@ -0,0 +1,45 @@ +-- mod-version:1 -- lite-xl 1.16 +local core = require "core" +local command = require "core.command" +local keymap = require "core.keymap" + +command.add("core.docview", { + ["pdfview:show-preview"] = function() + local av = core.active_view + +-- User's home directory + local homedir = "" + + if PLATFORM == "Windows" then + homedir = os.getenv("USERPROFILE") + else + homedir = os.getenv("HOME") + end + +-- The current (La)TeX file + local texfile = av:get_filename() + texfile = string.gsub(texfile, '~', homedir) +-- Construct the PDF file name out of the (La)Tex filename + local pdffile = "\"" .. string.gsub(texfile, ".tex", ".pdf") .. "\"" +-- PDF viewer - is there any provided by the environment + local pdfcmd = os.getenv("LITE_PDF_VIEWER") + + core.log("Opening pdf preview for \"%s\"", texfile) + + if pdfcmd ~= nil then + system.exec(pdfcmd .. " " .. pdffile) + elseif PLATFORM == "Windows" then + system.exec("start " .. pdffile) + else + system.exec(string.format("xdg-open %q", pdffile)) + end + +-- core.add_thread(function() +-- coroutine.yield(5) +-- os.remove(htmlfile) +-- end) + end +}) + + +keymap.add { ["ctrl+shift+v"] = "pdfview:show-preview" } diff --git a/plugins/texcompile.lua b/plugins/texcompile.lua new file mode 100644 index 0000000..7a5fd6e --- /dev/null +++ b/plugins/texcompile.lua @@ -0,0 +1,44 @@ +-- mod-version:1 -- lite-xl 1.16 +local core = require "core" +local command = require "core.command" +local keymap = require "core.keymap" + +command.add("core.docview", { + ["texcompile:tex-compile"] = function() + local av = core.active_view + +-- User's home directory + local homedir = "" + + if PLATFORM == "Windows" then + homedir = os.getenv("USERPROFILE") + else + homedir = os.getenv("HOME") + end + +-- The current (La)TeX file and path + local texname = av:get_name() + local texpath = av:get_filename() + texpath = string.gsub(texpath, '~', homedir) + texpath = string.gsub(texpath, texname, '') + +-- LaTeX compiler - is there any provided by the environment + local texcmd = os.getenv("LITE_LATEX_COMPILER") + + if texcmd == nil then + core.log("No LaTeX compiler found") + else + core.log("LaTeX compiler is %s, compiling %s", texcmd, texname) + + system.exec(string.format("cd %q && %q %q", texpath, texcmd, texname)) + end + +-- core.add_thread(function() +-- coroutine.yield(5) +-- os.remove(htmlfile) +-- end) + end +}) + + +keymap.add { ["ctrl+shift+t"] = "texcompile:tex-compile" } |