Initial commit

This commit is contained in:
Patrick Alvin Alcala 2025-06-26 16:53:43 +08:00
commit 209ba130c0
4852 changed files with 1517959 additions and 0 deletions

View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2023 Francisco Barreiras
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.

View file

@ -0,0 +1,41 @@
# Code+
> A quality of life plugin for the Lite XL text editor. Offering improvements such as highlighted comments and autocomplete for brackets, quotes and more.
## Basic usage
Highlight comments with special properties using the **@Todo(...)** and **@Fixme(...)** keywords for an enhanced coding experience.
Streamline coding by auto-completing brackets, parentheses, quotation marks reducing manual effort and improving the writing code experience.
## Demonstration
![Code+ demo](https://s12.gifyu.com/images/Sckre.gif)
## Instalation
Navigate to the `data/plugins` folder and run the following command:
```bash
git clone https://github.com/chqs-git/code-plus.git
```
Alternatively you can download and rename the `init.lua ` file to `code+.lua` and drop it into the `data/plugins` folder.
## Configuration
Using the settings plugin for Lite Xl you can easily configure your experience by changing the highlight colors for the *@todo* and *@fixme* operators.
If you wish to add more highlights you can simply update the following code:
```lua
function DocView:draw_line_text(line, x, y)
local lh = draw_line_text(self, line, x, y)
if config.plugins.code_plus.enabled then
highlight_comment(self, line, x, y, "@todo", config.plugins.code_plus.todo)
highlight_comment(self, line, x, y, "@fixme", config.plugins.code_plus.fixme)
-- add a new highlight! the color is just an example
highlight_comment(self, line, x, y, "@new_tag", {common.color "#ffffff"})
end
return lh
end
```
To extend the already auto-completing utilities to other keywords, you can simply use the `complete` function. Create a new command for the new auto-complete utility (required) and map a *key* to the command.

View file

@ -0,0 +1,110 @@
-- mod-version:3
local config = require "core.config"
local command = require "core.command"
local keymap = require "core.keymap"
local common = require "core.common"
local DocView = require "core.docview"
config.plugins.code_plus = common.merge({
enabled = true, --- enabled by default
config_spec = { --- config specification used by the settings gui
name = "Code+",
{
label = "Enable",
description = "Toggle to enable this plugin.",
path = "enabled",
type = "toggle",
default = true
},
{
label = "Todo Color",
description = "Define the color that highlights the todo comments.",
path = "todo",
type = "color",
default = "#5592CF"
},
{
label = "Fixme Color",
description = "Defines the color that highlights the fixme comments.",
path = "fixme",
type = "color",
default = "#EF6385"
},
}
}, config.plugins.code_plus)
--- draw comments highlights
local white = { common.color "#ffffff" }
local function draw_highlight(self, str, line, x, y, s, e, color)
local x1 = x + self:get_col_x_offset(line, s)
local x2 = x + self:get_col_x_offset(line, e + 1)
local oy = self:get_line_text_y_offset()
renderer.draw_rect(x1, y, x2 - x1, self:get_line_height(), color)
renderer.draw_text(self:get_font(), str, x1, y + oy, white)
end
local function highlight_comment(self, line, x, y, comment, color)
local text = self.doc.lines[line]
local s, e = 0, 0
while true do
s, e = text:lower():find(comment .. "%((.-)%)", e + 1)
if s then
local str = text:sub(s, e)
draw_highlight(self, str, line, x, y, s, e, color)
end
if not s then
break
end
end
end
local draw_line_text = DocView.draw_line_text
function DocView:draw_line_text(line, x, y)
local lh = draw_line_text(self, line, x, y)
if config.plugins.code_plus.enabled then
highlight_comment(self, line, x, y, "@todo", config.plugins.code_plus.todo)
highlight_comment(self, line, x, y, "@fixme", config.plugins.code_plus.fixme)
end
return lh
end
--- auto complete brackets, parantheses, etc...
local function complete(dv, characters)
local doc = dv.doc
local idx = dv.doc.last_selection
local line1, col1 = doc:get_selection_idx(idx)
doc:insert(line1, col1, characters)
doc:move_to_cursor(idx, idx)
end
command.add("core.docview!", {
["code_plus:complete_brackets"] = function(dv)
complete(dv, "[]")
end,
["code_plus:complete_curly_brackets"] = function(dv)
complete(dv, "{}")
end,
["code_plus:complete_parantheses"] = function(dv)
complete(dv, "()")
end,
["code_plus:complete_quotation_marks"] = function(dv)
complete(dv, '""')
end,
})
keymap.add {
["altgr+8"] = "code_plus:complete_brackets",
["ctrl+alt+8"] = "code_plus:complete_brackets",
["altgr+7"] = "code_plus:complete_curly_brackets",
["ctrl+alt+7"] = "code_plus:complete_curly_brackets",
["shift+8"] = "code_plus:complete_parantheses",
["shift+2"] = "code_plus:complete_quotation_marks"
}

View file

@ -0,0 +1,12 @@
{
"addons": [
{
"id": "codeplus",
"mod_version": "3",
"name": "codeplus",
"path": ".",
"type": "plugin",
"version": "0.1"
}
]
}