Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 940b067

Browse files
feat(globals): Rename open to agenda, add default prompt for agenda and capture
1 parent 3b120ea commit 940b067

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

docs/index.org

+4-3
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,12 @@ List of available actions:
6161
- =:Org help= - Open this documentation in new tab, set working directory to the docs folder for the tab to allow browsing
6262
- =:Org helpgrep= - Open search agenda view that allows searching through the documentation
6363
- =:Org agenda {type?}= - Open agenda view by the shortcut, for example =:Org agenda M= will open =tags_todo= view. When =type= is omitted, it opens up Agenda view.
64-
- =:Org capture {type}= - Open capture template by the shortcut, for example =:Org capture t=.
64+
- =:Org capture {type?}= - Open capture template by the shortcut, for example =:Org capture t=. When =type= is omitted, it opens up Capture prompt.
6565

6666
All of the commands above can be executed through the global Lua =Org= variable. Examples:
6767
- =Org.help()=
6868
- =Org.helpgrep()=
69-
- =Org.open()= - Opens =agenda= view
70-
- =Org.open.m()= - Opens =tags= view
69+
- =Org.agenda()= - Opens =agenda= prompt
70+
- =Org.agenda.m()= - Opens =tags= view
71+
- =Org.capture()= - Opens capture prompt
7172
- =Org.capture.t()= - Opens capture template for =t= shortcut

lua/orgmode/org/global.lua

+13-9
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ local docs_dir = vim.fn.fnamemodify(current_file_path, ':p:h:h:h:h') .. '/docs'
33

44
---@param orgmode Org
55
---@param config OrgConfig
6-
local function generate_open_object(orgmode, config)
7-
local Open = setmetatable({}, {
8-
__call = function(t, ...)
9-
t.a(...)
6+
local function generate_agenda_object(orgmode, config)
7+
local Agenda = setmetatable({}, {
8+
__call = function()
9+
return orgmode.agenda:prompt()
1010
end,
1111
})
1212

@@ -20,18 +20,22 @@ local function generate_open_object(orgmode, config)
2020
table.sort(agenda_keys)
2121

2222
for _, key in ipairs(agenda_keys) do
23-
Open[key] = function()
23+
Agenda[key] = function()
2424
return orgmode.agenda:open_by_key(key)
2525
end
2626
end
2727

28-
return Open
28+
return Agenda
2929
end
3030

3131
---@param orgmode Org
3232
---@param config OrgConfig
3333
local function generate_capture_object(orgmode, config)
34-
local Capture = {}
34+
local Capture = setmetatable({}, {
35+
__call = function()
36+
return orgmode.capture:prompt()
37+
end,
38+
})
3539

3640
for key, _ in pairs(config.org_capture_templates or {}) do
3741
Capture[key] = function()
@@ -58,7 +62,7 @@ local build = function(orgmode)
5862
})
5963
end,
6064

61-
open = generate_open_object(orgmode, config),
65+
agenda = generate_agenda_object(orgmode, config),
6266
capture = generate_capture_object(orgmode, config),
6367
}
6468

@@ -84,7 +88,7 @@ end
8488

8589
vim.api.nvim_create_user_command('Org', function(opts)
8690
local item = resolve_item(opts.fargs)
87-
if item and type(item) == 'function' then
91+
if item and (type(item) == 'function' or getmetatable(item).__call) then
8892
return item()
8993
end
9094
require('orgmode.utils').echo_error(('Invalid command "Org %s"'):format(opts.args))

0 commit comments

Comments
 (0)