diff options
author | rxi <rxi@users.noreply.github.com> | 2020-04-18 15:43:00 +0100 |
---|---|---|
committer | rxi <rxi@users.noreply.github.com> | 2020-04-18 15:43:00 +0100 |
commit | dc4c196706b2eb92d16a69a935b12fae88613c06 (patch) | |
tree | b6c750940be96afbb2b9e79233dec58299c86b7c | |
parent | 324f59283f2d42f764f98194f7895b09b6746488 (diff) | |
download | lite-xl-plugins-dc4c196706b2eb92d16a69a935b12fae88613c06.tar.gz lite-xl-plugins-dc4c196706b2eb92d16a69a935b12fae88613c06.zip |
Added `indentguide` plugin
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | indentguide.lua | 40 |
2 files changed, 41 insertions, 0 deletions
@@ -8,6 +8,7 @@ Plugin | Description -------|----------------------------------------- [`autowrap`](autowrap.lua?raw=1) | Automatically hardwraps lines when typing [`gofmt`](gofmt.lua?raw=1) | Auto-formats the current go file, adds the missing imports and the missing return cases +[`indentguide`](indentguide.lua?raw=1) | Adds [indent guides](https://user-images.githubusercontent.com/3920290/79640716-f9860000-818a-11ea-9c3b-26d10dd0e0c0.png) [`language_fe`](language_fe.lua?raw=1) | Syntax for the [fe](https://github.com/rxi/fe) programming language [`language_go`](language_go.lua?raw=1) | Syntax for the [Go](https://golang.org/) programming language [`language_jiyu`](language_jiyu.lua?raw=1) | Syntax for the [jiyu](https://github.com/machinamentum/jiyu) programming language diff --git a/indentguide.lua b/indentguide.lua new file mode 100644 index 0000000..9d903b7 --- /dev/null +++ b/indentguide.lua @@ -0,0 +1,40 @@ +local style = require "core.style" +local config = require "core.config" +local DocView = require "core.docview" + + +local function get_line_spaces(doc, idx, dir) + local text = doc.lines[idx] + if not text then + return 0 + end + local s, e = text:find("^%s*") + if e == #text then + return get_line_spaces(doc, idx + dir, dir) + end + return e - s + 1 +end + + +local function get_line_indent_guide_spaces(doc, idx) + if doc.lines[idx]:find("^%s*\n") then + return math.max( + get_line_spaces(doc, idx - 1, -1), + get_line_spaces(doc, idx + 1, 1)) + end + return get_line_spaces(doc, idx) +end + + +local draw_line_text = DocView.draw_line_text + +function DocView:draw_line_text(idx, x, y) + local spaces = get_line_indent_guide_spaces(self.doc, idx) + local sw = self:get_font():get_width(" ") + local h = self:get_line_height() + for i = 0, spaces - 1, config.indent_size do + local color = style.guide or style.selection + renderer.draw_rect(x + sw * i, y, style.divider_size, h, color) + end + draw_line_text(self, idx, x, y) +end |