Compare commits
10 Commits
d424f9bd87
...
c000ea3150
| Author | SHA1 | Date | |
|---|---|---|---|
|
c000ea3150
|
|||
|
2f14f4a4be
|
|||
|
49e13ccce1
|
|||
|
2babc2fd1d
|
|||
|
852b93d000
|
|||
|
32fd2bfda3
|
|||
|
abf2343e59
|
|||
|
68ade44490
|
|||
|
04e50b5d14
|
|||
|
e8cee1b631
|
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1 +1 @@
|
|||||||
**/test**
|
p.vim
|
||||||
|
|||||||
116
README.md
116
README.md
@@ -1,6 +1,120 @@
|
|||||||
# UdiVim
|
# UdiVim - A MarkUp language.
|
||||||
|
|
||||||
> UDI stands for User Do It
|
> UDI stands for User Do It
|
||||||
|
|
||||||
It is a simple todo file format for handling your tasks.
|
It is a simple todo file format for handling your tasks.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- It renders to a neovim buffer.
|
||||||
|
- It handles neovim shortcuts for fast typing.
|
||||||
|
- It allows shortcuts to mark tasks as done etc.
|
||||||
|
- It can be easily interpreted by other programs. And human readers.
|
||||||
|
|
||||||
|
## Screenshot
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Syntax
|
||||||
|
|
||||||
|
### General
|
||||||
|
|
||||||
|
#### Colors
|
||||||
|
|
||||||
|
The colors are defined by using the following pattern
|
||||||
|
|
||||||
|
- `w` = white
|
||||||
|
- `k` = black
|
||||||
|
- `e` = gray
|
||||||
|
- `r` = red
|
||||||
|
- `g` = green
|
||||||
|
- `b` = blue
|
||||||
|
- `c` = cyan
|
||||||
|
- `m` = magenta
|
||||||
|
- `y` = yellow
|
||||||
|
- `t` = tan
|
||||||
|
- `o` = orange
|
||||||
|
- `p` = pink
|
||||||
|
|
||||||
|
```lua
|
||||||
|
local colors = {
|
||||||
|
w = "#d6e0f5",
|
||||||
|
k = "#0a0b11",
|
||||||
|
e = "#3b415e",
|
||||||
|
r = "#ff4f78",
|
||||||
|
g = "#b0e57c",
|
||||||
|
b = "#89b4fa",
|
||||||
|
c = "#8cdcff",
|
||||||
|
m = "#c5a3ff",
|
||||||
|
y = "#f5c97f",
|
||||||
|
t = "#be8c71",
|
||||||
|
o = "#ff9e64",
|
||||||
|
p = "#ff99c2",
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Task modes
|
||||||
|
|
||||||
|
Tasks can be marked as
|
||||||
|
|
||||||
|
- Todo `(0)`
|
||||||
|
- Done `(x)`
|
||||||
|
- Unimportant `($)`
|
||||||
|
- Important `(!)`
|
||||||
|
- Won't do `(^)`
|
||||||
|
|
||||||
|
### Topic
|
||||||
|
|
||||||
|
- A topic is defined by starting a line with an asterisk (*).
|
||||||
|
- It is always colored white bg with black fg.
|
||||||
|
|
||||||
|
### SubTopic
|
||||||
|
|
||||||
|
- A subtopic is defined by starting a line with a color code followed by a hash (#).
|
||||||
|
- It takes the bg color as coded and an appropriate fg color.
|
||||||
|
|
||||||
|
### Problem
|
||||||
|
|
||||||
|
- A problem is defined by starting a line with a color code followed by an at symbol (@) and then a task mode.
|
||||||
|
- ex: `d@0 Problem`
|
||||||
|
- It takes the bg color as coded and an appropriate fg color.
|
||||||
|
- And shows a marking based on the task mode.
|
||||||
|
|
||||||
|
### Task
|
||||||
|
|
||||||
|
- A task is defined by starting a line with a semicolon (;) followed by a task mode.
|
||||||
|
- ex: `;0 TODO`
|
||||||
|
- It takes colors based on the task mode.
|
||||||
|
- And shows a marking based on the task mode.
|
||||||
|
|
||||||
|
### Separator
|
||||||
|
|
||||||
|
- A separator is defined by starting a line with a `=` and can have as many `=` as you want.
|
||||||
|
- Its should be at the indentation level of the required seperate blocks you need.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```
|
||||||
|
* Topic
|
||||||
|
|
||||||
|
m# SubTopic:
|
||||||
|
|
||||||
|
d@0 Problem
|
||||||
|
|
||||||
|
;! Task
|
||||||
|
|
||||||
|
d@x hello?
|
||||||
|
|
||||||
|
;0 IDK
|
||||||
|
;! Hello
|
||||||
|
;x I SHOE
|
||||||
|
|
||||||
|
c@0 FUN
|
||||||
|
|
||||||
|
;0 Why?
|
||||||
|
;! MAYBE
|
||||||
|
;x NOO
|
||||||
|
==================================================
|
||||||
|
;x Hello
|
||||||
|
```
|
||||||
|
|
||||||
|
|||||||
432
lua/udivim.lua
432
lua/udivim.lua
@@ -1,78 +1,252 @@
|
|||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
local colors = {
|
local colors = {
|
||||||
w = "#ffffff",
|
w = "#d6e0f5",
|
||||||
k = "#000000",
|
k = "#0a0b11",
|
||||||
r = "#ff0000",
|
e = "#3b415e",
|
||||||
g = "#00ff00",
|
r = "#ff4f78",
|
||||||
b = "#0000ff",
|
g = "#b0e57c",
|
||||||
c = "#00ffff",
|
b = "#89b4fa",
|
||||||
y = "#ffff00",
|
c = "#8cdcff",
|
||||||
m = "#ff00ff",
|
m = "#c5a3ff",
|
||||||
|
y = "#f5c97f",
|
||||||
|
t = "#be8c71",
|
||||||
|
o = "#ff9e64",
|
||||||
|
p = "#ff99c2",
|
||||||
}
|
}
|
||||||
|
|
||||||
local function define_color(name, color_fg, color_bg, bold)
|
local colors_s = "wkerbgcmytopd"
|
||||||
|
local types = "!x0%^%$"
|
||||||
|
|
||||||
|
local function define_color(name, color_fg, color_bg, bold, underline, italic)
|
||||||
if bold == nil then
|
if bold == nil then
|
||||||
bold = true
|
bold = true
|
||||||
end
|
end
|
||||||
vim.api.nvim_set_hl(0, name, { fg = colors[color_fg], bg = colors[color_bg], bold = bold })
|
if underline == nil then
|
||||||
|
underline = false
|
||||||
|
end
|
||||||
|
if italic == nil then
|
||||||
|
italic = false
|
||||||
|
end
|
||||||
|
vim.api.nvim_set_hl(
|
||||||
|
0,
|
||||||
|
name,
|
||||||
|
{ fg = colors[color_fg], bg = colors[color_bg], bold = bold, underline = underline, italic = italic }
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function highlight_todo_items()
|
local function highlight_todo_items()
|
||||||
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
|
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
|
||||||
local ns_id = vim.api.nvim_create_namespace("udivim_namespace")
|
local ns_id = vim.api.nvim_create_namespace("udivim_namespace")
|
||||||
|
local mode = vim.api.nvim_get_mode().mode
|
||||||
|
local cursor = vim.api.nvim_win_get_cursor(0)[1]
|
||||||
vim.api.nvim_buf_clear_namespace(0, ns_id, 0, -1)
|
vim.api.nvim_buf_clear_namespace(0, ns_id, 0, -1)
|
||||||
for i, line in ipairs(lines) do
|
for i, line in ipairs(lines) do
|
||||||
if line:match("^%s*@") then
|
local use_virt = true
|
||||||
|
if mode:match("^i") and i == cursor then
|
||||||
|
use_virt = false
|
||||||
|
end
|
||||||
|
if line:match("^%s*[" .. colors_s .. "]@[" .. types .. "]") then
|
||||||
local idx2 = string.find(line, "@")
|
local idx2 = string.find(line, "@")
|
||||||
if line:match("") then
|
local color_code = line:sub(idx2 - 1, idx2 - 1)
|
||||||
local idx = string.find(line, "")
|
if line:match("@x") then
|
||||||
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx2 - 1, { end_col = idx - 2, hl_group = "fgkbgg" })
|
local idx = string.find(line, "x")
|
||||||
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx + 4, { end_col = #line, hl_group = "fgkbgg" })
|
local virt_text = use_virt and { { " ", "fgg" } } or nil
|
||||||
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx - 1, { end_col = idx + 3, hl_group = "fgg" })
|
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx2 - 2, {
|
||||||
elseif line:match("") then
|
end_col = idx,
|
||||||
local idx = string.find(line, "")
|
hl_group = "fgg",
|
||||||
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx2 - 1, { end_col = idx - 2, hl_group = "fgkbgy" })
|
virt_text = virt_text,
|
||||||
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx + 4, { end_col = #line, hl_group = "fgkbgy" })
|
virt_text_pos = "overlay",
|
||||||
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx - 1, { end_col = idx + 3, hl_group = "fgy" })
|
})
|
||||||
elseif line:match("") then
|
if color_code == "d" then
|
||||||
local idx = string.find(line, "")
|
color_code = "g"
|
||||||
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx2 - 1, { end_col = idx - 2, hl_group = "fgkbgr" })
|
end
|
||||||
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx + 4, { end_col = #line, hl_group = "fgkbgr" })
|
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx + 0, {
|
||||||
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx - 1, { end_col = idx + 3, hl_group = "fgr" })
|
end_col = #line,
|
||||||
|
hl_group = "fgkbg" .. color_code,
|
||||||
|
virt_text_win_col = vim.api.nvim_strwidth(line),
|
||||||
|
virt_text = { { " ", "fgkbg" .. color_code } },
|
||||||
|
})
|
||||||
|
elseif line:match("@0") then
|
||||||
|
local idx = string.find(line, "0")
|
||||||
|
local virt_text = use_virt and { { " ", "fgy" } } or nil
|
||||||
|
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx2 - 2, {
|
||||||
|
end_col = idx,
|
||||||
|
hl_group = "fgy",
|
||||||
|
virt_text = virt_text,
|
||||||
|
virt_text_pos = "overlay",
|
||||||
|
})
|
||||||
|
if color_code == "d" then
|
||||||
|
color_code = "y"
|
||||||
|
end
|
||||||
|
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx + 0, {
|
||||||
|
end_col = #line,
|
||||||
|
hl_group = "fgkbg" .. color_code,
|
||||||
|
virt_text_win_col = vim.api.nvim_strwidth(line),
|
||||||
|
virt_text = { { " ", "fgkbg" .. color_code } },
|
||||||
|
})
|
||||||
|
elseif line:match("@!") then
|
||||||
|
local idx = string.find(line, "!")
|
||||||
|
local virt_text = use_virt and { { " ", "fgr" } } or nil
|
||||||
|
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx2 - 2, {
|
||||||
|
end_col = idx,
|
||||||
|
hl_group = "fgr",
|
||||||
|
virt_text = virt_text,
|
||||||
|
virt_text_pos = "overlay",
|
||||||
|
})
|
||||||
|
if color_code == "d" then
|
||||||
|
color_code = "r"
|
||||||
|
end
|
||||||
|
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx + 0, {
|
||||||
|
end_col = #line,
|
||||||
|
hl_group = "fgkbg" .. color_code,
|
||||||
|
virt_text_win_col = vim.api.nvim_strwidth(line),
|
||||||
|
virt_text = { { " ", "fgkbg" .. color_code } },
|
||||||
|
})
|
||||||
|
elseif line:match("@%$") then
|
||||||
|
local idx = string.find(line, "%$")
|
||||||
|
local virt_text = use_virt and { { " ", "fge" } } or nil
|
||||||
|
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx2 - 2, {
|
||||||
|
end_col = idx,
|
||||||
|
hl_group = "fge",
|
||||||
|
virt_text = virt_text,
|
||||||
|
virt_text_pos = "overlay",
|
||||||
|
})
|
||||||
|
if color_code == "d" then
|
||||||
|
color_code = "e"
|
||||||
|
end
|
||||||
|
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx + 0, {
|
||||||
|
end_col = #line,
|
||||||
|
hl_group = "fgkbg" .. color_code,
|
||||||
|
virt_text_win_col = vim.api.nvim_strwidth(line),
|
||||||
|
virt_text = { { " ", "fgkbg" .. color_code } },
|
||||||
|
})
|
||||||
|
elseif line:match("@%^") then
|
||||||
|
local idx = string.find(line, "%^")
|
||||||
|
local virt_text = use_virt and { { " ", "fgp" } } or nil
|
||||||
|
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx2 - 2, {
|
||||||
|
end_col = idx,
|
||||||
|
hl_group = "fgp",
|
||||||
|
virt_text = virt_text,
|
||||||
|
virt_text_pos = "overlay",
|
||||||
|
})
|
||||||
|
if color_code == "d" then
|
||||||
|
color_code = "p"
|
||||||
|
end
|
||||||
|
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx + 0, {
|
||||||
|
end_col = #line,
|
||||||
|
hl_group = "fgkbg" .. color_code,
|
||||||
|
virt_text_win_col = vim.api.nvim_strwidth(line),
|
||||||
|
virt_text = { { " ", "fgkbg" .. color_code } },
|
||||||
|
})
|
||||||
else
|
else
|
||||||
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, 0, { end_col = #line, hl_group = "Identifier" })
|
vim.api.nvim_buf_set_extmark(
|
||||||
|
0,
|
||||||
|
ns_id,
|
||||||
|
i - 1,
|
||||||
|
0,
|
||||||
|
{ end_col = vim.api.nvim_strwidth(line), hl_group = "Identifier" }
|
||||||
|
)
|
||||||
end
|
end
|
||||||
elseif line:match("^%s*#") then
|
elseif line:match("^%s*[" .. colors_s .. "]# ") then
|
||||||
local idx = string.find(line, "#")
|
local idx = string.find(line, "#")
|
||||||
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx - 1, { end_col = #line, hl_group = "fgkbgw" })
|
local color_code = line:sub(idx - 1, idx - 1)
|
||||||
|
local virt_text = use_virt and { { "⟩ ", "fg" .. color_code } } or nil
|
||||||
|
if color_code == "d" then
|
||||||
|
color_code = "w"
|
||||||
|
end
|
||||||
|
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx - 0, {
|
||||||
|
end_col = #line,
|
||||||
|
hl_group = "fgkbg" .. color_code,
|
||||||
|
virt_text_win_col = vim.api.nvim_strwidth(line),
|
||||||
|
virt_text = { { " ", "fgkbg" .. color_code } },
|
||||||
|
})
|
||||||
|
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx - 2, {
|
||||||
|
end_col = idx + 1,
|
||||||
|
hl_group = "fg" .. color_code,
|
||||||
|
virt_text_win_col = idx - 2,
|
||||||
|
virt_text = virt_text,
|
||||||
|
})
|
||||||
elseif line:match("^%s*%*") then
|
elseif line:match("^%s*%*") then
|
||||||
local idx = string.find(line, "%*")
|
local idx = string.find(line, "%*")
|
||||||
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx - 1, { end_col = #line, hl_group = "fgkbgw" })
|
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx - 1, {
|
||||||
|
end_col = #line,
|
||||||
|
hl_group = "fgkbgw",
|
||||||
|
virt_text_win_col = vim.api.nvim_strwidth(line),
|
||||||
|
virt_text = { { " ", "fgkbgw" } },
|
||||||
|
})
|
||||||
elseif line:match("^%s*==*$") then
|
elseif line:match("^%s*==*$") then
|
||||||
local idx = string.find(line, "=")
|
local idx = string.find(line, "=")
|
||||||
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx - 1, { end_col = #line, hl_group = "Comment" })
|
vim.api.nvim_buf_set_extmark(
|
||||||
elseif line:match("^%s*%-%-") then
|
0,
|
||||||
|
ns_id,
|
||||||
|
i - 1,
|
||||||
|
idx - 1,
|
||||||
|
{ end_col = vim.api.nvim_strwidth(line), hl_group = "Comment" }
|
||||||
|
)
|
||||||
|
elseif line:match("^%s*%-%>") then
|
||||||
local idx = string.find(line, "%-")
|
local idx = string.find(line, "%-")
|
||||||
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx - 1, { end_col = #line, hl_group = "Comment" })
|
vim.api.nvim_buf_set_extmark(
|
||||||
else
|
0,
|
||||||
if line:match("") then
|
ns_id,
|
||||||
local idx = string.find(line, "")
|
i - 1,
|
||||||
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, 0, { end_col = idx - 1, hl_group = "Comment" })
|
idx - 1,
|
||||||
|
{ end_col = vim.api.nvim_strwidth(line), hl_group = "fgeu" }
|
||||||
|
)
|
||||||
|
elseif line:match("^%s*;[" .. types .. "] ") then
|
||||||
|
if line:match("^%s*;x") then
|
||||||
|
local idx = string.find(line, ";x")
|
||||||
|
local virt_text = use_virt and { { " ", "fgg" } } or nil
|
||||||
|
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, 0, {
|
||||||
|
end_col = idx + 1,
|
||||||
|
hl_group = "fgg",
|
||||||
|
virt_text = virt_text,
|
||||||
|
virt_text_win_col = idx - 1,
|
||||||
|
})
|
||||||
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx + 2, { end_col = #line, hl_group = "Comment" })
|
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx + 2, { end_col = #line, hl_group = "Comment" })
|
||||||
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx - 1, { end_col = idx + 2, hl_group = "fgg" })
|
elseif line:match("^%s*;0") then
|
||||||
elseif line:match("") then
|
local idx = string.find(line, ";0")
|
||||||
local idx = string.find(line, "")
|
local virt_text = use_virt and { { " ", "fgy" } } or nil
|
||||||
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, 0, { end_col = idx - 1, hl_group = "Comment" })
|
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, 0, {
|
||||||
|
end_col = idx + 1,
|
||||||
|
hl_group = "fgy",
|
||||||
|
virt_text = virt_text,
|
||||||
|
virt_text_win_col = idx - 1,
|
||||||
|
})
|
||||||
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx + 2, { end_col = #line, hl_group = "Identifier" })
|
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx + 2, { end_col = #line, hl_group = "Identifier" })
|
||||||
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx - 1, { end_col = idx + 2, hl_group = "fgy" })
|
elseif line:match("^%s*;!") then
|
||||||
elseif line:match("") then
|
local idx = string.find(line, ";!")
|
||||||
local idx = string.find(line, "")
|
local virt_text = use_virt and { { " ", "fgr" } } or nil
|
||||||
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, 0, { end_col = idx - 1, hl_group = "Comment" })
|
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, 0, {
|
||||||
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx + 2, { end_col = #line, hl_group = "Error" })
|
end_col = idx + 1,
|
||||||
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx - 1, { end_col = idx + 2, hl_group = "fgr" })
|
hl_group = "fgr",
|
||||||
|
virt_text = virt_text,
|
||||||
|
virt_text_win_col = idx - 1,
|
||||||
|
})
|
||||||
|
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx + 2, { end_col = #line, hl_group = "fgru" })
|
||||||
|
elseif line:match("^%s*;%$") then
|
||||||
|
local idx = string.find(line, ";%$")
|
||||||
|
local virt_text = use_virt and { { " ", "fge" } } or nil
|
||||||
|
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, 0, {
|
||||||
|
end_col = idx + 1,
|
||||||
|
hl_group = "fge",
|
||||||
|
virt_text = virt_text,
|
||||||
|
virt_text_win_col = idx - 1,
|
||||||
|
})
|
||||||
|
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx + 2, { end_col = #line, hl_group = "fgeu" })
|
||||||
|
elseif line:match("^%s*;%^") then
|
||||||
|
local idx = string.find(line, ";%^")
|
||||||
|
local virt_text = use_virt and { { " ", "fgp" } } or nil
|
||||||
|
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, 0, {
|
||||||
|
end_col = idx + 1,
|
||||||
|
hl_group = "fgp",
|
||||||
|
virt_text = virt_text,
|
||||||
|
virt_text_win_col = idx - 1,
|
||||||
|
})
|
||||||
|
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx + 2, { end_col = #line, hl_group = "fgpi" })
|
||||||
else
|
else
|
||||||
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, 0, { end_col = #line, hl_group = "Identifier" })
|
local idx = string.find(line, ";")
|
||||||
|
vim.api.nvim_buf_set_extmark(0, ns_id, i - 1, idx - 1, { end_col = #line, hl_group = "Comment" })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for match in line:gmatch("`(.-)`") do
|
for match in line:gmatch("`(.-)`") do
|
||||||
@@ -93,7 +267,7 @@ local function right(val)
|
|||||||
new_pos = { current_pos[1], current_pos[2] + 1 }
|
new_pos = { current_pos[1], current_pos[2] + 1 }
|
||||||
elseif val == -1 then
|
elseif val == -1 then
|
||||||
local line = vim.api.nvim_buf_get_lines(0, current_pos[1] - 1, current_pos[1], false)[1]
|
local line = vim.api.nvim_buf_get_lines(0, current_pos[1] - 1, current_pos[1], false)[1]
|
||||||
local end_of_line = #line
|
local end_of_line = vim.api.nvim_strwidth(line)
|
||||||
new_pos = { current_pos[1], end_of_line }
|
new_pos = { current_pos[1], end_of_line }
|
||||||
else
|
else
|
||||||
new_pos = { current_pos[1], val }
|
new_pos = { current_pos[1], val }
|
||||||
@@ -101,38 +275,13 @@ local function right(val)
|
|||||||
vim.api.nvim_win_set_cursor(0, new_pos)
|
vim.api.nvim_win_set_cursor(0, new_pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function replace_task_symbols()
|
|
||||||
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
|
|
||||||
for i, line in ipairs(lines) do
|
|
||||||
if line:match("%[x%]") then
|
|
||||||
local idx = string.find(line, "%[x%]")
|
|
||||||
vim.api.nvim_buf_set_text(0, i - 1, idx - 1, i - 1, idx + 2, { "" })
|
|
||||||
right()
|
|
||||||
elseif line:match("%[%-%]") then
|
|
||||||
local idx = string.find(line, "%[%-%]")
|
|
||||||
vim.api.nvim_buf_set_text(0, i - 1, idx - 1, i - 1, idx + 2, { "" })
|
|
||||||
right()
|
|
||||||
elseif line:match("%[!%]") then
|
|
||||||
local idx = string.find(line, "%[!%]")
|
|
||||||
vim.api.nvim_buf_set_text(0, i - 1, idx - 1, i - 1, idx + 2, { "" })
|
|
||||||
right()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function handle_inp()
|
local function handle_inp()
|
||||||
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
|
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
|
||||||
for i, line in ipairs(lines) do
|
for i, line in ipairs(lines) do
|
||||||
if line:match("^%s*#") then
|
if line:match("^%s*#$") then
|
||||||
if not line:match("^%s*# ") then
|
local idx = string.find(line, "#")
|
||||||
local idx = string.find(line, "#")
|
vim.api.nvim_buf_set_text(0, i - 1, 0, i - 1, idx + 0, { " d# " })
|
||||||
if not line:match("^%s*# ") then
|
right(-1)
|
||||||
vim.api.nvim_buf_set_text(0, i - 1, 0, i - 1, idx + 0, { " # " })
|
|
||||||
else
|
|
||||||
vim.api.nvim_buf_set_text(0, i - 1, 0, i - 1, idx + 0, { " #" })
|
|
||||||
end
|
|
||||||
right(-1)
|
|
||||||
end
|
|
||||||
elseif line:match("^%s*%*") then
|
elseif line:match("^%s*%*") then
|
||||||
if not line:match("^* ") then
|
if not line:match("^* ") then
|
||||||
local idx = string.find(line, "*")
|
local idx = string.find(line, "*")
|
||||||
@@ -143,19 +292,15 @@ local function handle_inp()
|
|||||||
end
|
end
|
||||||
right(-1)
|
right(-1)
|
||||||
end
|
end
|
||||||
elseif line:match("^%s*%@") then
|
elseif line:match("^%s*%@%s*$") then
|
||||||
if not line:match("^%s*@ []") then
|
local idx = string.find(line, "@")
|
||||||
local idx = string.find(line, "@")
|
vim.api.nvim_buf_set_text(0, i - 1, 0, i - 1, idx + 0, { " d@0 " })
|
||||||
vim.api.nvim_buf_set_text(0, i - 1, 0, i - 1, idx + 0, { " @ " })
|
right(-1)
|
||||||
right(-1)
|
elseif line:match("^%s*;%s*$") then
|
||||||
end
|
local idx = string.find(line, ";")
|
||||||
elseif line:match("^%s*;") then
|
vim.api.nvim_buf_set_text(0, i - 1, 0, i - 1, idx + 0, { " ;0 " })
|
||||||
if not line:match("^%s*;[]") then
|
right(-1)
|
||||||
local idx = string.find(line, ";")
|
elseif line:match("^%s*%=$") then
|
||||||
vim.api.nvim_buf_set_text(0, i - 1, 0, i - 1, idx + 0, { " ; " })
|
|
||||||
right(-1)
|
|
||||||
end
|
|
||||||
elseif line:match(" =$") then
|
|
||||||
local idx = string.find(line, "=")
|
local idx = string.find(line, "=")
|
||||||
vim.api.nvim_buf_set_text(
|
vim.api.nvim_buf_set_text(
|
||||||
0,
|
0,
|
||||||
@@ -166,9 +311,9 @@ local function handle_inp()
|
|||||||
{ "==================================================" }
|
{ "==================================================" }
|
||||||
)
|
)
|
||||||
right(-1)
|
right(-1)
|
||||||
elseif line:match(" %-$") then
|
elseif line:match("^%s*%-$") then
|
||||||
local idx = string.find(line, "%-")
|
local idx = string.find(line, "%-")
|
||||||
vim.api.nvim_buf_set_text(0, i - 1, 0, i - 1, idx + 0, { " -- " })
|
vim.api.nvim_buf_set_text(0, i - 1, 0, i - 1, idx + 0, { " -> " })
|
||||||
right(-1)
|
right(-1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -178,15 +323,22 @@ function M.toggle_todo()
|
|||||||
local line = vim.api.nvim_get_current_line()
|
local line = vim.api.nvim_get_current_line()
|
||||||
local pos = vim.api.nvim_win_get_cursor(0)
|
local pos = vim.api.nvim_win_get_cursor(0)
|
||||||
local i = pos[1]
|
local i = pos[1]
|
||||||
if line:match("") then
|
if line:match("^%s*[" .. colors_s .. "]@[" .. types .. "]") then
|
||||||
local idx = string.find(line, "")
|
local match = line:match("[" .. colors_s .. "]@([" .. types .. "])")
|
||||||
vim.api.nvim_buf_set_text(0, i - 1, idx - 1, i - 1, idx + 2, { "" })
|
local idx = line:find("[" .. colors_s .. "]@([" .. types .. "])")
|
||||||
elseif line:match("") then
|
if match == "x" then
|
||||||
local idx = string.find(line, "")
|
vim.api.nvim_buf_set_text(0, i - 1, idx + 1, i - 1, idx + 2, { "0" })
|
||||||
vim.api.nvim_buf_set_text(0, i - 1, idx - 1, i - 1, idx + 2, { "" })
|
else
|
||||||
elseif line:match("") then
|
vim.api.nvim_buf_set_text(0, i - 1, idx + 1, i - 1, idx + 2, { "x" })
|
||||||
local idx = string.find(line, "")
|
end
|
||||||
vim.api.nvim_buf_set_text(0, i - 1, idx - 1, i - 1, idx + 2, { "" })
|
elseif line:match("^%s*;[" .. types .. "]") then
|
||||||
|
local match = line:match(";([" .. types .. "]) ")
|
||||||
|
local idx = line:find(";([" .. types .. "]) ")
|
||||||
|
if match == "x" then
|
||||||
|
vim.api.nvim_buf_set_text(0, i - 1, idx + 0, i - 1, idx + 1, { "0" })
|
||||||
|
else
|
||||||
|
vim.api.nvim_buf_set_text(0, i - 1, idx + 0, i - 1, idx + 1, { "x" })
|
||||||
|
end
|
||||||
end
|
end
|
||||||
highlight_todo_items()
|
highlight_todo_items()
|
||||||
end
|
end
|
||||||
@@ -195,32 +347,58 @@ function M.toggle_imp()
|
|||||||
local line = vim.api.nvim_get_current_line()
|
local line = vim.api.nvim_get_current_line()
|
||||||
local pos = vim.api.nvim_win_get_cursor(0)
|
local pos = vim.api.nvim_win_get_cursor(0)
|
||||||
local i = pos[1]
|
local i = pos[1]
|
||||||
if line:match("") then
|
if line:match("[" .. colors_s .. "]@[" .. types .. "]") then
|
||||||
local idx = string.find(line, "")
|
local match = line:match("[" .. colors_s .. "]@([" .. types .. "])")
|
||||||
vim.api.nvim_buf_set_text(0, i - 1, idx - 1, i - 1, idx + 2, { "" })
|
local idx = line:find("[" .. colors_s .. "]@([" .. types .. "])")
|
||||||
elseif line:match("") then
|
if match == "!" then
|
||||||
local idx = string.find(line, "")
|
vim.api.nvim_buf_set_text(0, i - 1, idx + 1, i - 1, idx + 2, { "$" })
|
||||||
vim.api.nvim_buf_set_text(0, i - 1, idx - 1, i - 1, idx + 2, { "" })
|
elseif match == "0" then
|
||||||
elseif line:match("") then
|
vim.api.nvim_buf_set_text(0, i - 1, idx + 1, i - 1, idx + 2, { "!" })
|
||||||
local idx = string.find(line, "")
|
elseif match == "^" then
|
||||||
vim.api.nvim_buf_set_text(0, i - 1, idx - 1, i - 1, idx + 2, { "" })
|
vim.api.nvim_buf_set_text(0, i - 1, idx + 1, i - 1, idx + 2, { "0" })
|
||||||
|
elseif match == "$" then
|
||||||
|
vim.api.nvim_buf_set_text(0, i - 1, idx + 1, i - 1, idx + 2, { "^" })
|
||||||
|
elseif match == "x" then
|
||||||
|
vim.api.nvim_buf_set_text(0, i - 1, idx + 1, i - 1, idx + 2, { "!" })
|
||||||
|
end
|
||||||
|
elseif line:match(";[" .. types .. "]") then
|
||||||
|
local match = line:match(";([" .. types .. "]) ")
|
||||||
|
local idx = line:find(";([" .. types .. "]) ")
|
||||||
|
if match == "!" then
|
||||||
|
vim.api.nvim_buf_set_text(0, i - 1, idx + 0, i - 1, idx + 1, { "$" })
|
||||||
|
elseif match == "0" then
|
||||||
|
vim.api.nvim_buf_set_text(0, i - 1, idx + 0, i - 1, idx + 1, { "!" })
|
||||||
|
elseif match == "^" then
|
||||||
|
vim.api.nvim_buf_set_text(0, i - 1, idx + 0, i - 1, idx + 1, { "0" })
|
||||||
|
elseif match == "$" then
|
||||||
|
vim.api.nvim_buf_set_text(0, i - 1, idx + 0, i - 1, idx + 1, { "^" })
|
||||||
|
elseif match == "x" then
|
||||||
|
vim.api.nvim_buf_set_text(0, i - 1, idx + 0, i - 1, idx + 1, { "!" })
|
||||||
|
end
|
||||||
end
|
end
|
||||||
highlight_todo_items()
|
highlight_todo_items()
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.setup()
|
function M.setup()
|
||||||
local define_grps = {
|
local define_grps = {}
|
||||||
["fgg"] = { "g" },
|
for key, _ in pairs(colors) do
|
||||||
["fgy"] = { "y" },
|
if key ~= "k" and key ~= "e" then
|
||||||
["fgr"] = { "r" },
|
define_grps["fg" .. key] = { key }
|
||||||
["fgkbgg"] = { "k", "g" },
|
define_grps["fgkbg" .. key] = { "k", key }
|
||||||
["fgkbgy"] = { "k", "y" },
|
end
|
||||||
["fgkbgr"] = { "k", "r" },
|
end
|
||||||
["fgkbgw"] = { "k", "w" },
|
|
||||||
}
|
|
||||||
for name, color in pairs(define_grps) do
|
for name, color in pairs(define_grps) do
|
||||||
define_color(name, color[1], color[2])
|
define_color(name, color[1], color[2])
|
||||||
|
define_color(name .. "u", color[1], color[2], false, true)
|
||||||
|
define_color(name .. "i", color[1], color[2], true, false, true)
|
||||||
end
|
end
|
||||||
|
define_color("fgk", "w", nil, true)
|
||||||
|
define_color("fgkbgk", "w", "k")
|
||||||
|
define_color("fge", "e", nil, true)
|
||||||
|
define_color("fgkbge", "w", "e")
|
||||||
|
define_color("fgkbgei", "w", "e", false, false, true)
|
||||||
|
define_color("fgeu", "w", nil, false, false, true)
|
||||||
|
define_color("fgpi", "p", nil, false, false, true)
|
||||||
vim.api.nvim_create_autocmd({ "BufRead", "BufNewFile" }, {
|
vim.api.nvim_create_autocmd({ "BufRead", "BufNewFile" }, {
|
||||||
pattern = "*.udi",
|
pattern = "*.udi",
|
||||||
callback = function()
|
callback = function()
|
||||||
@@ -265,7 +443,6 @@ function M.setup()
|
|||||||
vim.bo.expandtab = true
|
vim.bo.expandtab = true
|
||||||
vim.opt_local.foldmethod = "indent"
|
vim.opt_local.foldmethod = "indent"
|
||||||
vim.opt_local.foldlevel = 99
|
vim.opt_local.foldlevel = 99
|
||||||
replace_task_symbols()
|
|
||||||
highlight_todo_items()
|
highlight_todo_items()
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
@@ -279,11 +456,22 @@ function M.setup()
|
|||||||
if #current_text > #prev_text then
|
if #current_text > #prev_text then
|
||||||
handle_inp()
|
handle_inp()
|
||||||
end
|
end
|
||||||
replace_task_symbols()
|
|
||||||
highlight_todo_items()
|
highlight_todo_items()
|
||||||
vim.b.prev_content = current_content
|
vim.b.prev_content = current_content
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
vim.api.nvim_create_autocmd("TextChanged", {
|
||||||
|
pattern = "*.udi",
|
||||||
|
callback = function()
|
||||||
|
highlight_todo_items()
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, {
|
||||||
|
pattern = "*.udi",
|
||||||
|
callback = function()
|
||||||
|
highlight_todo_items()
|
||||||
|
end,
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
Reference in New Issue
Block a user