Skip to content

Commit

Permalink
Merge pull request #26 from Cassin01/update
Browse files Browse the repository at this point in the history
  • Loading branch information
Cassin01 authored Feb 16, 2023
2 parents 2d16a32 + 6c24637 commit 72b001f
Show file tree
Hide file tree
Showing 25 changed files with 1,697 additions and 1,796 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ vim.keymap.set(

```lua
require("wf").setup({
-- you can copy the full list from lua/wf/config.lua
-- you can copy the full list from lua/wf/setup/init.lua
})
```

Expand Down
132 changes: 66 additions & 66 deletions lua/wf/builtin/bookmark.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,81 +2,81 @@ local select = require("wf").select
local gen_highlight = require("wf.util").gen_highlight

local function require_deviocon()
return require("nvim-web-devicons")
return require("nvim-web-devicons")
end

local ok, devicon = pcall(require_deviocon)

---@param bookmark_dirs table
---@param opts? table
local function bookmark(bookmark_dirs, opts)
local function _bookmark()
opts = opts or {}
local _opts = {
title = "Bookmark",
behavior = {
skip_front_duplication = true,
skip_back_duplication = true,
},
output_obj_which_mode_desc_format = function(match_obj)
local desc = match_obj.text
if ok then
if match_obj.type == "group" then
return { { desc, "WFWhichDesc" }, { " +", "WFExpandable" } }
else
local icon, color = devicon.get_icon_color(desc)
if icon ~= nil then
local name = gen_highlight(desc, color)
local sp = vim.fn.strwidth(icon) > 1 and (icon .. "") or (icon .. " ")
return { { sp .. " ", name }, { desc, "WFWhichDesc" } }
else
return { { "", "Directory" }, { desc, "WFWhichDesc" } }
end
end
else
if match_obj.type == "group" then
return { { desc, "WFWhichDesc" }, { " +", "WFExpandable" } }
else
return { { desc, "WFWhichDesc" } }
end
end
end,
}
for k, v in pairs(opts) do
_opts[k] = v
end
local function _bookmark()
opts = opts or {}
local _opts = {
title = "Bookmark",
behavior = {
skip_front_duplication = true,
skip_back_duplication = true,
},
output_obj_which_mode_desc_format = function(match_obj)
local desc = match_obj.text
if ok then
if match_obj.type == "group" then
return { { desc, "WFWhichDesc" }, { " +", "WFExpandable" } }
else
local icon, color = devicon.get_icon_color(desc)
if icon ~= nil then
local name = gen_highlight(desc, color)
local sp = vim.fn.strwidth(icon) > 1 and (icon .. "") or (icon .. " ")
return { { sp .. " ", name }, { desc, "WFWhichDesc" } }
else
return { { "", "Directory" }, { desc, "WFWhichDesc" } }
end
end
else
if match_obj.type == "group" then
return { { desc, "WFWhichDesc" }, { " +", "WFExpandable" } }
else
return { { desc, "WFWhichDesc" } }
end
end
end,
}
for k, v in pairs(opts) do
_opts[k] = v
end

select(bookmark_dirs, _opts, function(path_, _)
local path = vim.fn.expand(path_)
if vim.fn.isdirectory(path) ~= 0 then
if vim.fn.exists(":Telescope") then
require("telescope").extensions.file_browser.file_browser({
path = path_,
depth = 4,
})
return
elseif vim.fn.exists(":CtrlP") then
local command = "CtrlP " .. path
vim.cmd(command)
return
elseif vim.g.loaded_netrwPlugin == 0 and vim.g.loaded_netrw == 0 then
local command = "e " .. path
vim.cmd(command)
return
else
print("not matched")
end
elseif vim.fn.filereadable(path) ~= 0 then
local command = "vi " .. path
vim.cmd(command)
return
else
print("The file/dir does not found")
end
end)
end
select(bookmark_dirs, _opts, function(path_, _)
local path = vim.fn.expand(path_)
if vim.fn.isdirectory(path) ~= 0 then
if vim.fn.exists(":Telescope") then
require("telescope").extensions.file_browser.file_browser({
path = path_,
depth = 4,
})
return
elseif vim.fn.exists(":CtrlP") then
local command = "CtrlP " .. path
vim.cmd(command)
return
elseif vim.g.loaded_netrwPlugin == 0 and vim.g.loaded_netrw == 0 then
local command = "e " .. path
vim.cmd(command)
return
else
print("not matched")
end
elseif vim.fn.filereadable(path) ~= 0 then
local command = "vi " .. path
vim.cmd(command)
return
else
print("The file/dir does not found")
end
end)
end

return _bookmark
return _bookmark
end

return bookmark
132 changes: 66 additions & 66 deletions lua/wf/builtin/buffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,82 +2,82 @@ local select = require("wf").select
local gen_highlight = require("wf.util").gen_highlight

local function require_deviocon()
return require("nvim-web-devicons")
return require("nvim-web-devicons")
end

local ok, devicon = pcall(require_deviocon)

local function get_active_buffers()
local blist = vim.fn.getbufinfo({ bufloadled = 1, buflisted = 1 })
local res = {}
local bs = {}
for _, b in ipairs(blist) do
if vim.fn.empty(b.name) == 0 then -- or b.hidden ~= 0 then
res[b.bufnr] = b.name
bs[b.bufnr] = b
end
end
return res, bs
local blist = vim.fn.getbufinfo({ bufloadled = 1, buflisted = 1 })
local res = {}
local bs = {}
for _, b in ipairs(blist) do
if vim.fn.empty(b.name) == 0 then -- or b.hidden ~= 0 then
res[b.bufnr] = b.name
bs[b.bufnr] = b
end
end
return res, bs
end

---@param opts? table
local function buffer(opts)
local function _buffer()
local choices, bs = get_active_buffers()
local current_buf = vim.api.nvim_get_current_buf()
local _opts = {
title = "Buffer",
behavior = {
skip_front_duplication = true,
skip_back_duplication = true,
},
style = {
width = vim.o.columns,
},
prefix_size = 3,
output_obj_which_mode_desc_format = function(match_obj)
local desc = match_obj.text
local id = match_obj.id
local bufinfo = bs[id]
if bufinfo ~= nil and bufinfo.variables["terminal_job_id"] ~= nil then
return { { "", "Identifier" }, { desc, "WFWhichDesc" } }
end
local hldesc = bufinfo.changed == 1 and "String" or "WFWhichDesc"
if id == current_buf then
return { { "", "Identifier" }, { desc, hldesc } }
end
if ok then
local icon, color = devicon.get_icon_color(desc)
if icon ~= nil then
local sp = vim.fn.strwidth(icon) > 1 and (icon .. "") or (icon .. " ")
return { { sp .. " ", gen_highlight(desc, color) }, { desc, hldesc } }
else
return { { "", "Identifier" }, { desc, hldesc } }
end
else
return { { desc, hldesc } }
end
end,
}
opts = opts or {}
for k, v in pairs(opts) do
_opts[k] = v
end
if table.maxn(choices) == 0 then
vim.api.nvim_echo({
{ "No buffers to switch to.", "ErrorMsg" },
{ " @wf.builtin.buffer", "Comment" },
}, false, {})
return
end
select(choices, _opts, function(_, lhs)
if vim.fn.bufexists(lhs) ~= 0 then
vim.api.nvim_set_current_buf(tonumber(lhs))
end
end)
end
local function _buffer()
local choices, bs = get_active_buffers()
local current_buf = vim.api.nvim_get_current_buf()
local _opts = {
title = "Buffer",
behavior = {
skip_front_duplication = true,
skip_back_duplication = true,
},
style = {
width = vim.o.columns,
},
prefix_size = 3,
output_obj_which_mode_desc_format = function(match_obj)
local desc = match_obj.text
local id = match_obj.id
local bufinfo = bs[id]
if bufinfo ~= nil and bufinfo.variables["terminal_job_id"] ~= nil then
return { { "", "Identifier" }, { desc, "WFWhichDesc" } }
end
local hldesc = bufinfo.changed == 1 and "String" or "WFWhichDesc"
if id == current_buf then
return { { "", "Identifier" }, { desc, hldesc } }
end
if ok then
local icon, color = devicon.get_icon_color(desc)
if icon ~= nil then
local sp = vim.fn.strwidth(icon) > 1 and (icon .. "") or (icon .. " ")
return { { sp .. " ", gen_highlight(desc, color) }, { desc, hldesc } }
else
return { { "", "Identifier" }, { desc, hldesc } }
end
else
return { { desc, hldesc } }
end
end,
}
opts = opts or {}
for k, v in pairs(opts) do
_opts[k] = v
end
if table.maxn(choices) == 0 then
vim.api.nvim_echo({
{ "No buffers to switch to.", "ErrorMsg" },
{ " @wf.builtin.buffer", "Comment" },
}, false, {})
return
end
select(choices, _opts, function(_, lhs)
if vim.fn.bufexists(lhs) ~= 0 then
vim.api.nvim_set_current_buf(tonumber(lhs))
end
end)
end

return _buffer
return _buffer
end

return buffer
Loading

0 comments on commit 72b001f

Please sign in to comment.