diff options
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | plugins/autowrap.lua | 1 | ||||
-rw-r--r-- | plugins/language_R.lua | 39 | ||||
-rw-r--r-- | plugins/language_java.lua | 106 | ||||
-rw-r--r-- | plugins/language_lobster.lua | 2 | ||||
-rw-r--r-- | plugins/language_php.lua | 177 | ||||
-rw-r--r-- | plugins/language_phps.lua | 140 | ||||
-rw-r--r-- | plugins/language_rescript.lua | 59 | ||||
-rw-r--r-- | plugins/language_tex.lua | 23 | ||||
-rw-r--r-- | plugins/language_toml.lua | 2 | ||||
-rw-r--r-- | plugins/linenumbers.lua | 2 | ||||
-rw-r--r-- | plugins/minimap.lua | 7 | ||||
-rw-r--r-- | plugins/open_ext.lua | 187 | ||||
-rw-r--r-- | plugins/texcompile.lua | 169 |
14 files changed, 692 insertions, 225 deletions
@@ -82,6 +82,8 @@ Plugin | Description [`language_pony`*](https://github.com/MrAnyx/lite-plugin-pony) | Syntax for [Pony](https://www.ponylang.io/) programming language [`language_powershell`](plugins/language_powershell.lua?raw=1) | Syntax for [PowerShell](https://docs.microsoft.com/en-us/powershell) scripting language [`language_psql`](plugins/language_psql.lua?raw=1) | Syntax for the postgresql database access language +[`language_r`](plugins/language_R.lua?raw=1) | Syntax for [R](https://www.r-project.org/) scripting language +[`language_rescript`](plugins/language_rescript.lua?raw=1) | Syntax for the [ReScript](https://rescript-lang.org/) programming language [`language_rust`](plugins/language_rust.lua?raw=1) | Syntax for the [Rust](https://rust-lang.org/) programming language [`language_ruby`](plugins/language_ruby.lua?raw=1) | Syntax for the [Ruby](https://www.ruby-lang.org/) programming language [`language sass`](plugins/language_sass.lua?raw=1) | Syntax for the [Sass](https://sass-lang.com/) CSS preprocessor @@ -110,6 +112,7 @@ Plugin | Description [`motiontrail`](plugins/motiontrail.lua?raw=1) | Adds a motion-trail to the caret *([screenshot](https://user-images.githubusercontent.com/3920290/83256814-085ccb00-a1ab-11ea-9e35-e6633cbed1a9.gif))* ~~[`nagbar`](https://github.com/takase1121/lite-nagbar)*~~ | integrated in lite-xl ~~consistent and _beautiful_ confirmation dialogs for lite and lite-xl *([gif](https://raw.githubusercontent.com/takase1121/lite-nagbar/master/assets/preview.gif))*~~ [`navigate`](plugins/navigate.lua?raw=1) | Allows moving back and forward between document positions, reducing the amount of scrolling +[`open_ext`](plugins/open_ext.lua?raw=1) | Automatically prompts you if you tried to open a binary file in the editor [`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~~ diff --git a/plugins/autowrap.lua b/plugins/autowrap.lua index 38f8eb3..c9dde6d 100644 --- a/plugins/autowrap.lua +++ b/plugins/autowrap.lua @@ -32,5 +32,6 @@ DocView.on_text_input = function(self, ...) command.perform("reflow:reflow") command.perform("doc:move-to-next-char") command.perform("doc:move-to-previous-char") + command.perform("doc:move-to-end-of-line") end end diff --git a/plugins/language_R.lua b/plugins/language_R.lua new file mode 100644 index 0000000..68c3a18 --- /dev/null +++ b/plugins/language_R.lua @@ -0,0 +1,39 @@ +-- mod-version:2 -- lite-xl 2.0 +local syntax = require "core.syntax" + +syntax.add{ + files = {"%.r$", "%.rds$", "%.rda$", "%.rdata$", "%.R$"}, + comment = "#", + patterns = { + {pattern = {"#", "\n"}, type = "comment"}, + {pattern = {'"', '"'}, type = "string"}, + {pattern = {"'", "'"}, type = "string"}, + {pattern = "[%a_][%w_]*%f[(]", type = "function"}, + {pattern = "[%a_][%w_]*", type = "symbol"}, + {pattern = "[%+%-=/%*%^%%<>!|&]", type = "operator"}, + {pattern = "0x[%da-fA-F]+", type = "number"}, + {pattern = "-?%d+[%d%.eE]*", type = "number"}, + {pattern = "-?%.?%d+", type = "number"}, + + }, + symbols = { + ["TRUE"] = "literal", + ["FALSE"] = "literal", + ["NA"] = "literal", + ["NULL"] = "literal", + ["Inf"] = "literal", + ["if"] = "keyword", + ["else"] = "keyword", + ["while"] = "keyword", + ["function"] = "keyword", + ["break"] = "keyword", + ["next"] = "keyword", + ["repeat"] = "keyword", + ["in"] = "keyword", + ["for"] = "keyword", + ["NA_integer"] = "keyword", + ["NA_complex"] = "keyword", + ["NA_character"] = "keyword", + ["NA_real"] = "keyword" + } +} diff --git a/plugins/language_java.lua b/plugins/language_java.lua index 8c6e98e..e6d3735 100644 --- a/plugins/language_java.lua +++ b/plugins/language_java.lua @@ -20,55 +20,63 @@ syntax.add { { pattern = "[%a_][%w_]*", type = "symbol" }, }, symbols = { - ["if"] = "keyword", - ["then"] = "keyword", - ["else"] = "keyword", - ["else if"] = "keyword", - ["do"] = "keyword", - ["while"] = "keyword", - ["for"] = "keyword", - ["new"] = "keyword", - ["break"] = "keyword", - ["continue"] = "keyword", - ["return"] = "keyword", - ["goto"] = "keyword", - ["class"] = "keyword", - ["implements"] = "keyword", - ["extends"] = "keyword", - ["private"] = "keyword", - ["protected"] = "keyword", - ["public"] = "keyword", - ["abstract"] = "keyword", - ["interface"] = "keyword", - ["assert"] = "keyword", - ["import"] = "keyword", - ["native"] = "keyword", - ["package"] = "keyword", - ["super"] = "keyword", - ["synchronized"] = "keyword", - ["instanceof"] = "keyword", - ["enum"] = "keyword", - ["catch"] = "keyword", - ["throw"] = "keyword", - ["throws"] = "keyword", - ["try"] = "keyword", - ["transient"] = "keyword", - ["finally"] = "keyword", - ["static"] = "keyword", - ["volatile"] = "keyword", - ["final"] = "keyword", - ["switch"] = "keyword", - ["case"] = "keyword", - ["default"] = "keyword", - ["void"] = "keyword", - ["int"] = "keyword2", - ["short"] = "keyword2", - ["byte"] = "keyword2", - ["long"] = "keyword2", - ["float"] = "keyword2", - ["double"] = "keyword2", - ["char"] = "keyword2", - ["boolean"] = "keyword2", + ["abstract"] = "keyword", + ["assert"] = "keyword", + ["break"] = "keyword", + ["case"] = "keyword", + ["catch"] = "keyword", + ["class"] = "keyword", + ["const"] = "keyword", + ["continue"] = "keyword", + ["default"] = "keyword", + ["do"] = "keyword", + ["else"] = "keyword", + ["enum"] = "keyword", + ["extends"] = "keyword", + ["final"] = "keyword", + ["finally"] = "keyword", + ["for"] = "keyword", + ["if"] = "keyword", + ["goto"] = "keyword", + ["implements"] = "keyword", + ["import"] = "keyword", + ["instanceof"] = "keyword", + ["interface"] = "keyword", + ["native"] = "keyword", + ["new"] = "keyword", + ["package"] = "keyword", + ["permits"] = "keyword", + ["private"] = "keyword", + ["protected"] = "keyword", + ["public"] = "keyword", + ["record"] = "keyword", + ["return"] = "keyword", + ["sealed"] = "keyword", + ["static"] = "keyword", + ["strictfp"] = "keyword", + ["super"] = "keyword", + ["switch"] = "keyword", + ["synchronized"] = "keyword", + ["this"] = "keyword", + ["throw"] = "keyword", + ["throws"] = "keyword", + ["transient"] = "keyword", + ["try"] = "keyword", + ["var"] = "keyword", + ["void"] = "keyword", + ["volatile"] = "keyword", + ["while"] = "keyword", + ["yield"] = "keyword", + + ["boolean"] = "keyword2", + ["byte"] = "keyword2", + ["char"] = "keyword2", + ["double"] = "keyword2", + ["float"] = "keyword2", + ["int"] = "keyword2", + ["long"] = "keyword2", + ["short"] = "keyword2", + ["true"] = "literal", ["false"] = "literal", ["null"] = "literal", diff --git a/plugins/language_lobster.lua b/plugins/language_lobster.lua index 8b4d899..593c89d 100644 --- a/plugins/language_lobster.lua +++ b/plugins/language_lobster.lua @@ -1,4 +1,4 @@ --- mod-version:1 -- lite-xl 1.16 +-- mod-version:2 -- lite-xl 2.0 local syntax = require "core.syntax" syntax.add { diff --git a/plugins/language_php.lua b/plugins/language_php.lua index 4f107aa..5ee6a93 100644 --- a/plugins/language_php.lua +++ b/plugins/language_php.lua @@ -1,13 +1,149 @@ -- mod-version:2 -- lite-xl 2.0 --[[ - language_php.lua - provides php syntax support allowing mixed html, css and js - version: 20210513_144200 - - Depends on plugin language_phps.lua version >= 20210512_181200 + language_php.lua + provides php syntax support allowing mixed html, css and js + version: 20210902_1 --]] local syntax = require "core.syntax" +-- load syntax dependencies to add additional rules +require "plugins.language_css" +require "plugins.language_js" + +-- define the core php syntax coloring +syntax.add { + files = { "%.phps$" }, + headers = "^<%?php", + comment = "//", + patterns = { + -- Attributes + { pattern = {"#%[", "%]"}, type = "normal" }, + -- Comments + { pattern = "//.-\n", type = "comment" }, + { pattern = "#.-\n", type = "comment" }, + { pattern = { "/%*", "%*/" }, type = "comment" }, + -- The '\\' is for escaping to work on " or ' + { pattern = { '"', '"', '\\' }, type = "string" }, + { pattern = { "'", "'", '\\' }, type = "string" }, + { pattern = "0[bB][%d]+", type = "number" }, + { pattern = "0[xX][%da-fA-F]+", type = "number" }, + { pattern = "-?%d[%d_%.eE]*", type = "number" }, + { pattern = "-?%.?%d+", type = "number" }, + { pattern = "[%.%+%-=/%*%^%%<>!~|&%?:]", type = "operator" }, + -- Variables + { pattern = "%$[%w_]+", type = "keyword2" }, + -- Respect control structures, treat as keyword not function + { pattern = "if[%s]*%f[(]", type = "keyword" }, + { pattern = "else[%s]*%f[(]", type = "keyword" }, + { pattern = "elseif[%s]*%f[(]", type = "keyword" }, + { pattern = "for[%s]*%f[(]", type = "keyword" }, + { pattern = "foreach[%s]*%f[(]", type = "keyword" }, + { pattern = "while[%s]*%f[(]", type = "keyword" }, + { pattern = "catch[%s]*%f[(]", type = "keyword" }, + { pattern = "switch[%s]*%f[(]", type = "keyword" }, + { pattern = "match[%s]*%f[(]", type = "keyword" }, + { pattern = "fn[%s]*%f[(]", type = "keyword" }, + -- All functions that aren't control structures + { pattern = "[%a_][%w_]*[%s]*%f[(]", type = "function" }, + -- Array type hint not added on symbols to also make it work + -- as a function call + { pattern = "array", type = "literal" }, + -- Match static or namespace container on sub element access + { pattern = "[%a_][%w_]*[%s]*%f[:]", type = "literal" }, + -- Uppercase constants of at least 3 characters in len + { pattern = "%u[%u_][%u%d_]+", type = "number" }, + -- Magic constants + { pattern = "__[%u]+__", type = "number" }, + -- Everything else + { pattern = "[%a_][%w_]*", type = "symbol" }, + }, + symbols = { + ["return"] = "keyword", + ["if"] = "keyword", + ["else"] = "keyword", + ["elseif"] = "keyword", + ["endif"] = "keyword", + ["declare"] = "keyword", + ["enddeclare"] = "keyword", + ["switch"] = "keyword", + ["endswitch"] = "keyword", + ["as"] = "keyword", + ["do"] = "keyword", + ["for"] = "keyword", + ["endfor"] = "keyword", + ["foreach"] = "keyword", + ["endforeach"] = "keyword", + ["while"] = "keyword", + ["endwhile"] = "keyword", + ["match"] = "keyword", + ["case"] = "keyword", + ["continue"] = "keyword", + ["default"] = "keyword", + ["break"] = "keyword", + ["goto"] = "keyword", + + ["try"] = "keyword", + ["catch"] = "keyword", + ["throw"] = "keyword", + ["finally"] = "keyword", + + ["class"] = "keyword", + ["trait"] = "keyword", + ["interface"] = "keyword", + ["public"] = "keyword", + ["static"] = "keyword", + ["protected"] = "keyword", + ["private"] = "keyword", + ["abstract"] = "keyword", + ["final"] = "keyword", + ["$this"] = "literal", + + ["function"] = "keyword", + ["fn"] = "keyword", + ["global"] = "keyword", + ["var"] = "keyword", + ["const"] = "keyword", + + ["bool"] = "literal", + ["boolean"] = "literal", + ["int"] = "literal", + ["integer"] = "literal", + ["real"] = "literal", + ["double"] = "literal", + ["float"] = "literal", + ["string"] = "literal", + ["object"] = "literal", + ["callable"] = "literal", + ["iterable"] = "literal", + ["void"] = "literal", + ["parent"] = "literal", + ["self"] = "literal", + ["mixed"] = "literal", + + ["namespace"] = "keyword", + ["extends"] = "keyword", + ["implements"] = "keyword", + ["instanceof"] = "keyword", + ["require"] = "keyword", + ["require_once"] = "keyword", + ["include"] = "keyword", + ["include_once"] = "keyword", + ["use"] = "keyword", + ["new"] = "keyword", + ["clone"] = "keyword", + + ["true"] = "number", + ["false"] = "number", + ["NULL"] = "number", + ["null"] = "number", + + ["print"] = "function", + ["echo"] = "function", + ["exit"] = "function", + }, +} + +-- allows html, css and js coloring on php files syntax.add { files = { "%.php$", "%.phtml" }, patterns = { @@ -68,3 +204,34 @@ syntax.add { symbols = {}, } +-- allow coloring of php code inside css and js code +local syntaxes = { "css", "js" } +for _, ext in pairs(syntaxes) do + local syntax_table = syntax.get("file."..ext, "") + + table.insert( + syntax_table.patterns, + 1, + { + pattern = { + "<%?=?", + "%?>" + }, + syntax = ".phps", + type = "keyword2" + } + ) + + table.insert( + syntax_table.patterns, + 1, + { + pattern = { + "<%?php%s+", + "%?>" + }, + syntax = ".phps", + type = "keyword2" + } + ) +end diff --git a/plugins/language_phps.lua b/plugins/language_phps.lua deleted file mode 100644 index 082b962..0000000 --- a/plugins/language_phps.lua +++ /dev/null @@ -1,140 +0,0 @@ --- mod-version:2 -- lite-xl 2.0 ---[[ - language_phps.lua - complement to language_php.lua providing the php syntax support - version: 20210512_181200 ---]] -local syntax = require "core.syntax" - -syntax.add { - files = { "%.phps$" }, - headers = "^<%?php", - comment = "//", - patterns = { - -- Attributes - { pattern = {"#%[", "%]"}, type = "normal" }, - -- Comments - { pattern = "//.-\n", type = "comment" }, - { pattern = "#.-\n", type = "comment" }, - { pattern = { "/%*", "%*/" }, type = "comment" }, - -- The '\\' is for escaping to work on " or ' - { pattern = { '"', '"', '\\' }, type = "string" }, - { pattern = { "'", "'", '\\' }, type = "string" }, - { pattern = "0[bB][%d]+", type = "number" }, - { pattern = "0[xX][%da-fA-F]+", type = "number" }, - { pattern = "-?%d[%d_%.eE]*", type = "number" }, - { pattern = "-?%.?%d+", type = "number" }, - { pattern = "[%.%+%-=/%*%^%%<>!~|&%?:]", type = "operator" }, - -- Variables - { pattern = "%$[%w_]+", type = "keyword2" }, - -- Respect control structures, treat as keyword not function - { pattern = "if[%s]*%f[(]", type = "keyword" }, - { pattern = "else[%s]*%f[(]", type = "keyword" }, - { pattern = "elseif[%s]*%f[(]", type = "keyword" }, - { pattern = "for[%s]*%f[(]", type = "keyword" }, - { pattern = "foreach[%s]*%f[(]", type = "keyword" }, - { pattern = "while[%s]*%f[(]", type = "keyword" }, - { pattern = "catch[%s]*%f[(]", type = "keyword" }, - { pattern = "switch[%s]*%f[(]", type = "keyword" }, - { pattern = "match[%s]*%f[(]", type = "keyword" }, - { pattern = "fn[%s]*%f[(]", type = "keyword" }, - -- All functions that aren't control structures - { pattern = "[%a_][%w_]*[%s]*%f[(]", type = "function" }, - -- Array type hint not added on symbols to also make it work - -- as a function call - { pattern = "array", type = "literal" }, - -- Match static or namespace container on sub element access - { pattern = "[%a_][%w_]*[%s]*%f[:]", type = "literal" }, - -- Uppercase constants of at least 3 characters in len - { pattern = "%u[%u_][%u%d_]+", type = "number" }, - -- Magic constants - { pattern = "__[%u]+__", type = "number" }, - -- Everything else - { pattern = "[%a_][%w_]*", type = "symbol" }, - }, - symbols = { - ["return"] = "keyword", - ["if"] = "keyword", - ["else"] = "keyword", - ["elseif"] = "keyword", - ["endif"] = "keyword", - ["declare"] = "keyword", - ["enddeclare"] = "keyword", - ["switch"] = "keyword", - ["endswitch"] = "keyword", - ["as"] = "keyword", - ["do"] = "keyword", - ["for"] = "keyword", - ["endfor"] = "keyword", - ["foreach"] = "keyword", - ["endforeach"] = "keyword", - ["while"] = "keyword", - ["endwhile"] = "keyword", - ["switch"] = "keyword", - ["match"] = "keyword", - ["case"] = "keyword", - ["continue"] = "keyword", - ["default"] = "keyword", - ["break"] = "keyword", - ["goto"] = "keyword", - - ["try"] = "keyword", - ["catch"] = "keyword", - ["throw"] = "keyword", - ["finally"] = "keyword", - - ["class"] = "keyword", - ["trait"] = "keyword", - ["interface"] = "keyword", - ["public"] = "keyword", - ["static"] = "keyword", - ["protected"] = "keyword", - ["private"] = "keyword", - ["abstract"] = "keyword", - ["final"] = "keyword", - ["$this"] = "literal", - - ["function"] = "keyword", - ["fn"] = "keyword", - ["global"] = "keyword", - ["var"] = "keyword", - ["const"] = "keyword", - - ["bool"] = "literal", - ["boolean"] = "literal", - ["int"] = "literal", - ["integer"] = "literal", - ["real"] = "literal", - ["double"] = "literal", - ["float"] = "literal", - ["string"] = "literal", - ["object"] = "literal", - ["callable"] = "literal", - ["iterable"] = "literal", - ["void"] = "literal", - ["parent"] = "literal", - ["self"] = "literal", - ["mixed"] = "literal", - - ["namespace"] = "keyword", - ["extends"] = "keyword", - ["implements"] = "keyword", - ["instanceof"] = "keyword", - ["require"] = "keyword", - ["require_once"] = "keyword", - ["include"] = "keyword", - ["include_once"] = "keyword", - ["use"] = "keyword", - ["new"] = "keyword", - ["clone"] = "keyword", - - ["true"] = "number", - ["false"] = "number", - ["NULL"] = "number", - ["null"] = "number", - - ["print"] = "function", - ["echo"] = "function", - ["exit"] = "function", - }, -} diff --git a/plugins/language_rescript.lua b/plugins/language_rescript.lua new file mode 100644 index 0000000..94dc964 --- /dev/null +++ b/plugins/language_rescript.lua @@ -0,0 +1,59 @@ +-- mod-version:2 -- lite-xl 2.0 +local syntax = require "core.syntax" + +syntax.add { + files = { "%.res$" }, + comment = "//", + patterns = { + { pattern = "//.-\n", type = "comment" }, + { pattern = { "/%*", "%*/" }, type = "comment" }, + { pattern = { '"', '"', '\\' }, type = "string" }, + { pattern = { "'", "'", '\\' }, type = "string" }, + { pattern = { "`", "`", '\\' }, type = "string" }, + { pattern = "#[%a_][%w_]*", type = "literal" }, + { pattern = "0x[%da-fA-F]+", type = "number" }, + { pattern = "-?%d+[%d%.eE]*", type = "number" }, + { pattern = "-?%.?%d+", type = "number" }, + { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" }, + { pattern = "%f[^%.>]%l[%w_]*", type = "function" }, + { pattern = "%l[%w_]*%f[(]", type = "function" }, + { pattern = "%u[%w_]*", type = "keyword2" }, + { pattern = "[%l_][%w_%.]*", type = "symbol" }, + { pattern = "@%l[%w_]*", type = "string" }, + }, + symbols = { + ["and"] = "keyword", + ["array"] = "keyword2", + ["as"] = "keyword", + ["assert"] = "keyword", + ["bool"] = "keyword2", + ["constraint"] = "keyword", + ["downto"] = "keyword", + ["else"] = "keyword", + ["exception"] = "keyword", + ["external"] = "keyword", + ["false"] = "literal", + ["for"] = "keyword", + ["if"] = "keyword", + ["in"] = "keyword", + ["int"] = "keyword2", + ["include"] = "keyword", + ["lazy"] = "keyword", + ["let"] = "keyword", + ["module"] = "keyword", + ["mutable"] = "keyword", + ["of"] = "keyword", + ["open"] = "keyword", + ["option"] = "keyword2", + ["rec"] = "keyword", + ["switch"] = "keyword", + ["string"] = "keyword2", + ["to"] = "keyword", + ["true"] = "literal", + ["try"] = "keyword", + ["type"] = "keyword", + ["when"] = "keyword", + ["while"] = "keyword", + ["with"] = "keyword", + } +} diff --git a/plugins/language_tex.lua b/plugins/language_tex.lua index 1bc08f5..9878505 100644 --- a/plugins/language_tex.lua +++ b/plugins/language_tex.lua @@ -5,13 +5,22 @@ syntax.add { files = { "%.tex$" }, comment = "%%", patterns = { - { pattern = {"%%", "\n"}, type = "comment" }, - { pattern = "&", type = "operator" }, - { pattern = "\\\\", type = "operator" }, - { pattern = {"%$", "%$"}, type = "operator" }, - { pattern = {"\\%[", "\\]"}, type = "operator" }, - { pattern = {"{", "}"}, type = "keyword" }, - { pattern = "\\%w*", type = "keyword2" }, + { pattern = "%%.-\n", type = "comment" }, + { pattern = "\\documentclass().-{()%a%w+()}", type = {"keyword", "symbol", "function", "symbol"} }, + { pattern = "\\usepackage", type = "keyword" }, + { pattern = "\\chapter", type = "keyword" }, + { pattern = "\\section", type = "keyword" }, + { pattern = "\\subsection", type = "keyword" }, + { pattern = "\\paragraph", type = "keyword" }, + { pattern = "\\subparagraph", type = "keyword" }, + { pattern = "\\begin(){()%a%w+()}", type = {"keyword2", "symbol", "function", "symbol"} }, + { pattern = "\\end(){()%a%w+()}", type = {"keyword2", "symbol", "function", "symbol"} }, + { pattern = "\\%a%w+()%*", type = {"keyword2", "operator"} }, + { pattern = "\\%a%w+", type = "keyword2" }, + { pattern = "&", type = "operator" }, + { pattern = "\\\\", type = "operator" }, + { pattern = "%$", type = "operator" }, + { pattern = "\\[%[%]()]", type = "operator" }, }, symbols = {} } diff --git a/plugins/language_toml.lua b/plugins/language_toml.lua index 9de31f9..3774dfb 100644 --- a/plugins/language_toml.lua +++ b/plugins/language_toml.lua @@ -1,4 +1,4 @@ --- lite-xl 1.16 +-- mod-version:2 local syntax = require "core.syntax" diff --git a/plugins/linenumbers.lua b/plugins/linenumbers.lua index fde0a08..1b0bdc6 100644 --- a/plugins/linenumbers.lua +++ b/plugins/linenumbers.lua @@ -1,4 +1,4 @@ --- mod-version:1 -- lite-xl 1.16 +-- mod-version:2 -- lite-xl 2.0 local config = require "core.config" local style = require "core.style" local DocView = require "core.docview" diff --git a/plugins/minimap.lua b/plugins/minimap.lua index c9e1c54..3f4a2a2 100644 --- a/plugins/minimap.lua +++ b/plugins/minimap.lua @@ -289,6 +289,13 @@ DocView.draw_scrollbar = function(self) end +local prev_update = DocView.update +DocView.update = function (self) + if not config.plugins.minimap.enabled then return prev_update(self) end + self.size.x = self.size.x - config.plugins.minimap.width * SCALE + return prev_update(self) +end + command.add(nil, { ["minimap:toggle-visibility"] = function() config.plugins.minimap.enabled = not config.plugins.minimap.enabled diff --git a/plugins/open_ext.lua b/plugins/open_ext.lua new file mode 100644 index 0000000..f01ab85 --- /dev/null +++ b/plugins/open_ext.lua @@ -0,0 +1,187 @@ +-- mod-version:2 -- lite-xl 2.0 + +-- The general idea is to check if the file opened is valid utf-8 +-- since lite-xl only supports UTF8 text, others can be safely assumed +-- to be binary +local core = require "core" +local common = require "core.common" +local style = require "core.style" +local DocView = require "core.docview" +local RootView = require "core.rootview" +local View = require "core.view" + + +local function validate_utf8(s, limit) + --[[ + MIT LICENSE + Copyright (c) 2013 Enrique GarcĂa Cota + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + ]] + limit = limit or math.huge + local i, p, len = 1, 1, #s + while p <= len do + if p == s:find("[%z\1-\127]", p) then p = p + 1 + elseif p == s:find("[\194-\223][\128-\191]", p) then p = p + 2 + elseif p == s:find( "\224[\160-\191][\128-\191]", p) + or p == s:find("[\225-\236][\128-\191][\128-\191]", p) + or p == s:find( "\237[\128-\159][\128-\191]", p) + or p == s:find("[\238-\239][\128-\191][\128-\191]", p) then p = p + 3 + elseif p == s:find( "\240[\144-\191][\128-\191][\128-\191]", p) + or p == s:find("[\241-\243][\128-\191][\128-\191][\128-\191]", p) + or p == s:find( "\244[\128-\143][\128-\191][\128-\191]", p) then p = p + 4 + else + return false + end + i = i + 1 + if i > limit then break end + end + + return true +end + + +local function replace_view(this, that) + local node = core.root_view.root_node:get_node_for_view(this) + local idx = node:get_view_idx(this) + node:remove_view(core.root_view.root_node, this) + node:add_view(that, idx) + core.root_view.root_node:update_layout() + core.redraw = true +end + + +local msg = "This file is not displayed because it is either binary or uses an unsupported text encoding." +local cmd -- here's evil code again... +if PLATFORM == "Windows" then + cmd = "start %q" +elseif PLATFORM == "Linux" then + cmd = "xdg-open %q" +else + cmd = "open %q" +end + +local opt = { "Open anyway", "Open with other program", "Close" } +local opt_actions = { + function(self) + -- open anyway + local view = DocView(core.open_doc(self.filename)) + replace_view(self, view) + end, + function(self) + -- open externally + local node = core.root_view.root_node:get_node_for_view(self) + node:close_view(core.root_view.root_node, self) + system.exec(string.format(cmd, self.filename)) + end, + function(self) + local node = core.root_view.root_node:get_node_for_view(self) + node:close_view(core.root_view.root_node, self) + end +} + + +local OpenExtView = View:extend() + + +function OpenExtView:new(filename) + OpenExtView.super.new(self) + self.filename = filename +end + + +function OpenExtView:get_name() + return common.basename(self.filename) +end + + +function OpenExtView:each_option() + return coroutine.wrap(function() + local w = (self.size.x - style.padding.x * (#opt + 1)) / #opt + local h = style.font:get_height() + style.padding.y + local x, y = self:get_content_offset() + x = x + style.padding.x + y = y + self.size.y / 2 + style.padding.y + for i, o in ipairs(opt) do + coroutine.yield(i, o, x, y, w, h) + x = x + w + style.padding.x + end + end) +end + + +function OpenExtView:on_mouse_moved(px, py, dx, dy) + OpenExtView.super.on_mouse_moved(self, px, py, dx, dy) + self.hovered = nil + for i, _, x, y, w, h in self:each_option() do + if px > x and px <= x + w and py > y and py <= y + h then + self.hovered = i + break + end + end +end + + +function OpenExtView:on_mouse_pressed(button, x, y, clicks) + if OpenExtView.super.on_mouse_pressed(self, button, x, y, clicks) then return end + if self.hovered then + opt_actions[self.hovered](self) + end +end + + +function OpenExtView:draw() + self:draw_background(style.background) + local x, y = self:get_content_offset() + local lh = style.font:get_height() + y = y + self.size.y / 2 - style.padding.y - lh + common.draw_text(style.font, style.text, msg, "center", x, y, self.size.x, lh) + for i, opt, x, y, w, h in self:each_option() do + local text_color = i == self.hovered and style.background or style.text + renderer.draw_rect(x, y, w, h, style.accent) + if i ~= self.hovered then + renderer.draw_rect(x + 1, y + 1, w - 2, h - 2, style.background) + end + common.draw_text(style.font, text_color, opt, "center", x, y, w, h) + end +end + + +local function read_from_doc(doc, limit) + local l, result = 0, {} + for _, line in ipairs(doc.lines) do + result[#result+1] = line + l = l + #line + if l >= limit then break end + end + return table.concat(result, "") +end + + +local rootview_open_doc = RootView.open_doc +function RootView:open_doc(doc) + local str = read_from_doc(doc, 4 * 128) -- max size for 128 codepoints + if str == "\n" or str == "" and validate_utf8(str, 128) then + return rootview_open_doc(self, doc) + else + local node = self:get_active_node_default() + local view = OpenExtView(doc.abs_filename or doc.filename) + node:add_view(view) + self.root_node:update_layout() + return view + end +end diff --git a/plugins/texcompile.lua b/plugins/texcompile.lua index 2f53513..517aa9b 100644 --- a/plugins/texcompile.lua +++ b/plugins/texcompile.lua @@ -1,44 +1,171 @@ -- mod-version:2 -- lite-xl 2.0 local core = require "core" +local config = require "core.config" local command = require "core.command" +local common = require "core.common" local keymap = require "core.keymap" -command.add("core.docview", { - ["texcompile:tex-compile"] = function() - local av = core.active_view +-- This code use an adaptation of the rxi/console plugin code to +-- start commands. + +local pending_threads = {} +local thread_active = false --- User's home directory - local homedir = "" +local function push_output(str, opt) + -- By default we just ignore the output of a command. + -- print(">>OUTPUT:", str) +end + +local function read_file(filename, offset) + local fp = io.open(filename, "rb") + fp:seek("set", offset or 0) + local res = fp:read("*a") + fp:close() + return res +end + +local function write_file(filename, text) + local fp = io.open(filename, "w") + fp:write(text) + fp:close() +end + +local function init_opt(opt) + local res = { + command = "", + arguments = {}, + on_complete = function() end, + } + for k, v in pairs(res) do + res[k] = opt[k] or v + end + return res +end +local files = { + script = core.temp_filename(PLATFORM == "Windows" and ".bat"), + script2 = core.temp_filename(PLATFORM == "Windows" and ".bat"), + output = core.temp_filename(), + complete = core.temp_filename(), +} + +local function command_run(opt) + opt = init_opt(opt) + + local function thread() + -- init script file(s) + local args_quoted = {} + for i, arg in ipairs(opt.arguments) do args_quoted[i] = string.format("%q", arg) end + local args_concat = table.concat(args_quoted, " ") + local working_dir = opt.working_dir or "." if PLATFORM == "Windows" then - homedir = os.getenv("USERPROFILE") + write_file(files.script, string.format("%s %s\n", opt.command, args_concat)) + write_file(files.script2, string.format([[ + @echo off + cd %q + call %q >%q 2>&1 + echo "" >%q + exit + ]], working_dir, files.script, files.output, files.complete)) + system.exec(string.format("call %q", files.script2)) + else + write_file(files.script, string.format([[ + cd %q + %s %s + touch %q + ]], working_dir, opt.command, args_concat, files.complete)) + system.exec(string.format("bash %q >%q 2>&1", files.script, files.output)) + end + + -- checks output file for change and reads + local last_size = 0 + local function check_output_file() + if PLATFORM == "Windows" then + local fp = io.open(files.output) + if fp then fp:close() end + end + local info = system.get_file_info(files.output) + if info and info.size > last_size then + local text = read_file(files.output, last_size) + push_output(text, opt) + last_size = info.size + end + end + + -- read output file until we get a file indicating completion + while not system.get_file_info(files.complete) do + check_output_file() + coroutine.yield(0.1) + end + check_output_file() + + -- clean up and finish + for _, file in pairs(files) do + os.remove(file) + end + opt.on_complete() + + -- handle pending thread + local pending = table.remove(pending_threads, 1) + if pending then + core.add_thread(pending) else - homedir = os.getenv("HOME") + thread_active = false end + end + + -- push/init thread + if thread_active then + table.insert(pending_threads, thread) + else + core.add_thread(thread) + thread_active = true + end +end --- The current (La)TeX file and path +command.add("core.docview", { + ["texcompile:tex-compile"] = function() + local av = core.active_view + + -- 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, '') + local texpath = common.dirname(av:get_filename()) + + -- Add in your user's config file something like: + -- + -- config.texcompile = { + -- latex_command = "pdflatex", + -- view_command = "evince", + -- } + -- + -- On windows you may use the full path for the command like: + -- + -- latex_command = [[c:\miktex\miktex\bin\x64\pdflatex.exe]], --- LaTeX compiler - is there any provided by the environment - local texcmd = os.getenv("LITE_LATEX_COMPILER") + -- LaTeX compiler - is there any provided by the environment + local texcmd = config.texcompile and config.texcompile.latex_command + local viewcmd = config.texcompile and config.texcompile.view_command - if texcmd == nil then + if not texcmd 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 + command_run { + command = texcmd, + arguments = { texname }, + working_dir = texpath, + on_complete = function() core.log("Tex compiling command terminated.") end + } --- core.add_thread(function() --- coroutine.yield(5) --- os.remove(htmlfile) --- end) + local pdfname = texname:gsub("%.tex$", ".pdf") + command_run { + command = viewcmd, + arguments = { pdfname }, + working_dir = texpath + } + end end }) - keymap.add { ["ctrl+shift+t"] = "texcompile:tex-compile" } |