feat: API to change config.view.is_hidden_file at runtime (#69)
This commit is contained in:
parent
33d5701a8d
commit
12bea0f646
5 changed files with 53 additions and 6 deletions
15
README.md
15
README.md
|
|
@ -234,6 +234,21 @@ Change the display columns for oil
|
||||||
| ----- | ------------------ | ---- |
|
| ----- | ------------------ | ---- |
|
||||||
| cols | `oil.ColumnSpec[]` | |
|
| cols | `oil.ColumnSpec[]` | |
|
||||||
|
|
||||||
|
### set_is_hidden_file(is_hidden_file)
|
||||||
|
|
||||||
|
`set_is_hidden_file(is_hidden_file)` \
|
||||||
|
Change how oil determines if the file is hidden
|
||||||
|
|
||||||
|
| Param | Type | Desc |
|
||||||
|
| -------------- | ----------------------------------------------------- | -------------------------------------------- |
|
||||||
|
| is_hidden_file | `fun(filename: string, bufnr: nil\|integer): boolean` | Return true if the file/dir should be hidden |
|
||||||
|
|
||||||
|
### toggle_hidden()
|
||||||
|
|
||||||
|
`toggle_hidden()` \
|
||||||
|
Toggle hidden files and directories
|
||||||
|
|
||||||
|
|
||||||
### get_current_dir()
|
### get_current_dir()
|
||||||
|
|
||||||
`get_current_dir(): nil|string` \
|
`get_current_dir(): nil|string` \
|
||||||
|
|
|
||||||
11
doc/oil.txt
11
doc/oil.txt
|
|
@ -110,6 +110,17 @@ set_columns({cols}) *oil.set_column
|
||||||
Parameters:
|
Parameters:
|
||||||
{cols} `oil.ColumnSpec[]`
|
{cols} `oil.ColumnSpec[]`
|
||||||
|
|
||||||
|
set_is_hidden_file({is_hidden_file}) *oil.set_is_hidden_file*
|
||||||
|
Change how oil determines if the file is hidden
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
{is_hidden_file} `fun(filename: string, bufnr: nil|integer): boolean` Retu
|
||||||
|
rn true if the file/dir should be hidden
|
||||||
|
|
||||||
|
toggle_hidden() *oil.toggle_hidden*
|
||||||
|
Toggle hidden files and directories
|
||||||
|
|
||||||
|
|
||||||
get_current_dir(): nil|string *oil.get_current_dir*
|
get_current_dir(): nil|string *oil.get_current_dir*
|
||||||
Get the current directory
|
Get the current directory
|
||||||
|
|
||||||
|
|
|
||||||
2
doc/tags
2
doc/tags
|
|
@ -53,5 +53,7 @@ oil.open_float oil.txt /*oil.open_float*
|
||||||
oil.save oil.txt /*oil.save*
|
oil.save oil.txt /*oil.save*
|
||||||
oil.select oil.txt /*oil.select*
|
oil.select oil.txt /*oil.select*
|
||||||
oil.set_columns oil.txt /*oil.set_columns*
|
oil.set_columns oil.txt /*oil.set_columns*
|
||||||
|
oil.set_is_hidden_file oil.txt /*oil.set_is_hidden_file*
|
||||||
oil.setup oil.txt /*oil.setup*
|
oil.setup oil.txt /*oil.setup*
|
||||||
|
oil.toggle_hidden oil.txt /*oil.toggle_hidden*
|
||||||
oil.txt oil.txt /*oil.txt*
|
oil.txt oil.txt /*oil.txt*
|
||||||
|
|
|
||||||
|
|
@ -135,6 +135,17 @@ M.set_columns = function(cols)
|
||||||
require("oil.view").set_columns(cols)
|
require("oil.view").set_columns(cols)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Change how oil determines if the file is hidden
|
||||||
|
---@param is_hidden_file fun(filename: string, bufnr: nil|integer): boolean Return true if the file/dir should be hidden
|
||||||
|
M.set_is_hidden_file = function(is_hidden_file)
|
||||||
|
require("oil.view").set_is_hidden_file(is_hidden_file)
|
||||||
|
end
|
||||||
|
|
||||||
|
---Toggle hidden files and directories
|
||||||
|
M.toggle_hidden = function()
|
||||||
|
require("oil.view").toggle_hidden()
|
||||||
|
end
|
||||||
|
|
||||||
---Get the current directory
|
---Get the current directory
|
||||||
---@return nil|string
|
---@return nil|string
|
||||||
M.get_current_dir = function()
|
M.get_current_dir = function()
|
||||||
|
|
|
||||||
|
|
@ -53,8 +53,7 @@ M.get_last_cursor = function(bufname)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function are_any_modified()
|
local function are_any_modified()
|
||||||
local view = require("oil.view")
|
local buffers = M.get_all_buffers()
|
||||||
local buffers = view.get_all_buffers()
|
|
||||||
for _, bufnr in ipairs(buffers) do
|
for _, bufnr in ipairs(buffers) do
|
||||||
if vim.bo[bufnr].modified then
|
if vim.bo[bufnr].modified then
|
||||||
return true
|
return true
|
||||||
|
|
@ -64,25 +63,34 @@ local function are_any_modified()
|
||||||
end
|
end
|
||||||
|
|
||||||
M.toggle_hidden = function()
|
M.toggle_hidden = function()
|
||||||
local view = require("oil.view")
|
|
||||||
local any_modified = are_any_modified()
|
local any_modified = are_any_modified()
|
||||||
if any_modified then
|
if any_modified then
|
||||||
vim.notify("Cannot toggle hidden files when you have unsaved changes", vim.log.levels.WARN)
|
vim.notify("Cannot toggle hidden files when you have unsaved changes", vim.log.levels.WARN)
|
||||||
else
|
else
|
||||||
config.view_options.show_hidden = not config.view_options.show_hidden
|
config.view_options.show_hidden = not config.view_options.show_hidden
|
||||||
view.rerender_all_oil_buffers({ refetch = false })
|
M.rerender_all_oil_buffers({ refetch = false })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param is_hidden_file fun(filename: string, bufnr: nil|integer): boolean
|
||||||
|
M.set_is_hidden_file = function(is_hidden_file)
|
||||||
|
local any_modified = are_any_modified()
|
||||||
|
if any_modified then
|
||||||
|
vim.notify("Cannot change is_hidden_file when you have unsaved changes", vim.log.levels.WARN)
|
||||||
|
else
|
||||||
|
config.view_options.is_hidden_file = is_hidden_file
|
||||||
|
M.rerender_all_oil_buffers({ refetch = false })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
M.set_columns = function(cols)
|
M.set_columns = function(cols)
|
||||||
local view = require("oil.view")
|
|
||||||
local any_modified = are_any_modified()
|
local any_modified = are_any_modified()
|
||||||
if any_modified then
|
if any_modified then
|
||||||
vim.notify("Cannot change columns when you have unsaved changes", vim.log.levels.WARN)
|
vim.notify("Cannot change columns when you have unsaved changes", vim.log.levels.WARN)
|
||||||
else
|
else
|
||||||
config.columns = cols
|
config.columns = cols
|
||||||
-- TODO only refetch if we don't have all the necessary data for the columns
|
-- TODO only refetch if we don't have all the necessary data for the columns
|
||||||
view.rerender_all_oil_buffers({ refetch = true })
|
M.rerender_all_oil_buffers({ refetch = true })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue