From 05e3127d523102f9bff98af4051f4bd7afa201c1 Mon Sep 17 00:00:00 2001 From: TK Kiatkungwanglai Date: Sun, 29 Jan 2023 08:41:17 +0000 Subject: [PATCH 1/2] Allow users to configure the loading of runtimepath cheatsheets. * The user's cheatsheet loads unconditionally. * Configuration defaults to previous behavior. --- README.md | 3 +++ lua/cheatsheet/config.lua | 3 +++ lua/cheatsheet/init.lua | 13 ++++++++++--- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bd80c7a..1a89c18 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lua/cheatsheet/config.lua b/lua/cheatsheet/config.lua index 188e3f0..f3401f8 100644 --- a/lua/cheatsheet/config.lua +++ b/lua/cheatsheet/config.lua @@ -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 diff --git a/lua/cheatsheet/init.lua b/lua/cheatsheet/init.lua index b4a3232..288c2e7 100644 --- a/lua/cheatsheet/init.lua +++ b/lua/cheatsheet/init.lua @@ -37,9 +37,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) + -- Load user's cheatsheet. + local cheats = { utils.get_user_cheatsheet() } + + -- Load 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) + + -- Load 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, From d366aab83664f7419af8bfae3bc43b71d8ae0792 Mon Sep 17 00:00:00 2001 From: TK Kiatkungwanglai Date: Sun, 29 Jan 2023 09:09:23 +0000 Subject: [PATCH 2/2] Update comments. --- lua/cheatsheet/init.lua | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lua/cheatsheet/init.lua b/lua/cheatsheet/init.lua index 288c2e7..19e4917 100644 --- a/lua/cheatsheet/init.lua +++ b/lua/cheatsheet/init.lua @@ -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) @@ -37,14 +38,14 @@ M.get_cheatsheet_files = function(opts) cheatsheet_plugin_name_pat, plugin_include ) - -- Load user's cheatsheet. + -- Includes user's cheatsheet. local cheats = { utils.get_user_cheatsheet() } - -- Load rtp cheatsheets (if configured to do so). + -- 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) - -- Load bundled cheatsheets (if configured to do so). + -- 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)