Skip to content

Commit 5bbefc6

Browse files
committed
feat(excmd): various test fixes and introducing excmd module
1 parent 2a53d9e commit 5bbefc6

43 files changed

Lines changed: 720 additions & 165 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

PICKERS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -887,13 +887,13 @@ helptags_picker.open_helptags_picker({
887887
### Manpages
888888

889889
Lists man pages. Entries are collected from `apropos -k .` (fallback: `man -k .`) and normalized to `name(section)`. The user is allowed
890-
to provide a list of additional customized command arguments to pass down to the executable (man or apropos)
890+
to provide a list of additional customized arguments to pass down to the executable (man or apropos).
891891

892892
```lua
893893
local manpages_picker = require("fuzzy.pickers.manpages")
894894

895895
manpages_picker.open_manpages_picker({
896-
command_args = { "-k", "." }
896+
args = { "-k", "." }
897897
})
898898
```
899899

README.md

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
- [Primary stage](#primary-stage)
1111
- [Matching stage](#matching-stage)
1212
- [Features](#features)
13+
- [PICKERS](#pickers)
1314
- [Description](#description)
1415
- [Installation](#installation)
1516
- [Using packer.nvim](#using-packernvimhttpsgithubcomwbthomasonpackernvim)
1617
- [Using lazy.nvim](#using-lazynvimhttpsgithubcomfolkelazynvim)
1718
- [Using vim-plug](#using-vim-plughttpsgithubcomjunegunnvim-plug)
1819
- [Configuration](#configuration)
20+
- [User commands](#user-commands)
1921
- [Quickstart](#quickstart)
2022
- [Static table](#static-table)
2123
- [Callback function](#callback-function)
@@ -30,20 +32,21 @@
3032
- [Dynamic streams](#dynamic-streams)
3133
- [Contextual awareness](#contextual-awareness)
3234
- [Interaction](#interaction)
33-
- [Interactive and Fuzzy stages](#interactive-and-fuzzy-stages)
34-
- [Closing and hiding pickers](#closing-and-hiding-pickers)
35+
- [Interactive & Matching stages](#interactive--matching-stages)
36+
- [Closing & hiding pickers](#closing--hiding-pickers)
3537
- [Dynamic context evaluation](#dynamic-context-evaluation)
36-
- [Picker actions & interaction](#picker-actions--interaction)
38+
- [Actions & interaction](#actions--interaction)
3739
- [Picker Options](#picker-options)
3840
- [Core options](#core-options)
3941
- [Advanced options](#advanced-options)
4042
- [Option details](#option-details)
4143
- [Core options](#core-options-1)
4244
- [Advanced options](#advanced-options-1)
43-
- [In-depth look](#in-depth-look)
45+
- [In-depth description](#in-depth-description)
4446
- [Actions](#actions)
4547
- [Previewers](#previewers)
4648
- [Decorators](#decorators)
49+
- [Highlighters](#highlighters)
4750
- [Converters](#converters)
4851
- [Examples](#examples)
4952
- [Interactive grep](#interactive-grep)
@@ -177,6 +180,10 @@ require("fuzzy").setup({
177180
general = {
178181
-- override the built-in `vim.ui.select` with fuzzymatch
179182
override_select = true,
183+
user_command = {
184+
enabled = true,
185+
name = "Fzm",
186+
},
180187
}
181188

182189
-- Scheduler controls the async budget for cooperative tasks
@@ -203,6 +210,8 @@ require("fuzzy").setup({
203210
Configuration details:
204211

205212
- `general.override_select`: Replaces `vim.ui.select` with the built-in picker-based implementation.
213+
- `general.user_command.enabled`: Registers the user command that opens pickers by name.
214+
- `general.user_command.name`: Command name used for pickers (default: `Fzm`).
206215
- `scheduler.async_budget`: Time budget in microseconds for cooperative async tasks.
207216
- `pool.max_idle`: Maximum idle time in milliseconds before a pooled table is discarded.
208217
- `pool.prune_interval`: Interval in milliseconds for pool cleanup.
@@ -226,6 +235,30 @@ when the picker is re-opened the context will be re-evaluated and if it has chan
226235
`TDDR;` To start using the picker simply require the picker and select modules those are going to be enough for you to create pretty much any
227236
type of picker you can imagine. Lets see a few examples
228237

238+
### User command
239+
240+
The `:Fzm` command opens any picker by name, with optional `key=value` arguments. You can change the
241+
command name with `general.user_command.name`.
242+
243+
```vim
244+
:Fzm files
245+
:Fzm grep cwd=/path/to/project
246+
:Fzm grep args=--hidden,--iglob=*.lua prompt_query="init.lua"
247+
:Fzm manpages args=-k,. preview=false
248+
```
249+
250+
- `cwd`: working directory (string)
251+
- `args`: comma-separated list (quoted strings supported)
252+
- `env`: comma-separated list (quoted strings supported)
253+
- `preview`: `true|false`
254+
- `icons`: `true|false`
255+
- `watch`: `true|false`
256+
- `prompt_query`: initial prompt string (quote if it contains spaces)
257+
- `prompt_debounce`, `match_limit`, `match_timer`, `match_step`, `stream_step`, `stream_debounce`: numbers
258+
- `stream_type`: `lines|bytes`
259+
- `window_size`: number (0-1)
260+
- `interactive`: `true|false`
261+
229262
### Static table
230263

231264
Use a static table when you already have all entries in memory. This produces a non-interactive picker: the list is shown as-is and no

lua/fuzzy/init.lua

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
Picker = require("fuzzy.picker")
2-
Pool = require("fuzzy.pool")
3-
Registry = require("fuzzy.registry")
4-
Scheduler = require("fuzzy.scheduler")
5-
Select = require("fuzzy.select")
1+
local Pool = require("fuzzy.pool")
2+
local Registry = require("fuzzy.registry")
3+
local Scheduler = require("fuzzy.scheduler")
64

75
local M = {
86
config = {},
@@ -11,7 +9,11 @@ local M = {
119
function M.setup(opts)
1210
M.config = vim.tbl_deep_extend("keep", opts or {}, {
1311
general = {
14-
override_select = true
12+
override_select = true,
13+
user_command = {
14+
enabled = true,
15+
name = "Fzm",
16+
},
1517
},
1618
scheduler = {
1719
async_budget = 1 * 1e6,
@@ -42,6 +44,12 @@ function M.setup(opts)
4244
vim.ui.select = select_picker.open_select_picker
4345
end
4446

47+
local user_command = M.config.general.user_command or {}
48+
if user_command.enabled then
49+
local excmd = require("fuzzy.pickers.excmd")
50+
excmd.register_user_commands(user_command.name)
51+
end
52+
4553
vim.api.nvim_set_hl(0, "SelectToggleSign", { link = "Special", default = false })
4654
vim.api.nvim_set_hl(0, "SelectPrefixText", { link = "Normal", default = false })
4755
vim.api.nvim_set_hl(0, "SelectStatusText", { link = "NonText", default = false })
@@ -50,13 +58,14 @@ function M.setup(opts)
5058
vim.api.nvim_set_hl(0, "SelectHeaderDefault", { link = "Normal", default = false })
5159
vim.api.nvim_set_hl(0, "SelectHeaderPadding", { link = "NonText", default = false })
5260
vim.api.nvim_set_hl(0, "SelectHeaderDelimiter", { link = "Ignore", default = false })
53-
vim.api.nvim_set_hl(0, "SelectDecoratorDefault", { link = "Normal", default = false })
54-
vim.api.nvim_set_hl(0, "SelectLineHighlight", { link = "Visual", default = false })
5561

5662
vim.api.nvim_set_hl(0, "PickerHeaderActionKey", { link = "ErrorMsg", default = false })
5763
vim.api.nvim_set_hl(0, "PickerHeaderActionLabel", { link = "MoreMsg", default = false })
5864
vim.api.nvim_set_hl(0, "PickerHeaderActionSeparator", { link = "ModeMsg", default = false })
5965

66+
vim.api.nvim_set_hl(0, "SelectLineHighlight", { link = "Normal", default = false })
67+
vim.api.nvim_set_hl(0, "SelectDecoratorDefault", { link = "Normal", default = false })
68+
6069
Pool.prime(pool_config.prime_sizes or {})
6170
end
6271

lua/fuzzy/picker.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,8 +907,8 @@ function Picker.new(opts)
907907
context = {
908908
args = {},
909909
env = nil,
910+
cwd = nil,
910911
tick = nil,
911-
cwd = vim.loop.cwd,
912912
},
913913
interactive = false,
914914
stream_map = nil,

lua/fuzzy/pickers/btags.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function M.open_btags_picker(opts)
4646
},
4747
highlighters = {
4848
Select.RegexHighlighter.new({
49-
{ "^%S+", "Identifier" },
49+
{ "^%S+", "Function" },
5050
{ "%s%[([^%]]+)%]$", "Type", 1 },
5151
}),
5252
},

lua/fuzzy/pickers/buffers.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ function M.open_buffers_picker(opts)
241241
highlighters = {
242242
Select.RegexHighlighter.new({
243243
{ "^%d+", "Number" },
244-
{ "%s.+$", "Directory" },
244+
{ "^%d+%s+(.*/)", "Directory", 1 },
245+
{ "([^/]+)$", "Function", 1 },
245246
}),
246247
},
247248
display = function(entry)

lua/fuzzy/pickers/changes.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ function M.open_changes_picker(opts)
7171
preview = opts.preview,
7272
actions = util.build_default_actions(conv, opts),
7373
decorators = decorators,
74+
highlighters = {
75+
Select.RegexHighlighter.new({
76+
{ "%d+:%d+", "Number" },
77+
}),
78+
},
7479
display = function(entry)
7580
return util.format_location_entry(
7681
nil, entry.lnum or 1, entry.col or 1

lua/fuzzy/pickers/colorscheme.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ function M.open_colorscheme_picker(opts)
7474
},
7575
preview = opts.preview,
7676
actions = actions,
77+
highlighters = {
78+
Select.RegexHighlighter.new({
79+
{ "^.+$", "Constant" },
80+
}),
81+
},
7782
}, opts, {
7883
match_timer = 5,
7984
match_step = 1000,

lua/fuzzy/pickers/command_history.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ function M.open_command_history(opts)
3636
return false
3737
end)),
3838
},
39+
highlighters = {
40+
Select.RegexHighlighter.new({
41+
{ "^%S+", "Statement" },
42+
{ "%s(.+)$", "Comment", 1 },
43+
}),
44+
},
3945
}, opts, {
4046
match_timer = 5,
4147
match_step = 1000,

lua/fuzzy/pickers/commands.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ function M.open_commands_picker(opts)
7272
return false
7373
end)),
7474
},
75+
highlighters = {
76+
Select.RegexHighlighter.new({
77+
{ "^%S+", "Statement" },
78+
}),
79+
},
7580
}, opts, {
7681
match_timer = 5,
7782
match_step = 2000,

0 commit comments

Comments
 (0)