Skip to content

Commit

Permalink
feat: Allow setting limits to the match length (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
F authored Feb 25, 2024
1 parent b5c45c0 commit 873c7f6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ require('local-highlight').setup({
cw_hlgroup = nil,
-- Whether to display highlights in INSERT mode or not
insert_mode = false,
min_match_len = 1,
max_match_len = math.huge,
})
```

Expand Down Expand Up @@ -80,6 +82,10 @@ attach to any buffer on its own, and will leave all attach logic to the user.

If set to `true`, will also work during insert mode.

## `min_match_len` and `max_match_len`

Set lower and upper limits on the length of the word being matched.

## API

If you want to directly attach the plugin to your buffers, you can use any
Expand Down
8 changes: 8 additions & 0 deletions doc/local-highlight.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Table of Contents *local-highlight-table-of-contents*
- cw_hlgroup |local-highlight-setup-cw_hlgroup|
- file_types and disable_file_types|local-highlight-setup-file_types-and-disable_file_types|
- insert_mode |local-highlight-setup-insert_mode|
- min_match_len and max_match_len |local-highlight-min-max-match-len|
- API |local-highlight-setup-api|
- Callbacks |local-highlight-setup-callbacks|
6. User Commands |local-highlight-user-commands|
Expand Down Expand Up @@ -78,6 +79,8 @@ You can setup local-highlight`as follows:`
cw_hlgroup = nil,
-- Whether to display highlights in INSERT mode or not
insert_mode = false,
min_match_len = 2,
max_match_len = math.huge,
})
<

Expand Down Expand Up @@ -121,6 +124,11 @@ INSERT_MODE *local-highlight-setup-insert_mode*
If set to `true`, will also work during insert mode.


MIN_MATCH_LEN AND MAX_MATCH_LEN *local-highlight-min-max-match-len*

Set lower and upper limits on the length of the word being matched.


API *local-highlight-setup-api*

If you want to directly attach the plugin to your buffers, you can use
Expand Down
5 changes: 4 additions & 1 deletion lua/local-highlight.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ local M = {
hlgroup = 'LocalHighlight',
cw_hlgroup = nil,
insert_mode = false,
min_match_len = 1,
max_match_len = math.huge,
},
timing_info = {},
usage_count = 0,
Expand Down Expand Up @@ -72,7 +74,7 @@ function M.highlight_usages(bufnr)
return
end
local curword, curword_start, curword_end = unpack(vim.fn.matchstrpos(line, [[\k*\%]] .. cursor[2] + 1 .. [[c\k*]]))
if not curword or #curword == 0 then
if not curword or #curword < M.config.min_match_len or #curword > M.config.max_match_len then
M.clear_usage_highlights(bufnr)
return
end
Expand Down Expand Up @@ -264,3 +266,4 @@ function M.setup(config)
end

return M

0 comments on commit 873c7f6

Please sign in to comment.