@@ -97,6 +97,40 @@ module.setup = function()
9797 }
9898end
9999
100+ --- @type core.integrations.treesitter
101+ local ts
102+ module .load = function ()
103+ ts = module .required [" core.integrations.treesitter" ] --[[ @as core.integrations.treesitter]]
104+
105+ if module .config .private .strategies [module .config .public .strategy ] then
106+ module .config .public .strategy = module .config .private .strategies [module .config .public .strategy ]
107+ end
108+
109+ modules .await (" core.neorgcmd" , function (neorgcmd )
110+ neorgcmd .add_commands_from_table ({
111+ journal = {
112+ min_args = 1 ,
113+ max_args = 2 ,
114+ subcommands = {
115+ tomorrow = { args = 0 , name = " journal.tomorrow" },
116+ yesterday = { args = 0 , name = " journal.yesterday" },
117+ today = { args = 0 , name = " journal.today" },
118+ custom = { max_args = 1 , name = " journal.custom" }, -- format :yyyy-mm-dd
119+ template = { args = 0 , name = " journal.template" },
120+ toc = {
121+ args = 1 ,
122+ name = " journal.toc" ,
123+ subcommands = {
124+ open = { args = 0 , name = " journal.toc.open" },
125+ update = { args = 0 , name = " journal.toc.update" },
126+ },
127+ },
128+ },
129+ },
130+ })
131+ end )
132+ end
133+
100134module .config .public = {
101135 -- Which workspace to use for the journal files, the default behaviour
102136 -- is to use the current workspace.
@@ -251,11 +285,21 @@ module.public = {
251285 return handle
252286 end
253287
254- -- Gets the title from the metadata of a file, must be called in a vim.schedule
288+ --- Gets the title from the metadata of a file, must be called in a vim.schedule
289+ --- @param file PathlibPath
290+ --- @return string ?
255291 local get_title = function (file )
256- local buffer = vim .fn .bufadd (workspace_path .. config .pathsep .. folder_name .. config .pathsep .. file )
257- local meta = module .required [" core.integrations.treesitter" ].get_document_metadata (buffer )
258- return meta .title
292+ local path = workspace_path / folder_name / file
293+ local meta
294+ if vim .fn .bufexists (tostring (path )) == 1 then
295+ local buf = vim .fn .bufloaded (vim .fn .bufnr (tostring (path )))
296+ meta = ts .get_document_metadata (buf )
297+ else
298+ meta = ts .get_document_metadata (path )
299+ end
300+ if meta then
301+ return meta .title
302+ end
259303 end
260304
261305 vim .loop .fs_scandir (workspace_path .. config .pathsep .. folder_name .. config .pathsep , function (err , handle )
@@ -416,36 +460,6 @@ module.public = {
416460 end ,
417461}
418462
419- module .load = function ()
420- if module .config .private .strategies [module .config .public .strategy ] then
421- module .config .public .strategy = module .config .private .strategies [module .config .public .strategy ]
422- end
423-
424- modules .await (" core.neorgcmd" , function (neorgcmd )
425- neorgcmd .add_commands_from_table ({
426- journal = {
427- min_args = 1 ,
428- max_args = 2 ,
429- subcommands = {
430- tomorrow = { args = 0 , name = " journal.tomorrow" },
431- yesterday = { args = 0 , name = " journal.yesterday" },
432- today = { args = 0 , name = " journal.today" },
433- custom = { max_args = 1 , name = " journal.custom" }, -- format :yyyy-mm-dd
434- template = { args = 0 , name = " journal.template" },
435- toc = {
436- args = 1 ,
437- name = " journal.toc" ,
438- subcommands = {
439- open = { args = 0 , name = " journal.toc.open" },
440- update = { args = 0 , name = " journal.toc.update" },
441- },
442- },
443- },
444- },
445- })
446- end )
447- end
448-
449463module .on_event = function (event )
450464 if event .split_type [1 ] == " core.neorgcmd" then
451465 if event .split_type [2 ] == " journal.tomorrow" then
0 commit comments