Skip to content

Commit acfa513

Browse files
mikesmithghfolke
andauthored
feat(cmdline): added cmdline support for :lua= and :=
* feat(cmdline): Add format for := lua expr * style: formatting * feat: added support for multiple patterns for cmldine --------- Co-authored-by: Folke Lemaitre <folke.lemaitre@gmail.com>
1 parent 92b058a commit acfa513

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ Check the [wiki](https://github.com/folke/noice.nvim/wiki/Configuration-Recipes)
122122
search_down = { kind = "search", pattern = "^/", icon = " ", lang = "regex" },
123123
search_up = { kind = "search", pattern = "^%?", icon = " ", lang = "regex" },
124124
filter = { pattern = "^:%s*!", icon = "$", lang = "bash" },
125-
lua = { pattern = "^:%s*lua%s+", icon = "", lang = "lua" },
125+
lua = { pattern = { "^:%s*lua%s+", "^:%s*lua%s*=%s*", "^:%s*=%s*" }, icon = "", lang = "lua" },
126126
help = { pattern = "^:%s*he?l?p?%s+", icon = "" },
127127
input = {}, -- Used by input()
128128
-- lua = false, -- to disable a format, set to `false`

lua/noice/config/init.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function M.defaults()
2424
search_down = { kind = "search", pattern = "^/", icon = " ", lang = "regex" },
2525
search_up = { kind = "search", pattern = "^%?", icon = " ", lang = "regex" },
2626
filter = { pattern = "^:%s*!", icon = "$", lang = "bash" },
27-
lua = { pattern = "^:%s*lua%s+", icon = "", lang = "lua" },
27+
lua = { pattern = { "^:%s*lua%s+", "^:%s*lua%s*=%s*", "^:%s*=%s*" }, icon = "", lang = "lua" },
2828
help = { pattern = "^:%s*he?l?p?%s+", icon = "" },
2929
calculator = { pattern = "^=", icon = "", lang = "vimnormal" },
3030
input = {}, -- Used by input()

lua/noice/ui/cmdline.lua

+24-15
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ M.active = nil
3838

3939
---@class CmdlineFormat
4040
---@field kind string
41-
---@field pattern? string
41+
---@field pattern? string|string[]
4242
---@field view string
4343
---@field conceal? boolean
4444
---@field icon? string
@@ -75,22 +75,31 @@ function Cmdline:get_format()
7575
end
7676
local line = self.state.firstc .. self:get()
7777

78-
---@type table<string, CmdlineFormat>
79-
local formats = vim.tbl_values(vim.tbl_filter(function(f)
80-
return f.pattern
81-
end, Config.options.cmdline.format))
82-
table.sort(formats, function(a, b)
83-
return #a.pattern > #b.pattern
84-
end)
85-
86-
for _, format in pairs(formats) do
87-
local from, to = line:find(format.pattern)
88-
-- if match and cmdline pos is visible
89-
if from and self.state.pos >= to - 1 then
90-
self.offset = format.conceal and to or 0
91-
return format
78+
---@type {offset:number, format: CmdlineFormat}[]
79+
local ret = {}
80+
81+
for _, format in pairs(Config.options.cmdline.format) do
82+
local patterns = type(format.pattern) == "table" and format.pattern or { format.pattern }
83+
---@cast patterns string[]
84+
for _, pattern in ipairs(patterns) do
85+
local from, to = line:find(pattern)
86+
-- if match and cmdline pos is visible
87+
if from and self.state.pos >= to - 1 then
88+
ret[#ret + 1] = {
89+
offset = format.conceal and to or 0,
90+
format = format,
91+
}
92+
end
9293
end
9394
end
95+
table.sort(ret, function(a, b)
96+
return a.offset > b.offset
97+
end)
98+
local format = ret[1]
99+
if format then
100+
self.offset = format.offset
101+
return format.format
102+
end
94103
self.offset = 0
95104
return {
96105
kind = self.state.firstc,

0 commit comments

Comments
 (0)