Skip to content

Allow users to configure the loading of runtimepath cheatsheets. #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ This is the default configuration:

```lua
require("cheatsheet").setup({
-- Whether to show rtp cheatsheets
rtp_cheatsheets = true,

-- Whether to show bundled cheatsheets

-- For generic cheatsheets like default, unicode, nerd-fonts, etc
Expand Down
3 changes: 3 additions & 0 deletions lua/cheatsheet/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ local M = {}
-- NOTE: Watch out for bugs in cheatsheet.get_cheatsheet_files if
-- defaults is modified in the future
local defaults = {
-- Whether to show rtp cheatsheets
rtp_cheatsheets = true,

-- Whether to show bundled cheatsheets

-- For generic cheatsheets like default, unicode, nerd-fonts, etc
Expand Down
18 changes: 13 additions & 5 deletions lua/cheatsheet/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ local M = {}

M.setup = function(opts) config.setup(opts) end

-- Get `cheatsheet.txt` files from any directory in runtimepath
-- Inlcudes bundled cheatsheets if configured to do so.
-- Includes the user's `cheatsheet.txt` file.
-- Includes `cheatsheet.txt` files from any directory in runtimepath if configured to do so.
-- Includes bundled cheatsheets if configured to do so.
-- @param *opts* config.options like table
-- @return array of filepaths
M.get_cheatsheet_files = function(opts)
Expand Down Expand Up @@ -37,9 +38,16 @@ M.get_cheatsheet_files = function(opts)
cheatsheet_plugin_name_pat, plugin_include
)

local cheats = vim.api.nvim_get_runtime_file("cheatsheet.txt", true)
local bundled = utils.get_bundled_cheatsheets()
filter_insert(cheats, bundled, cheatsheet_name_pat, opts.bundled_cheatsheets)
-- Includes user's cheatsheet.
local cheats = { utils.get_user_cheatsheet() }

-- Includes rtp cheatsheets (if configured to do so).
local rtp_cheatsheets = vim.api.nvim_get_runtime_file("cheatsheet.txt", true)
filter_insert(cheats, rtp_cheatsheets, cheatsheet_name_pat, opts.rtp_cheatsheets)

-- Includes bundled cheatsheets (if configured to do so).
local bundled_cheatsheets = utils.get_bundled_cheatsheets()
filter_insert(cheats, bundled_cheatsheets, cheatsheet_name_pat, opts.bundled_cheatsheets)

filter_insert(
cheats, bundled_plugins, cheatsheet_plugin_name_pat,
Expand Down