Extended glob and fancy path patterns #13
Labels
No labels
autorelease: pending
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
upstream/digest
upstream/pr
wontfix
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
barrettruth/canola.nvim#13
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Filter the entries visible in an oil buffer by a glob pattern — e.g. show only
*.luafiles, or only files matchingtest_*. The filter is per-buffer, toggled by the user, and does not affect mutations on entries that remain visible.What "extended glob" means here
This is not glob expansion in rename targets (that is covered by the brace-expansion logic already present in
create_actions_from_diffs). The feature here is view filtering: narrowing which entries are rendered in the buffer based on a pattern the user supplies at runtime.Example use cases:
*.rssource files.Relationship to
view_optionsThe existing visibility pipeline in
view.lua:should_displaycallsconfig.view_options.is_always_hiddenandconfig.view_options.is_hidden_file, then gates onshow_hidden. A per-buffer glob filter is a third, independent gate: an entry passes only if the active filter matches its name (or if no filter is active).The filter must be per-buffer rather than global, because the user may have multiple oil buffers open simultaneously and filtering one should not affect the others.
Implementation approach
Filter state
A module-level table in
view.lua(keyed bybufnr) holds the active pattern for each buffer. When the table has no entry for a buffer, no filtering is applied.should_displayintegrationAfter the existing
is_always_hidden/is_hidden_filechecks, apply the per-buffer filter. If a filter is active for the buffer and the entry name does not match it, returnfalse(not displayed, not hidden in the oil-hidden sense — the entry simply does not appear).UI: setting and clearing the filter
Two mechanisms:
filter): prompts the user for a pattern viavim.ui.input. Accepts a glob pattern (converted to a Lua pattern via a small helper, or matched withvim.fn.globsemantics). Calling the action with an empty string clears the filter.:Oil --filter=*.luacould pass a filter at open time, narrowing the view before the first render.After setting or clearing the filter, call
view.rerender_all_oil_buffers({ refetch = false })(same astoggle_hidden) so the buffer updates immediately without a round-trip to the filesystem.A statusline component or winbar integration point should expose whether a filter is active, so the user has a visible indicator. The exact mechanism is left to the user (an API function that returns the current filter for a buffer would suffice).
Mutations and filtered-out entries
Entries hidden by the glob filter are not removed from the cache. The
parsefunction inparser.luaonly sees lines present in the buffer; filtered-out entries are absent from the buffer and therefore appear as deletes in the diff. This is the same behaviour asshow_hidden = false: hidden entries are not protected from deletion if the user toggles visibility off, edits, and saves.Two approaches to address the deletion risk:
Option A — treat filtered-out entries as protected. Before computing diffs,
parser.parsechecks whether eachoriginal_entriesentry is hidden by an active filter. If it is, remove it fromoriginal_entriesso it is never emitted as a delete diff. This is analogous to howshould_displaygates which entries are included inoriginal_entriestoday.Option B — document the behaviour. Filtered-out entries behave like hidden files with
show_hidden = false. The user is responsible for clearing the filter before saving if they do not want to delete filtered entries. This is the simpler implementation.Option A is recommended for the same reason that
is_always_hiddenentries are excluded fromoriginal_entries: a user who filtered to*.luashould not accidentally delete every non-Lua file in the directory on:w.Pattern semantics
Accept standard glob patterns (
*,?,[abc]). Usevim.fn.fnamemodifymatching or convert globs to Lua patterns with a simple substitution (*→.*,?→., escape magic chars). Do not support**(recursive glob) — the filter applies only to names in the current directory, not to subtrees.Scope
view.luashould_displayextended with a filter gateoriginal_entriesinparser.parseexcludes filtered-out entries (Option A)filteraction that prompts for a pattern and rerenders