Skip to content

Commit fa0aabd

Browse files
committed
✨ feat: Add keyword highlighting for TODO, BUG, NOTE
0 parents  commit fa0aabd

File tree

6 files changed

+335
-0
lines changed

6 files changed

+335
-0
lines changed

README.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# notice-me
2+
3+
A Neovim plugin that highlights important keywords in your code like TODO, BUG, and NOTE.
4+
5+
## Features
6+
7+
- Highlights keywords with different colors:
8+
- TODO (green)
9+
- BUG (red)
10+
- NOTE (yellow)
11+
- Automatically applies highlighting when entering buffers or after saving
12+
- Toggle keyword highlighting on/off with a command
13+
14+
## Installation
15+
16+
Using [packer.nvim](https://github.com/wbthomason/packer.nvim):
17+
18+
```lua
19+
use {
20+
'yourusername/notice-me',
21+
config = function()
22+
require('notice-me').setup({
23+
-- Optional custom configuration
24+
})
25+
end
26+
}
27+
```
28+
29+
Using [lazy.nvim](https://github.com/folke/lazy.nvim):
30+
31+
```lua
32+
{
33+
'yourusername/notice-me',
34+
config = function()
35+
require('notice-me').setup({
36+
-- Optional custom configuration
37+
})
38+
end
39+
}
40+
```
41+
42+
## Configuration
43+
44+
notice-me comes with the following defaults:
45+
46+
```lua
47+
{
48+
enable = true,
49+
keywords = {
50+
TODO = { fg = "#00ff00" }, -- green
51+
BUG = { fg = "#ff0000" }, -- red
52+
NOTE = { fg = "#ffff00" } -- yellow
53+
}
54+
}
55+
```
56+
57+
You can customize the plugin by passing options to the setup function:
58+
59+
```lua
60+
require('notice-me').setup({
61+
enable = true, -- Enable/disable the plugin
62+
keywords = {
63+
TODO = { fg = "#00ff00" }, -- green
64+
BUG = { fg = "#ff0000" }, -- red
65+
NOTE = { fg = "#ffff00" }, -- yellow
66+
IMPORTANT = { fg = "#ff00ff" }, -- add your own keywords and colors
67+
}
68+
})
69+
```
70+
71+
## Usage
72+
73+
The plugin automatically highlights keywords in all buffers.
74+
75+
## Commands
76+
77+
- `:NoticeMe`: Display which keywords are being highlighted
78+
- `:NoticeMeToggle`: Toggle keyword highlighting on/off
79+
80+
## API
81+
82+
```lua
83+
-- Manually highlight keywords in the current buffer
84+
require('notice-me').highlight_keywords(vim.api.nvim_get_current_buf())
85+
86+
-- Example function that displays highlighted keywords
87+
require('notice-me').example_function()
88+
```
89+
90+
## License
91+
92+
MIT

doc/notice-me.txt

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
*notice-me.txt* A plugin for Neovim
2+
3+
==============================================================================
4+
CONTENTS *notice-me-contents*
5+
6+
1. Introduction ................. |notice-me-introduction|
7+
2. Installation ................. |notice-me-installation|
8+
3. Configuration ................ |notice-me-configuration|
9+
4. Usage ........................ |notice-me-usage|
10+
5. Commands ..................... |notice-me-commands|
11+
6. API .......................... |notice-me-api|
12+
7. License ...................... |notice-me-license|
13+
14+
==============================================================================
15+
1. INTRODUCTION *notice-me-introduction*
16+
17+
A Neovim plugin for [brief description of what your plugin does].
18+
19+
==============================================================================
20+
2. INSTALLATION *notice-me-installation*
21+
22+
Using packer.nvim:
23+
>
24+
use {
25+
'yourusername/notice-me',
26+
config = function()
27+
require('notice-me').setup({
28+
-- your configuration goes here
29+
})
30+
end
31+
}
32+
<
33+
34+
Using lazy.nvim:
35+
>
36+
{
37+
'yourusername/notice-me',
38+
config = function()
39+
require('notice-me').setup({
40+
-- your configuration goes here
41+
})
42+
end
43+
}
44+
<
45+
46+
==============================================================================
47+
3. CONFIGURATION *notice-me-configuration*
48+
49+
notice-me comes with the following defaults:
50+
>
51+
{
52+
enable = true,
53+
-- Add more options as needed
54+
}
55+
<
56+
57+
==============================================================================
58+
4. USAGE *notice-me-usage*
59+
60+
Describe how to use your plugin here.
61+
62+
==============================================================================
63+
5. COMMANDS *notice-me-commands*
64+
65+
:NoticeMe *:NoticeMe*
66+
Example command that calls the example function.
67+
68+
==============================================================================
69+
6. API *notice-me-api*
70+
71+
require('notice-me').example_function() *notice-me.example_function()*
72+
Example function description.
73+
74+
==============================================================================
75+
7. LICENSE *notice-me-license*
76+
77+
MIT
78+
79+
==============================================================================
80+
vim:tw=78:ts=8:ft=help:norl:

lua/notice-me/init.lua

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
local M = {}
2+
3+
-- Plugin configuration with default values
4+
M.config = {
5+
enable = true,
6+
keywords = {
7+
TODO = { fg = "#00ff00" }, -- green
8+
BUG = { fg = "#ff0000" }, -- red
9+
NOTE = { fg = "#ffff00" } -- yellow
10+
}
11+
}
12+
13+
-- Function to setup the plugin with user config
14+
function M.setup(opts)
15+
-- Merge user config with defaults
16+
opts = opts or {}
17+
M.config = vim.tbl_deep_extend("force", M.config, opts)
18+
19+
-- Initialize your plugin here
20+
M.setup_highlights()
21+
M.setup_autocmds()
22+
23+
-- Return the module for chaining
24+
return M
25+
end
26+
27+
-- Set up highlights for keywords
28+
function M.setup_highlights()
29+
local ns_id = vim.api.nvim_create_namespace("notice_me")
30+
M.namespace = ns_id
31+
32+
-- Create highlight groups
33+
for keyword, color in pairs(M.config.keywords) do
34+
vim.api.nvim_set_hl(0, "NoticeMe" .. keyword, color)
35+
end
36+
end
37+
38+
-- Set up autocommands to apply highlighting
39+
function M.setup_autocmds()
40+
vim.api.nvim_create_autocmd({"BufEnter", "BufWritePost"}, {
41+
callback = function(args)
42+
if not M.config.enable then return end
43+
M.highlight_keywords(args.buf)
44+
end,
45+
desc = "Notice-me highlight keywords on buffer enter/write",
46+
})
47+
48+
-- Also highlight current buffer immediately
49+
vim.schedule(function()
50+
if vim.api.nvim_get_current_buf() then
51+
M.highlight_keywords(vim.api.nvim_get_current_buf())
52+
end
53+
end)
54+
end
55+
56+
-- Highlight keywords in a buffer
57+
function M.highlight_keywords(bufnr)
58+
if not bufnr or not vim.api.nvim_buf_is_valid(bufnr) then return end
59+
60+
-- Clear previous highlights
61+
vim.api.nvim_buf_clear_namespace(bufnr, M.namespace, 0, -1)
62+
63+
-- Get buffer content
64+
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
65+
66+
-- Highlight keywords
67+
for i, line in ipairs(lines) do
68+
for keyword, _ in pairs(M.config.keywords) do
69+
local start_idx = 1
70+
while true do
71+
local match_start, match_end = line:find(keyword, start_idx)
72+
if not match_start then break end
73+
74+
-- Apply highlight
75+
vim.api.nvim_buf_add_highlight(
76+
bufnr,
77+
M.namespace,
78+
"NoticeMe" .. keyword,
79+
i - 1,
80+
match_start - 1,
81+
match_end
82+
)
83+
84+
start_idx = match_end + 1
85+
end
86+
end
87+
end
88+
end
89+
90+
-- Example function implementation
91+
function M.example_function()
92+
print("Notice-me plugin function called!")
93+
print("Keywords being highlighted:", vim.inspect(vim.tbl_keys(M.config.keywords)))
94+
end
95+
96+
return M

lua/notice-me/utils.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
local M = {}
2+
3+
-- Example utility function
4+
function M.is_enabled()
5+
local notice_me = require("notice-me")
6+
return notice_me.config.enable
7+
end
8+
9+
-- Add more utility functions as needed
10+
11+
return M

plugin/notice-me.lua

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
if vim.g.loaded_notice_me then
2+
return
3+
end
4+
vim.g.loaded_notice_me = true
5+
6+
-- Initialize the plugin
7+
require("notice-me").setup()
8+
9+
-- Create user commands
10+
vim.api.nvim_create_user_command("NoticeMe", function()
11+
require("notice-me").example_function()
12+
end, { desc = "Example notice-me command" })
13+
14+
vim.api.nvim_create_user_command("NoticeMeToggle", function()
15+
local notice_me = require("notice-me")
16+
notice_me.config.enable = not notice_me.config.enable
17+
18+
if notice_me.config.enable then
19+
-- Reapply highlights on current buffer
20+
notice_me.highlight_keywords(vim.api.nvim_get_current_buf())
21+
vim.notify("Keyword highlighting enabled")
22+
else
23+
-- Clear highlights on current buffer
24+
local bufnr = vim.api.nvim_get_current_buf()
25+
vim.api.nvim_buf_clear_namespace(bufnr, notice_me.namespace, 0, -1)
26+
vim.notify("Keyword highlighting disabled")
27+
end
28+
end, { desc = "Toggle notice-me keyword highlighting" })

tests/notice-me_spec.lua

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
local notice_me = require("notice-me")
2+
3+
describe("notice-me", function()
4+
it("can be required", function()
5+
assert.truthy(notice_me)
6+
end)
7+
8+
it("has setup function", function()
9+
assert.truthy(notice_me.setup)
10+
assert.is_function(notice_me.setup)
11+
end)
12+
13+
it("has example_function", function()
14+
assert.truthy(notice_me.example_function)
15+
assert.is_function(notice_me.example_function)
16+
end)
17+
18+
it("can be configured", function()
19+
local original_config = vim.deepcopy(notice_me.config)
20+
21+
-- Test with custom config
22+
notice_me.setup({ enable = false })
23+
assert.equals(false, notice_me.config.enable)
24+
25+
-- Reset config
26+
notice_me.config = original_config
27+
end)
28+
end)

0 commit comments

Comments
 (0)