diff options
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | plugins/drawwhitespace.lua | 29 | ||||
-rw-r--r-- | plugins/selectionhighlight.lua | 26 |
3 files changed, 58 insertions, 0 deletions
@@ -12,6 +12,7 @@ Plugin | Description -------|----------------------------------------- [`autowrap`](plugins/autowrap.lua?raw=1) | Automatically hardwraps lines when typing [`bracketmatch`](plugins/bracketmatch.lua?raw=1) | [Underlines](https://user-images.githubusercontent.com/3920290/80132745-0c863f00-8594-11ea-8875-c455c6fd7eae.png) matching right-bracket of left-bracket under caret +[`drawwhitespace`](plugins/drawwhitespace.lua?raw=1) | [Draws](https://user-images.githubusercontent.com/3920290/80573013-22ae5800-89f7-11ea-9895-6362a1c0abc7.png) tabs and spaces [`eval`](plugins/eval.lua?raw=1) | Replaces selected Lua code with its evaluated result [`gofmt`](plugins/gofmt.lua?raw=1) | Auto-formats the current go file, adds the missing imports and the missing return cases [`indentguide`](plugins/indentguide.lua?raw=1) | Adds [indent guides](https://user-images.githubusercontent.com/3920290/79640716-f9860000-818a-11ea-9c3b-26d10dd0e0c0.png) @@ -27,9 +28,11 @@ Plugin | Description [`language_wren`](plugins/language_wren.lua?raw=1) | Syntax for the [Wren](http://wren.io/) programming language [`linter`](https://github.com/drmargarido/linters)* | Linters for multiple languages [`macmodkeys`](plugins/macmodkeys.lua?raw=1) | Remaps mac modkeys `command/option` to `ctrl/alt` +[`selectionhighlight`](plugins/selectionhighlight.lua?raw=1) | Highlights regions of code that match the current selection [`sort`](plugins/sort.lua?raw=1) | Sorts selected lines alphabetically [`spellcheck`](plugins/spellcheck.lua?raw=1) | [Underlines](https://user-images.githubusercontent.com/3920290/79923973-9caa7400-842e-11ea-85d4-7a196a91ca50.png) misspelt words [`theme16`](https://github.com/monolifed/theme16)* | Theme manager with base16 themes [`titleize`](plugins/titleize.lua?raw=1) | Titleizes selected string (`hello world` => `Hello World`) [`todotreeview`](https://github.com/drmargarido/TodoTreeView)* | Todo tree viewer for anotations in code like `TODO`, `BUG`, `FIX`, `IMPROVEMENT` [`togglesnakecamel`](plugins/togglesnakecamel.lua?raw=1) | Toggles symbols between `snake_case` and `camelCase` + diff --git a/plugins/drawwhitespace.lua b/plugins/drawwhitespace.lua new file mode 100644 index 0000000..b121833 --- /dev/null +++ b/plugins/drawwhitespace.lua @@ -0,0 +1,29 @@ +local config = require "core.config" +local style = require "core.style" +local DocView = require "core.docview" + +-- originally written by luveti + +config.whitespace_map = { [" "] = "·", ["\t"] = "»" } + +local draw_line_text = DocView.draw_line_text + +function DocView:draw_line_text(idx, x, y) + draw_line_text(self, idx, x, y) + + local cl = self:get_cached_line(idx) + local tx, ty = x, y + self:get_line_text_y_offset() + local font = self:get_font() + local color = style.whitespace or style.syntax.comment + local map = config.whitespace_map + + for i = 1, #cl.text do + local chr = cl.text:sub(i, i) + local rep = map[chr] + if rep then + renderer.draw_text(font, rep, tx, ty, color) + end + tx = tx + font:get_width(chr) + end +end + diff --git a/plugins/selectionhighlight.lua b/plugins/selectionhighlight.lua new file mode 100644 index 0000000..31a5042 --- /dev/null +++ b/plugins/selectionhighlight.lua @@ -0,0 +1,26 @@ +local style = require "core.style" +local DocView = require "core.docview" + +-- originally written by luveti + +local draw_line_body = DocView.draw_line_body + +function DocView:draw_line_body(idx, x, y) + local line1, col1, line2, col2 = self.doc:get_selection(true) + if line1 == line2 and col1 ~= col2 then + local lh = self:get_line_height() + local selected_text = self:get_cached_line(line1).text:sub(col1, col2 - 1) + local current_line_text = self:get_cached_line(idx).text + local last_col = 1 + while true do + local start_col, end_col = current_line_text:find(selected_text, last_col, true) + if start_col == nil then break end + local x1 = x + self:get_col_x_offset(idx, start_col) + local x2 = x + self:get_col_x_offset(idx, end_col + 1) + renderer.draw_rect(x1, y, x2 - x1, lh, style.selection) + last_col = end_col + 1 + end + end + draw_line_body(self, idx, x, y) +end + |