fix: improve attribute block collapse for .udt and .db files
- Add case-insensitive pattern matching for attributes - Add patterns for NonRetain and Retain attributes - Add generic patterns for key := value and single word attributes - Fix BufUnload autocmd to also handle *.udt and *.db files
This commit is contained in:
+14
-3
@@ -109,11 +109,22 @@ function M.expand_all_attr_blocks()
|
||||
vim.notify("Expanded " .. count .. " attribute block(s)", vim.log.levels.INFO)
|
||||
end
|
||||
|
||||
-- Helper to make a pattern case-insensitive
|
||||
local function case_insensitive_pattern(pattern)
|
||||
return pattern:gsub("(%a)", function(c)
|
||||
return "[" .. c:upper() .. c:lower() .. "]"
|
||||
end)
|
||||
end
|
||||
|
||||
-- Collapse all attribute blocks matching patterns in current buffer
|
||||
function M.collapse_all_attr_blocks(patterns)
|
||||
patterns = patterns or {
|
||||
"^%s*EXTERNAL", -- Match EXTERNALACCESSIBLE, EXTERNALVISIBLE, etc. (with optional leading space)
|
||||
"^%s*S7_", -- Match S7_Optimized_Access, etc. (with optional leading space)
|
||||
case_insensitive_pattern("^%s*EXTERNAL"), -- EXTERNALACCESSIBLE, EXTERNALVISIBLE
|
||||
case_insensitive_pattern("^%s*S7_"), -- S7_Optimized_Access
|
||||
case_insensitive_pattern("^%s*NonRetain"), -- NonRetain
|
||||
case_insensitive_pattern("^%s*Retain"), -- Retain (but not NonRetain)
|
||||
"^%s*%w+%s*:=", -- key := value
|
||||
"^%s*%w+%s*$", -- single word attribute
|
||||
}
|
||||
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
@@ -184,7 +195,7 @@ function M.setup()
|
||||
|
||||
vim.api.nvim_create_autocmd("BufUnload", {
|
||||
group = augroup,
|
||||
pattern = "*.scl",
|
||||
pattern = { "*.scl", "*.udt", "*.db" },
|
||||
callback = function(args)
|
||||
M.clear_buffer_state(args.buf)
|
||||
end,
|
||||
|
||||
Reference in New Issue
Block a user