Skip to content

Commit

Permalink
Merge pull request #14 from Cassin01/update
Browse files Browse the repository at this point in the history
  • Loading branch information
Cassin01 authored Feb 11, 2023
2 parents 2c39b6d + 18ccda0 commit 929c459
Show file tree
Hide file tree
Showing 30 changed files with 1,811 additions and 1,790 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[![Stargazers][stars-shield]][stars-url]
[![Issues][issues-shield]][issues-url]
[![MIT License][license-shield]][license-url]
[![Build Status][ci-shield]][ci-url]

<br />
<div align="center">
Expand Down Expand Up @@ -35,7 +36,7 @@
<li>
<a href="#about-the-project">About The Project</a>
</li>
<li><a href="#📋installation">Installation</a></li>
<li><a href="#installation">Installation</a></li>
<li><a href="#getting-started">Getting started</a></li>
<li><a href="#configuration">Configuration</a></li>
<li><a href="#Wiki">Wiki</a></li>
Expand Down Expand Up @@ -269,4 +270,6 @@ Distributed under the MIT License. See `LICENSE.txt` for more information.
[issues-url]: /~https://github.com/Cassin01/wf.nvim/issues
[license-shield]: https://img.shields.io/github/license/Cassin01/wf.nvim.svg?style=for-the-badge
[license-url]: /~https://github.com/Cassin01/wf.nvim/blob/main/LICENSE.txt
[ci-shield]: https://img.shields.io/github/actions/workflow/status/Cassin01/wf.nvim/main.yml?style=for-the-badge
[ci-url]: /~https://github.com/Cassin01/wf.nvim/.github/workflows/main.yml
[product-screenshot]: https://user-images.githubusercontent.com/42632201/213849418-3cddb8bb-7323-4af7-b201-1ce2de07d3b9.png
5 changes: 5 additions & 0 deletions doc/tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Wf.disable() wf.txt /*Wf.disable()*
Wf.enable() wf.txt /*Wf.enable()*
Wf.options wf.txt /*Wf.options*
Wf.setup() wf.txt /*Wf.setup()*
Wf.toggle() wf.txt /*Wf.toggle()*
45 changes: 45 additions & 0 deletions doc/wf.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
==============================================================================
------------------------------------------------------------------------------
*Wf.options*
`Wf.options`
Your plugin configuration with its default values.

Default values:
>
Wf.options = {
-- Prints useful logs about what event are triggered, and reasons actions are executed.
debug = false,
}
<

------------------------------------------------------------------------------
*Wf.setup()*
`Wf.setup`({options})
Define your wf setup.

Parameters~
{options} `(table)` Module config table. See |Wf.options|.

Usage~
`require("wf").setup()` (add `{}` with your |Wf.options| table)


==============================================================================
------------------------------------------------------------------------------
*Wf.toggle()*
`Wf.toggle`()
Toggle the plugin by calling the `enable`/`disable` methods respectively.

------------------------------------------------------------------------------
*Wf.enable()*
`Wf.enable`()
A method to enable your plugin.

------------------------------------------------------------------------------
*Wf.disable()*
`Wf.disable`()
A method to disable your plugin.


vim:tw=78:ts=8:noet:ft=help:norl:
128 changes: 64 additions & 64 deletions lua/wf/builtin/bookmark.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,79 +2,79 @@ 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 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

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
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
print("The file/dir does not found")
return { { "", "Directory" }, { desc, "WFWhichDesc" } }
end
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

return _bookmark
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
end

return bookmark
124 changes: 62 additions & 62 deletions lua/wf/builtin/buffer.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)

local function get_active_buffers()
local blist = vim.fn.getbufinfo({ bufloadled = 1, buflisted = 0 })
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
local blist = vim.fn.getbufinfo({ bufloadled = 1, buflisted = 0 })
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
return res, bs
end
return res, bs
end

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
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 table.maxn(choices) == 0 then
vim.api.nvim_echo({
{ "No buffers to switch to.", "ErrorMsg" },
{ " @wf.builtin.buffer", "Comment" },
}, false, {})
return
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
select(choices, _opts, function(_, lhs)
if vim.fn.bufexists(lhs) ~= 0 then
vim.api.nvim_set_current_buf(tonumber(lhs))
end
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 929c459

Please sign in to comment.