diff options
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | plugins/language_bib.lua | 22 | ||||
-rw-r--r-- | plugins/lfautoinsert.lua | 60 | ||||
-rw-r--r-- | plugins/pdfview.lua | 45 | ||||
-rw-r--r-- | plugins/texcompile.lua | 44 |
5 files changed, 165 insertions, 9 deletions
@@ -45,6 +45,7 @@ Plugin | Description *[`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_bib`](plugins/language_bib.lua?raw=1) | Syntax for [BibTex](https://en.wikipedia.org/wiki/BibTeX) files [`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 @@ -99,6 +100,7 @@ Plugin | Description [`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)~~ | Integrated in lite-xl with improvements ~~Save projects and load/reload them quickly~~ +[`pdfview`](plugins/pdfview.lua?raw=1) | PDF preview for TeX files [`rainbowparen`](plugins/rainbowparen.lua?raw=1) | Show nesting of parentheses with rainbow colours [`restoretabs`](plugins/restoretabs.lua?raw=1) | Keep a list of recently closed tabs, and restore the tab in order on cntrl+shift+t. [`regexreplaceplugin`](plugins/regexreplaceplugin.lua?raw=1) | Allows for you to write a regex and its replacement in one go, and live preview the results. @@ -108,6 +110,7 @@ Plugin | Description [`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* [`tabnumbers`](plugins/tabnumbers.lua?raw=1) | Displays tab numbers from 1–9 next to their names *([screenshot](https://user-images.githubusercontent.com/16415678/101285362-007a8500-37e5-11eb-869b-c10eb9d9d902.png)) +[`texcompile`](plugins/texcompile.lua?raw=1) | Compile Tex files into PDF [`theme16`](https://github.com/monolifed/theme16)* | Theme manager with base16 themes [`themescheduler`](https://github.com/BenStigsen/lite-config/blob/main/plugins/themescheduler.lua?raw=1) | Schedule themes to be used at certain times [`themeselect`](plugins/themeselect.lua?raw=1) | Select a theme based on filename of active document 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/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/pdfview.lua b/plugins/pdfview.lua new file mode 100644 index 0000000..41e8ad0 --- /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" } |