From 9f671f2ae3f64029b1c1ab556b4060c322831028 Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Sat, 12 Jun 2021 18:10:59 -0400 Subject: Added entry in README. --- README.md | 1 + 1 file changed, 1 insertion(+) (limited to 'README.md') diff --git a/README.md b/README.md index 48f9796..1255ace 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,7 @@ Plugin | Description [`macmodkeys`](plugins/macmodkeys.lua?raw=1) | Remaps mac modkeys `command/option` to `ctrl/alt` [`markers`](plugins/markers.lua?raw=1) | Add markers to docs and jump between them quickly *([screenshot](https://user-images.githubusercontent.com/3920290/82252149-5faaa200-9946-11ea-9199-bea2efb7ee23.png))* [`memoryusage`](plugins/memoryusage.lua?raw=1) | Show memory usage in the status view +[`minimap`](plugins/minimap.lua?raw=1) | Shows a minimap on the right-hand side of the docview. Taken from [@andsve](https://github.com/andsve/lite-plugins/tree/minimap-plugin). [`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)* | 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 -- cgit v1.2.3 From 69e109111f000b01d4d761ea87a10f51cfab183b Mon Sep 17 00:00:00 2001 From: takase1121 <20792268+takase1121@users.noreply.github.com> Date: Mon, 21 Jun 2021 17:23:52 +0800 Subject: add language_tsx to README --- README.md | 1 + 1 file changed, 1 insertion(+) (limited to 'README.md') diff --git a/README.md b/README.md index a31c13a..97f3e73 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,7 @@ Plugin | Description [`language_sh`](plugins/language_sh.lua?raw=1) | Syntax for shell scripting language [`language_teal`](plugins/language_teal.lua?raw=1) | Syntax for the [Teal](https://github.com/teal-language/tl) programming language, a typed dialect of Lua. [`language_tex`](plugins/language_tex.lua?raw=1) | Syntax for the [LaTeX](https://www.latex-project.org/) typesetting language +[`language_tsx`](plugins/language_tsx.lua?raw=1) | Syntax for [TSX](https://www.typescriptlang.org/docs/handbook/jsx.html) language [`language_v`](plugins/language_v.lua?raw=1) | Syntax for the [V](https://vlang.io/) programming language [`language_wren`](plugins/language_wren.lua?raw=1) | Syntax for the [Wren](http://wren.io/) programming language [`language_zig`](plugins/language_zig.lua?raw=1) | Syntax for the [Zig](https://ziglang.org/) programming language -- cgit v1.2.3 From d888ceec02f4538ef51f4534713bbbd2847ec796 Mon Sep 17 00:00:00 2001 From: takase1121 <20792268+takase1121@users.noreply.github.com> Date: Mon, 21 Jun 2021 17:30:20 +0800 Subject: remove nagbar because it is integrated in lite-xl --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'README.md') diff --git a/README.md b/README.md index a31c13a..9196658 100644 --- a/README.md +++ b/README.md @@ -96,7 +96,7 @@ Plugin | Description [`markers`](plugins/markers.lua?raw=1) | Add markers to docs and jump between them quickly *([screenshot](https://user-images.githubusercontent.com/3920290/82252149-5faaa200-9946-11ea-9199-bea2efb7ee23.png))* [`memoryusage`](plugins/memoryusage.lua?raw=1) | Show memory usage in the status view [`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)* | consistent and _beautiful_ confirmation dialogs for lite and lite-xl *([gif](https://raw.githubusercontent.com/takase1121/lite-nagbar/master/assets/preview.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 [`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 -- cgit v1.2.3 From 4421ee3d6a2ad35e510e2d2857c527cb08235fda Mon Sep 17 00:00:00 2001 From: takase1121 <20792268+takase1121@users.noreply.github.com> Date: Mon, 21 Jun 2021 17:44:15 +0800 Subject: add language_ts --- README.md | 1 + plugins/language_ts.lua | 73 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 plugins/language_ts.lua (limited to 'README.md') diff --git a/README.md b/README.md index a31c13a..d6a71c0 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,7 @@ Plugin | Description [`language sass`](plugins/language_sass.lua?raw=1) | Syntax for the [Sass](https://sass-lang.com/) CSS preprocessor [`language_sh`](plugins/language_sh.lua?raw=1) | Syntax for shell scripting language [`language_teal`](plugins/language_teal.lua?raw=1) | Syntax for the [Teal](https://github.com/teal-language/tl) programming language, a typed dialect of Lua. +[`language_ts`](plugins/language_ts.lua?raw=1) | Syntax for the [TypeScript](https://www.typescriptlang.org/) programming language, a typed dialect of JavaScript. [`language_tex`](plugins/language_tex.lua?raw=1) | Syntax for the [LaTeX](https://www.latex-project.org/) typesetting language [`language_v`](plugins/language_v.lua?raw=1) | Syntax for the [V](https://vlang.io/) programming language [`language_wren`](plugins/language_wren.lua?raw=1) | Syntax for the [Wren](http://wren.io/) programming language diff --git a/plugins/language_ts.lua b/plugins/language_ts.lua new file mode 100644 index 0000000..96cf0d3 --- /dev/null +++ b/plugins/language_ts.lua @@ -0,0 +1,73 @@ +-- mod-version:1 -- lite-xl 1.16 +-- copied from language_js, but added regex highlighting back +local syntax = require "core.syntax" + +syntax.add { + files = { "%.ts$" }, + comment = "//", + patterns = { + { pattern = "//.-\n", type = "comment" }, + { pattern = { "/%*", "%*/" }, type = "comment" }, + { pattern = { '/%g', '/', '\\' }, type = "string" }, + { pattern = { '"', '"', '\\' }, type = "string" }, + { pattern = { "'", "'", '\\' }, type = "string" }, + { pattern = { "`", "`", '\\' }, type = "string" }, + { pattern = "0x[%da-fA-F]+", type = "number" }, + { pattern = "-?%d+[%d%.eE]*", type = "number" }, + { pattern = "-?%.?%d+", type = "number" }, + { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" }, + { pattern = "interface%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, + { pattern = "type%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, + { pattern = "[%a_][%w_]*%f[(]", type = "function" }, + { pattern = "[%a_][%w_]*", type = "symbol" }, + }, + symbols = { + ["async"] = "keyword", + ["await"] = "keyword", + ["break"] = "keyword", + ["case"] = "keyword", + ["catch"] = "keyword", + ["class"] = "keyword", + ["const"] = "keyword", + ["continue"] = "keyword", + ["debugger"] = "keyword", + ["default"] = "keyword", + ["delete"] = "keyword", + ["do"] = "keyword", + ["else"] = "keyword", + ["export"] = "keyword", + ["extends"] = "keyword", + ["finally"] = "keyword", + ["for"] = "keyword", + ["function"] = "keyword", + ["get"] = "keyword", + ["if"] = "keyword", + ["import"] = "keyword", + ["implements"] = "keyword", + ["in"] = "keyword", + ["instanceof"] = "keyword", + ["let"] = "keyword", + ["new"] = "keyword", + ["return"] = "keyword", + ["set"] = "keyword", + ["static"] = "keyword", + ["super"] = "keyword", + ["switch"] = "keyword", + ["throw"] = "keyword", + ["try"] = "keyword", + ["typeof"] = "keyword", + ["var"] = "keyword", + ["void"] = "keyword", + ["while"] = "keyword", + ["with"] = "keyword", + ["yield"] = "keyword", + ["true"] = "literal", + ["false"] = "literal", + ["null"] = "literal", + ["undefined"] = "literal", + ["arguments"] = "keyword2", + ["Infinity"] = "keyword2", + ["NaN"] = "keyword2", + ["this"] = "keyword2", + }, +} -- cgit v1.2.3 From d1b4b6ec41a7626fb18b834fdf6751eeb376c50d Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Thu, 24 Jun 2021 09:27:25 +0200 Subject: Add syntax file for tcl language --- README.md | 1 + plugins/language_tcl.lua | 68 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 plugins/language_tcl.lua (limited to 'README.md') diff --git a/README.md b/README.md index a31c13a..9142365 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,7 @@ Plugin | Description [`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 [`language_sh`](plugins/language_sh.lua?raw=1) | Syntax for shell scripting language +[`language_tcl`](plugins/language_tcl.lua?raw=1) | Syntax for the [Tcl](https://www.tcl.tk/) programming language [`language_teal`](plugins/language_teal.lua?raw=1) | Syntax for the [Teal](https://github.com/teal-language/tl) programming language, a typed dialect of Lua. [`language_tex`](plugins/language_tex.lua?raw=1) | Syntax for the [LaTeX](https://www.latex-project.org/) typesetting language [`language_v`](plugins/language_v.lua?raw=1) | Syntax for the [V](https://vlang.io/) programming language 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", + }, +} + -- cgit v1.2.3 From 99a80e97cce08620230cc11a41321d78ac6f8743 Mon Sep 17 00:00:00 2001 From: Aayush Kashyap Date: Fri, 2 Jul 2021 14:17:39 +0530 Subject: added smallclock plugin --- README.md | 1 + plugins/smallclock.lua | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 plugins/smallclock.lua (limited to 'README.md') diff --git a/README.md b/README.md index ca6361f..dbfab60 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,7 @@ Plugin | Description *[`scale`](plugins/scale.lua?raw=1)* | Provides support for dynamically adjusting the scale of the code font / UI (`ctrl+-`, `ctrl+=`) [`scalestatus`](plugins/scalestatus.lua?raw=1) | Displays current scale (zoom) in status view (depends on scale plugin) [`selectionhighlight`](plugins/selectionhighlight.lua?raw=1) | Highlights regions of code that match the current selection *([screenshot](https://user-images.githubusercontent.com/3920290/80710883-5f597c80-8ae7-11ea-97f0-76dfacc08439.png))* +[`smallclock`](plugins/smallclock.lua?raw=1) | Displays the current time in the corner of the status view [`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)) diff --git a/plugins/smallclock.lua b/plugins/smallclock.lua new file mode 100644 index 0000000..8742b07 --- /dev/null +++ b/plugins/smallclock.lua @@ -0,0 +1,27 @@ +-- lite-xl 1.16 +local core = require "core" +local style = require "core.style" +local status_view = require "core.statusview" + +local time = "" + +core.add_thread(function() + while true do + local t = os.date("*t") + time = string.format("%02d:%02d", t.hour, t.min) + coroutine.yield() + end +end) + +local get_items = status_view.get_items + +function status_view:get_items() + local left, right = get_items(self) + local t = {style.dim, self.separator2, style.accent, time} + + for _, item in ipairs(t) do + table.insert(right, item) + end + + return left, right +end -- cgit v1.2.3 From 83fcee49038842f3d7f60ebce5058d6e3fccbc92 Mon Sep 17 00:00:00 2001 From: cukmekerb Date: Mon, 5 Jul 2021 21:50:35 -0700 Subject: minimap plugin no longer crashes lite-xl and now renders tab indentation --- README.md | 2 +- plugins/minimap.lua | 511 ++++++++++++++++++++++++++-------------------------- 2 files changed, 257 insertions(+), 256 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index ca6361f..be823f8 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ Plugin | Description [`macmodkeys`](plugins/macmodkeys.lua?raw=1) | Remaps mac modkeys `command/option` to `ctrl/alt` [`markers`](plugins/markers.lua?raw=1) | Add markers to docs and jump between them quickly *([screenshot](https://user-images.githubusercontent.com/3920290/82252149-5faaa200-9946-11ea-9199-bea2efb7ee23.png))* [`memoryusage`](plugins/memoryusage.lua?raw=1) | Show memory usage in the status view -[`minimap`](plugins/minimap.lua?raw=1) | Shows a minimap on the right-hand side of the docview. Taken from [@andsve](https://github.com/andsve/lite-plugins/tree/minimap-plugin). +[`minimap`](plugins/minimap.lua?raw=1) | Shows a minimap on the right-hand side of the docview. Taken from [@andsve](https://github.com/andsve/lite-plugins/tree/minimap-plugin), and improved upon. [`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 diff --git a/plugins/minimap.lua b/plugins/minimap.lua index f58a609..ecae5eb 100644 --- a/plugins/minimap.lua +++ b/plugins/minimap.lua @@ -1,107 +1,112 @@ --- mod-version:1 -- lite-xl 1.16 --- Pulled from git@github.com:andsve/lite-plugins.git - -local command = require "core.command" -local common = require "core.common" -local config = require "core.config" -local style = require "core.style" -local DocView = require "core.docview" +-- mod-version:1 +local command = require "core.command" +local common = require "core.common" +local config = require "core.config" +local style = require "core.style" +local DocView = require "core.docview" -- General plugin settings -config.minimap_enabled = true -config.minimap_width = 100 -config.minimap_instant_scroll = false +config.minimap_enabled = true +config.minimap_width = 100 +config.minimap_instant_scroll = false config.minimap_syntax_highlight = true -config.minimap_scale = 1 -config.minimap_draw_background = true +config.minimap_scale = 1 + +-- how many spaces one tab is equivalent to +config.minimap_tab_width = 4 + +config.minimap_draw_background = true -- Configure size for rendering each char in the minimap -local char_height = 1 * SCALE * config.minimap_scale +local char_height = 1 * SCALE * config.minimap_scale local char_spacing = 0.8 * SCALE * config.minimap_scale local line_spacing = 2 * SCALE * config.minimap_scale -- Overloaded since the default implementation adds a extra x3 size of hotspot for the mouse to hit the scrollbar. local prev_scrollbar_overlaps_point = DocView.scrollbar_overlaps_point DocView.scrollbar_overlaps_point = function(self, x, y) - if not config.minimap_enabled then return prev_scrollbar_overlaps_point(self, x, y) end + if not config.minimap_enabled then + return prev_scrollbar_overlaps_point(self, x, y) + end - local sx, sy, sw, sh = self:get_scrollbar_rect() - return x >= sx and x < sx + sw and y >= sy and y < sy + sh + local sx, sy, sw, sh = self:get_scrollbar_rect() + return x >= sx and x < sx + sw and y >= sy and y < sy + sh end -- Helper function to determine if current file is too large to be shown fully inside the minimap area. local function is_file_too_large(self) - local line_count = #self.doc.lines - local _, _, _, sh = self:get_scrollbar_rect() + local line_count = #self.doc.lines + local _, _, _, sh = self:get_scrollbar_rect() - -- check if line count is too large to fit inside the minimap area - local max_minmap_lines = math.floor(sh / line_spacing) - return line_count > 1 and line_count > max_minmap_lines + -- check if line count is too large to fit inside the minimap area + local max_minmap_lines = math.floor(sh / line_spacing) + return line_count > 1 and line_count > max_minmap_lines end -- Overloaded with an extra check if the user clicked inside the minimap to automatically scroll to that line. local prev_on_mouse_pressed = DocView.on_mouse_pressed DocView.on_mouse_pressed = function(self, button, x, y, clicks) - if not config.minimap_enabled then return prev_on_mouse_pressed(self, button, x, y, clicks) end - - -- check if user clicked in the minimap area and jump directly to that line - -- unless they are actually trying to perform a drag - local minimap_hit = self:scrollbar_overlaps_point(x, y) - if minimap_hit then - local line_count = #self.doc.lines - local minimap_height = line_count * line_spacing - - -- check if line count is too large to fit inside the minimap area - local is_too_large = is_file_too_large(self) - if is_too_large then - local _, _, _, sh = self:get_scrollbar_rect() - minimap_height = sh - end - - -- calc which line to jump to - local dy = y - self.position.y - local jump_to_line = math.floor((dy / minimap_height) * line_count) + 1 - - local _, cy, _, cy2 = self:get_content_bounds() - local lh = self:get_line_height() - local visible_lines_count = math.max(1, (cy2 - cy) / lh) - local visible_lines_start = math.max(1, math.floor(cy / lh)) - - -- calc if user hit the currently visible area - local hit_visible_area = true - if is_too_large then - - local visible_height = visible_lines_count * line_spacing - local scroll_pos = (visible_lines_start-1) / (line_count - visible_lines_count - 1) - scroll_pos = math.min(1.0, scroll_pos) -- 0..1 - local visible_y = self.position.y + scroll_pos * (minimap_height - visible_height) - - local t = (line_count - visible_lines_start) / visible_lines_count - if t <= 1 then - visible_y = visible_y + visible_height * (1.0 - t) - end - - if y < visible_y or y > visible_y + visible_height then - hit_visible_area = false - end - else - - -- If the click is on the currently visible line numbers, - -- ignore it since then they probably want to initiate a drag instead. - if jump_to_line < visible_lines_start or jump_to_line > visible_lines_start + visible_lines_count then - hit_visible_area = false - end - end - - -- if user didn't click on the visible area (ie not dragging), scroll accordingly - if not hit_visible_area then - self:scroll_to_line(jump_to_line, false, config.minimap_instant_scroll) - return - end - - end - - return prev_on_mouse_pressed(self, button, x, y, clicks) + if not config.minimap_enabled then + return prev_on_mouse_pressed(self, button, x, y, clicks) + end + + -- check if user clicked in the minimap area and jump directly to that line + -- unless they are actually trying to perform a drag + local minimap_hit = self:scrollbar_overlaps_point(x, y) + if minimap_hit then + local line_count = #self.doc.lines + local minimap_height = line_count * line_spacing + + -- check if line count is too large to fit inside the minimap area + local is_too_large = is_file_too_large(self) + if is_too_large then + local _, _, _, sh = self:get_scrollbar_rect() + minimap_height = sh + end + + -- calc which line to jump to + local dy = y - self.position.y + local jump_to_line = math.floor((dy / minimap_height) * line_count) + 1 + + local _, cy, _, cy2 = self:get_content_bounds() + local lh = self:get_line_height() + local visible_lines_count = math.max(1, (cy2 - cy) / lh) + local visible_lines_start = math.max(1, math.floor(cy / lh)) + + -- calc if user hit the currently visible area + local hit_visible_area = true + if is_too_large then + + local visible_height = visible_lines_count * line_spacing + local scroll_pos = (visible_lines_start - 1) / + (line_count - visible_lines_count - 1) + scroll_pos = math.min(1.0, scroll_pos) -- 0..1 + local visible_y = self.position.y + scroll_pos * + (minimap_height - visible_height) + + local t = (line_count - visible_lines_start) / visible_lines_count + if t <= 1 then visible_y = visible_y + visible_height * (1.0 - t) end + + if y < visible_y or y > visible_y + visible_height then + hit_visible_area = false + end + else + + -- If the click is on the currently visible line numbers, + -- ignore it since then they probably want to initiate a drag instead. + if jump_to_line < visible_lines_start or jump_to_line > visible_lines_start + + visible_lines_count then hit_visible_area = false end + end + + -- if user didn't click on the visible area (ie not dragging), scroll accordingly + if not hit_visible_area then + self:scroll_to_line(jump_to_line, false, config.minimap_instant_scroll) + return + end + + end + + return prev_on_mouse_pressed(self, button, x, y, clicks) end -- Overloaded with pretty much the same logic as original DocView implementation, @@ -109,190 +114,186 @@ end -- since the "scrollbar" essentially represents the lines visible in the content view. local prev_on_mouse_moved = DocView.on_mouse_moved DocView.on_mouse_moved = function(self, x, y, dx, dy) - if not config.minimap_enabled then return prev_on_mouse_moved(self, x, y, dx, dy) end - - if self.dragging_scrollbar then - local line_count = #self.doc.lines - local lh = self:get_line_height() - local delta = lh / line_spacing * dy - - if is_file_too_large(self) then - local _, sy, _, sh = self:get_scrollbar_rect() - delta = (line_count * lh) / sh * dy - end - - self.scroll.to.y = self.scroll.to.y + delta - end - - -- we need to "hide" that the scrollbar is dragging so that View doesnt does its own scrolling logic - local t = self.dragging_scrollbar - self.dragging_scrollbar = false - local r = prev_on_mouse_moved(self, x, y, dx, dy) - self.dragging_scrollbar = t - return r + if not config.minimap_enabled then + return prev_on_mouse_moved(self, x, y, dx, dy) + end + + if self.dragging_scrollbar then + local line_count = #self.doc.lines + local lh = self:get_line_height() + local delta = lh / line_spacing * dy + + if is_file_too_large(self) then + local _, sy, _, sh = self:get_scrollbar_rect() + delta = (line_count * lh) / sh * dy + end + + self.scroll.to.y = self.scroll.to.y + delta + end + + -- we need to "hide" that the scrollbar is dragging so that View doesnt does its own scrolling logic + local t = self.dragging_scrollbar + self.dragging_scrollbar = false + local r = prev_on_mouse_moved(self, x, y, dx, dy) + self.dragging_scrollbar = t + return r end -- Overloaded since we want the mouse to interact with the full size of the minimap area, -- not juse the scrollbar. local prev_get_scrollbar_rect = DocView.get_scrollbar_rect -DocView.get_scrollbar_rect = function (self) - if not config.minimap_enabled then return prev_get_scrollbar_rect(self) end - - return - self.position.x + self.size.x - config.minimap_width * SCALE, - self.position.y, - config.minimap_width * SCALE, - self.size.y +DocView.get_scrollbar_rect = function(self) + if not config.minimap_enabled then return prev_get_scrollbar_rect(self) end + + return self.position.x + self.size.x - config.minimap_width * SCALE, + self.position.y, config.minimap_width * SCALE, self.size.y end -- Overloaded so we can render the minimap in the "scrollbar area". local prev_draw_scrollbar = DocView.draw_scrollbar -DocView.draw_scrollbar = function (self) - if not config.minimap_enabled then return prev_draw_scrollbar(self) end - - local x, y, w, h = self:get_scrollbar_rect() - - local highlight = self.hovered_scrollbar or self.dragging_scrollbar - local visual_color = highlight and style.scrollbar2 or style.scrollbar - - local _, cy, _, cy2 = self:get_content_bounds() - local lh = self:get_line_height() - local visible_lines_count = math.max(1, (cy2 - cy) / lh) - local visible_lines_start = math.max(1, math.floor(cy / lh)) - local scroller_height = visible_lines_count * line_spacing - local line_count = #self.doc.lines - - local visible_y = self.position.y + (visible_lines_start-1) * line_spacing - - - -- check if file is too large to fit inside the minimap area - local max_minmap_lines = math.floor(h / line_spacing) - local minimap_start_line = 1 - if is_file_too_large(self) then - - local scroll_pos = (visible_lines_start-1) / (line_count - visible_lines_count - 1) - scroll_pos = math.min(1.0, scroll_pos) -- 0..1, procent of visual area scrolled - - local scroll_pos_pixels = scroll_pos * (h - scroller_height) - visible_y = self.position.y + scroll_pos_pixels - - -- offset visible area if user is scrolling past end - local t = (line_count - visible_lines_start) / visible_lines_count - if t <= 1 then - visible_y = visible_y + scroller_height * (1.0 - t) - end - - minimap_start_line = visible_lines_start - math.floor(scroll_pos_pixels / line_spacing) - minimap_start_line = math.max(1, math.min(minimap_start_line, line_count - max_minmap_lines)) - end - - if config.minimap_draw_background then - renderer.draw_rect(x, y, w, h, style.minimap_background or style.background) - end - -- draw visual rect - renderer.draw_rect(x, visible_y, w, scroller_height, visual_color) - - -- time to draw the actual code, setup some local vars that are used in both highlighted and plain renderind. - local line_y = y - - -- when not using syntax highlighted rendering, just use the normal color but dim it 50%. - local color = style.syntax["normal"] - color = { color[1],color[2],color[3],color[4] * 0.5 } - - -- we try to "batch" characters so that they can be rendered as just one rectangle instead of one for each. - local batch_width = 0 - local batch_start = x - local minimap_cutoff_x = x + config.minimap_width * SCALE - - -- render lines with syntax highlighting - if config.minimap_syntax_highlight then - - -- keep track of the highlight type, since this needs to break batches as well - local batch_syntax_type = nil - - local function flush_batch(type) - if batch_width > 0 then - -- fetch and dim colors - color = style.syntax[batch_syntax_type] - color = { color[1], color[2], color[3], color[4] * 0.5 } - renderer.draw_rect(batch_start, line_y, batch_width, char_height, color) - end - batch_syntax_type = type - batch_start = batch_start + batch_width - batch_width = 0 - end - - -- per line - local endidx = minimap_start_line + max_minmap_lines - endidx = math.min(endidx, line_count) - for idx=minimap_start_line,endidx do - batch_syntax_type = nil - batch_start = x - batch_width = 0 - - -- per token - for _, type, text in self.doc.highlighter:each_token(idx) do - -- flush prev batch - if not batch_syntax_type then batch_syntax_type = type end - if batch_syntax_type ~= type then - flush_batch(type) - end - - -- per character - for char in common.utf8_chars(text) do - if char == " " or char == "\n" then - flush_batch(type) - batch_start = batch_start + char_spacing - elseif batch_start + batch_width > minimap_cutoff_x then - flush_batch(type) - break - else - batch_width = batch_width + char_spacing - end - - end - end - flush_batch(nil) - line_y = line_y + line_spacing - end - - else -- render lines without syntax highlighting - - local function flush_batch() - if batch_width > 0 then - renderer.draw_rect(batch_start, line_y, batch_width, char_height, color) - end - batch_start = batch_start + batch_width - batch_width = 0 - end - - for idx=1,line_count-1 do - batch_start = x - batch_width = 0 - - for char in common.utf8_chars(self.doc.lines[idx]) do - if char == " " or char == "\n" then - flush_batch() - batch_start = batch_start + char_spacing - elseif batch_start + batch_width > minimap_cutoff_x then - flush_batch() - else - batch_width = batch_width + char_spacing - end - end - flush_batch() - line_y = line_y + line_spacing - end - - end +DocView.draw_scrollbar = function(self) + if not config.minimap_enabled then return prev_draw_scrollbar(self) end + + local x, y, w, h = self:get_scrollbar_rect() + + local highlight = self.hovered_scrollbar or self.dragging_scrollbar + local visual_color = highlight and style.scrollbar2 or style.scrollbar + + local _, cy, _, cy2 = self:get_content_bounds() + local lh = self:get_line_height() + local visible_lines_count = math.max(1, (cy2 - cy) / lh) + local visible_lines_start = math.max(1, math.floor(cy / lh)) + local scroller_height = visible_lines_count * line_spacing + local line_count = #self.doc.lines + + local visible_y = self.position.y + (visible_lines_start - 1) * line_spacing + + -- check if file is too large to fit inside the minimap area + local max_minmap_lines = math.floor(h / line_spacing) + local minimap_start_line = 1 + if is_file_too_large(self) then + + local scroll_pos = (visible_lines_start - 1) / + (line_count - visible_lines_count - 1) + scroll_pos = math.min(1.0, scroll_pos) -- 0..1, procent of visual area scrolled + + local scroll_pos_pixels = scroll_pos * (h - scroller_height) + visible_y = self.position.y + scroll_pos_pixels + + -- offset visible area if user is scrolling past end + local t = (line_count - visible_lines_start) / visible_lines_count + if t <= 1 then visible_y = visible_y + scroller_height * (1.0 - t) end + + minimap_start_line = visible_lines_start - + math.floor(scroll_pos_pixels / line_spacing) + minimap_start_line = math.max(1, math.min(minimap_start_line, + line_count - max_minmap_lines)) + end + + if config.minimap_draw_background then + renderer.draw_rect(x, y, w, h, style.minimap_background or style.background) + end + -- draw visual rect + renderer.draw_rect(x, visible_y, w, scroller_height, visual_color) + + -- time to draw the actual code, setup some local vars that are used in both highlighted and plain renderind. + local line_y = y + + -- when not using syntax highlighted rendering, just use the normal color but dim it 50%. + local color = style.syntax["normal"] + color = {color[1], color[2], color[3], color[4] * 0.5} + + -- we try to "batch" characters so that they can be rendered as just one rectangle instead of one for each. + local batch_width = 0 + local batch_start = x + local minimap_cutoff_x = x + config.minimap_width * SCALE + local batch_syntax_type = nil + local function flush_batch(type) + local old_color = color + color = style.syntax[batch_syntax_type] + if config.minimap_syntax_highlight and color ~= nil then + -- fetch and dim colors + color = {color[1], color[2], color[3], color[4] * 0.5} + else + color = old_color + end + if batch_width > 0 then + renderer.draw_rect(batch_start, line_y, batch_width, char_height, color) + end + batch_syntax_type = type + batch_start = batch_start + batch_width + batch_width = 0 + end + + -- render lines with syntax highlighting + if config.minimap_syntax_highlight then + + -- keep track of the highlight type, since this needs to break batches as well + batch_syntax_type = nil + + -- per line + local endidx = minimap_start_line + max_minmap_lines + endidx = math.min(endidx, line_count) + for idx = minimap_start_line, endidx do + batch_syntax_type = nil + batch_start = x + batch_width = 0 + + -- per token + for _, type, text in self.doc.highlighter:each_token(idx) do + -- flush prev batch + if not batch_syntax_type then batch_syntax_type = type end + if batch_syntax_type ~= type then flush_batch(type) end + + -- per character + for char in common.utf8_chars(text) do + if char == " " or char == "\n" then + flush_batch(type) + batch_start = batch_start + char_spacing + elseif char == " " then + flush_batch(type) + batch_start = batch_start + (char_spacing * config.minimap_tab_width) + elseif batch_start + batch_width > minimap_cutoff_x then + flush_batch(type) + break + else + batch_width = batch_width + char_spacing + end + + end + end + flush_batch(nil) + line_y = line_y + line_spacing + end + + else -- render lines without syntax highlighting + for idx = 1, line_count - 1 do + batch_start = x + batch_width = 0 + + for char in common.utf8_chars(self.doc.lines[idx]) do + if char == " " or char == "\n" then + flush_batch() + batch_start = batch_start + char_spacing + elseif batch_start + batch_width > minimap_cutoff_x then + flush_batch() + else + batch_width = batch_width + char_spacing + end + end + flush_batch() + line_y = line_y + line_spacing + end + + end end command.add(nil, { - ["minimap:toggle-visibility"] = function() - config.minimap_enabled = not config.minimap_enabled - end, - ["minimap:toggle-syntax-highlighting"] = function() - config.minimap_syntax_highlight = not config.minimap_syntax_highlight - end, + ["minimap:toggle-visibility"] = function() + config.minimap_enabled = not config.minimap_enabled + end, + ["minimap:toggle-syntax-highlighting"] = function() + config.minimap_syntax_highlight = not config.minimap_syntax_highlight + end }) -- cgit v1.2.3 From 261a20db99b0152f8baba7ea16272aa2559ec325 Mon Sep 17 00:00:00 2001 From: jgmdev Date: Wed, 7 Jul 2021 18:47:10 -0400 Subject: Added yaml language to README --- README.md | 1 + 1 file changed, 1 insertion(+) (limited to 'README.md') diff --git a/README.md b/README.md index 37a5b92..2edfbf7 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,7 @@ Plugin | Description [`language_tsx`](plugins/language_tsx.lua?raw=1) | Syntax for [TSX](https://www.typescriptlang.org/docs/handbook/jsx.html) language [`language_v`](plugins/language_v.lua?raw=1) | Syntax for the [V](https://vlang.io/) programming language [`language_wren`](plugins/language_wren.lua?raw=1) | Syntax for the [Wren](http://wren.io/) programming language +[`language_yaml`](plugins/language_yaml.lua?raw=1) | Syntax for [YAML](https://yaml.org/) serialization language [`language_zig`](plugins/language_zig.lua?raw=1) | Syntax for the [Zig](https://ziglang.org/) programming language ~~[`lastproject`](plugins/lastproject.lua?raw=1)~~ | Integrated with lite-xl ~~Loads the last loaded project if lite is launched without any arguments~~ [`lfautoinsert`](plugins/lfautoinsert.lua?raw=1) | Automatically inserts indentation and closing bracket/text after newline -- cgit v1.2.3 From 661f13314d3ea05e4ccd9cfe3266def42eb41b05 Mon Sep 17 00:00:00 2001 From: Francesco Abbate Date: Fri, 6 Aug 2021 19:16:32 +0200 Subject: Add syntax of Lobster language --- README.md | 1 + plugins/language_lobster.lua | 66 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 plugins/language_lobster.lua (limited to 'README.md') diff --git a/README.md b/README.md index 7a40002..1844e28 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ Plugin | Description [`language_jsx`](plugins/language_jsx.lua?raw=1) | Syntax for the [JSX](https://reactjs.org/docs/introducing-jsx.html) language for the React framework in JavaScript [`language_ksy`](https://raw.githubusercontent.com/whiteh0le/lite-plugins/main/plugins/language_ksy.lua?raw=1) | Syntax for [Kaitai](http://kaitai.io/) struct files [`language_liquid`](plugins/language_liquid.lua?raw=1) | Syntax for [Liquid](https://shopify.github.io/liquid/) templating language +[`language_lobster`](plugins/language_lobster.lua?raw=1) | Syntax for [Lobster](https://strlen.com/lobster/) programming language [`language_make`](plugins/language_make.lua?raw=1) | Syntax for the Make build system language [`language_meson`](plugins/language_meson.lua?raw=1) | Syntax for the [Meson](https://mesonbuild.com) build system language [`language_moon`](plugins/language_moon.lua?raw=1) | Syntax for the [MoonScript](https://moonscript.org) scripting language diff --git a/plugins/language_lobster.lua b/plugins/language_lobster.lua new file mode 100644 index 0000000..8b4d899 --- /dev/null +++ b/plugins/language_lobster.lua @@ -0,0 +1,66 @@ +-- mod-version:1 -- lite-xl 1.16 +local syntax = require "core.syntax" + +syntax.add { + files = "%.lobster$", + comment = "//", + patterns = { + { pattern = "//.-\n", type = "comment" }, + { pattern = { "/%*", "%*/" }, type = "comment" }, + + { pattern = "struct%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, + { pattern = "class%s()[%a_][%w_]*", type = {"keyword", "keyword2"} }, + { pattern = "import%s+from", type = "keyword" }, + + { pattern = { '"', '"', '\\' }, type = "string" }, + { pattern = { "'", "'", '\\' }, type = "string" }, + { pattern = { '"""', '"""' }, type = "string" }, + { pattern = "0x%x+", type = "number" }, + { pattern = "%d+[%d%.eE]*f?", type = "number" }, + { pattern = "%.?%d+f?", type = "number" }, + { pattern = "[%+%-=/%*%^%%<>!~|&]", type = "operator" }, + { pattern = "[%a_][%w_]*%f[(]", type = "function" }, + { pattern = "[%a_][%w_]*", type = "symbol" }, + }, + symbols = { + ["import"] = "keyword", + ["def"] = "keyword", + ["fn"] = "keyword", + ["return"] = "keyword", + ["program"] = "keyword", + ["private"] = "keyword", + ["resource"] = "keyword", + + -- not really keywords but provides control-flow constructs + ["if"] = "keyword", + ["for"] = "keyword", + ["while"] = "keyword", + ["else"] = "keyword", + + ["enum"] = "keyword", + ["enum_flags"] = "keyword", + + ["int"] = "keyword2", + ["float"] = "keyword2", + ["string"] = "keyword2", + ["any"] = "keyword2", + ["void"] = "keyword2", + + ["is"] = "keyword", + ["typeof"] = "keyword", + ["var"] = "keyword", + ["let"] = "keyword", + ["pakfile"] = "keyword", + ["switch"] = "keyword", + ["case"] = "keyword", + ["default"] = "keyword", + ["namespace"] = "keyword", + + ["not"] = "operator", + ["and"] = "operator", + ["or"] = "operator", + + ["nil"] = "literal", + }, +} + -- cgit v1.2.3 From bcfbb0c5cf7c1c087f7bc3bd37afde309322978c Mon Sep 17 00:00:00 2001 From: Timofffee Date: Mon, 16 Aug 2021 01:52:24 +0400 Subject: Add plugin --- README.md | 3 +- plugins/linenumbers.lua | 85 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 plugins/linenumbers.lua (limited to 'README.md') diff --git a/README.md b/README.md index 1844e28..250fdfd 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,7 @@ Plugin | Description [`lfautoinsert`](plugins/lfautoinsert.lua?raw=1) | Automatically inserts indentation and closing bracket/text after newline [`linecopypaste`](plugins/linecopypaste.lua?raw=1) | Copy, cut and paste the current line when nothing is selected [*`lineguide`*](plugins/lineguide.lua?raw=1) | Displays a line-guide at the line limit offset *([screenshot](https://user-images.githubusercontent.com/3920290/81476159-2cf70000-9208-11ea-928b-9dae3884c477.png))* +[`linenumbers`](plugins/linenumbers.lua?raw=1) | The ability to change the display of the line number *([screenshot](https://user-images.githubusercontent.com/5556081/129493788-6a4cbd7a-9074-4133-bab7-110ed55f18f7.png))* [`linter`](https://github.com/drmargarido/linters)* | Linters for multiple languages [`lint+`](https://github.com/liquid600pgm/lintplus)* | Advanced linter with ErrorLens-like error reporting. Compatible with linters made for `linter` *([screenshot](https://raw.githubusercontent.com/liquid600pgm/lintplus/master/screenshots/1.png))* [`macmodkeys`](plugins/macmodkeys.lua?raw=1) | Remaps mac modkeys `command/option` to `ctrl/alt` @@ -109,8 +110,8 @@ Plugin | Description ~~[`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. +[`restoretabs`](plugins/restoretabs.lua?raw=1) | Keep a list of recently closed tabs, and restore the tab in order on cntrl+shift+t. *[`scale`](plugins/scale.lua?raw=1)* | Provides support for dynamically adjusting the scale of the code font / UI (`ctrl+-`, `ctrl+=`) [`scalestatus`](plugins/scalestatus.lua?raw=1) | Displays current scale (zoom) in status view (depends on scale plugin) [`selectionhighlight`](plugins/selectionhighlight.lua?raw=1) | Highlights regions of code that match the current selection *([screenshot](https://user-images.githubusercontent.com/3920290/80710883-5f597c80-8ae7-11ea-97f0-76dfacc08439.png))* diff --git a/plugins/linenumbers.lua b/plugins/linenumbers.lua new file mode 100644 index 0000000..fde0a08 --- /dev/null +++ b/plugins/linenumbers.lua @@ -0,0 +1,85 @@ +-- mod-version:1 -- lite-xl 1.16 +local config = require "core.config" +local style = require "core.style" +local DocView = require "core.docview" +local common = require "core.common" +local command = require "core.command" + +local draw = DocView.draw_line_gutter +local get_width = DocView.get_gutter_width + +function DocView:draw_line_gutter(idx, x, y, width) + if not config.line_numbers and not config.relative_line_numbers then + return + end + + if config.relative_line_numbers then + + local color = style.line_number + local local_idx = idx + local align = "right" + + local l1 = self.doc:get_selection(false) + if idx == l1 then + color = style.line_number2 + if config.line_numbers then + align = "center" + else + local_idx = 0 + end + else + local_idx = math.abs(idx - l1) + end + + -- Fix for old version (<=1.16) + if width == nil then + local gpad = style.padding.x * 2 + local gw = self:get_font():get_width(#self.doc.lines) + gpad + width = gpad and gw - gpad or gw + end + + common.draw_text( + self:get_font(), + color, local_idx, align, + x + style.padding.x, + y + self:get_line_text_y_offset(), + width, self:get_line_height() + ) + else + draw(self, idx, x, y, width) + end +end + +function DocView:get_gutter_width(...) + if not config.line_numbers and not config.relative_line_numbers then + return style.padding.x + else + return get_width(self, ...) + end +end + +command.add(nil, { + ["line-numbers:toggle"] = function() + config.line_numbers = not config.line_numbers + end, + + ["line-numbers:disable"] = function() + config.line_numbers = false + end, + + ["line-numbers:enable"] = function() + config.line_numbers = true + end, + + ["relative-line-numbers:toggle"] = function() + config.relative_line_numbers = not config.relative_line_numbers + end, + + ["relative-line-numbers:enable"] = function() + config.relative_line_numbers = true + end, + + ["relative-line-numbers:disable"] = function() + config.relative_line_numbers = false + end +}) -- cgit v1.2.3