Skip to content

Commit 1a5955c

Browse files
committed
make recursive scans optional
1 parent f83f268 commit 1a5955c

File tree

4 files changed

+40
-9
lines changed

4 files changed

+40
-9
lines changed

doc/nvim-reminders.txt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,28 @@ Use 't' to toggle the sort order from oldest to newest and vice versa.
3939
==============================================================================
4040
CONFIGURATION *nvim-reminders-config*
4141

42-
The nvim-reminders plugin can be configured by passing a configuration table
42+
The nvim-reminders plugin can be enabled by the `setup` function called your
43+
init.lua file:
44+
>
45+
require('reminders').setup()
46+
47+
The nvim-reminders plugin can be customized by passing a configuration table
4348
to the `setup` function in your init.lua file:
4449

50+
`paths`: A list of paths to scan for and edit reminders
51+
>
52+
require('reminders').setup({
53+
paths = { "~/path/to/your/markdown/files" }
54+
})
55+
56+
`recursive_scan`: A boolean flag to indicate scan all sub directories when
57+
processing the `ReminderScan` and `ReminderScanUpcoming` commands. Note,
58+
`ReminderScanAll` always scans recursively.
4559
>
4660
require('reminders').setup({
47-
paths = { "~/path/to/your/reminders" }
61+
recursive_scan = true
4862
})
4963
50-
`paths`: A list of paths to scan for reminders
5164
5265
==============================================================================
5366
vim:tw=78:ts=8:ft=help:norl:

lua/reminders/autocmds.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function M.update_virtual_text()
6565
end
6666

6767
-- Set up autocmds for markdown files in the configured paths
68-
function M.setup_autocmds(paths)
68+
function M.setup_autocmds()
6969
vim.cmd([[
7070
augroup Reminders
7171
autocmd!

lua/reminders/init.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,17 @@ end, {})
313313
-- Plugin setup function
314314
function M.setup(user_config)
315315
M.config = {
316-
paths = { fn.expand("~/git/" .. io.popen("whoami"):read("*a"):gsub("\n", "") .. "/zet") }
316+
paths = { fn.expand("~/git/" .. io.popen("whoami"):read("*a"):gsub("\n", "") .. "/zet") },
317+
recursive_scan = false
317318
}
318319
if user_config and user_config.paths then
319320
M.config.paths = user_config.paths
320321
end
322+
if user_config and user_config.recursive_scan then
323+
M.config.recursive_scan = user_config.recursive_scan
324+
end
321325
-- Set up autocmds for markdown files in the configured paths
322-
require('reminders.autocmds').setup_autocmds(M.config.paths)
326+
require('reminders.autocmds').setup_autocmds()
323327
end
324328

325329
function M.is_reminder(line)

lua/reminders/reminder_list.lua

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ local function scan_file(file_path, upcoming, all_reminders)
6262
local lines = vim.fn.readfile(file_path)
6363
for i, line in ipairs(lines) do
6464
local reminder, datetime, is_checked = parse_reminder_line(line)
65-
6665
if datetime and (all_reminders or not is_checked) then
6766
add_reminder(file_path, i, reminder, datetime, upcoming, all_reminders)
6867
end
@@ -71,9 +70,17 @@ end
7170

7271
-- Function to scan all configured paths for due reminders
7372
function M.scan_paths(paths)
73+
74+
local recursive_scan = require('reminders').config.recursive_scan
75+
7476
M.reminders = {} -- Clear the list before scanning
7577
for _, path in ipairs(paths) do
76-
local files = vim.fn.globpath(path, "**/*.md", false, true)
78+
local files
79+
if recursive_scan == true then
80+
files = vim.fn.globpath(path, "**/*.md", false, true)
81+
else
82+
files = vim.fn.globpath(path, "*.md", false, true)
83+
end
7784
for _, file in ipairs(files) do
7885
scan_file(file, false, false) -- Pass false for upcoming and all_reminders
7986
end
@@ -82,9 +89,15 @@ end
8289

8390
-- Function to scan all configured paths for upcoming reminders
8491
function M.scan_paths_upcoming(paths)
92+
local recursive_scan = require('reminders').config.recursive_scan
8593
M.reminders = {} -- Clear the list before scanning
8694
for _, path in ipairs(paths) do
87-
local files = vim.fn.globpath(path, "**/*.md", false, true)
95+
local files
96+
if recursive_scan == true then
97+
files = vim.fn.globpath(path, "**/*.md", false, true)
98+
else
99+
files = vim.fn.globpath(path, "*.md", false, true)
100+
end
88101
for _, file in ipairs(files) do
89102
scan_file(file, true, false) -- Pass true for upcoming and false for all_reminders
90103
end
@@ -95,6 +108,7 @@ end
95108
function M.scan_paths_all(paths)
96109
M.reminders = {} -- Clear the list before scanning
97110
for _, path in ipairs(paths) do
111+
-- always scan recursively for all reminders
98112
local files = vim.fn.globpath(path, "**/*.md", false, true)
99113
for _, file in ipairs(files) do
100114
scan_file(file, false, true) -- Pass false for upcoming and true for all_reminders

0 commit comments

Comments
 (0)