From 5e6e1fb63079df33152298eb3b851da244a7dde3 Mon Sep 17 00:00:00 2001 From: Steve Beaulac Date: Mon, 10 Mar 2025 11:03:25 -0400 Subject: [PATCH 1/3] feat(babel): add directory creation support with :mkdirp header argument When tangling code blocks to files, automatically create parent directories when the :mkdirp header argument is set to 'yes'. --- lua/orgmode/babel/tangle.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lua/orgmode/babel/tangle.lua b/lua/orgmode/babel/tangle.lua index aeaa70523..27a25dd44 100644 --- a/lua/orgmode/babel/tangle.lua +++ b/lua/orgmode/babel/tangle.lua @@ -54,6 +54,13 @@ function Tangle:tangle() end end end + + if info.header_args[':mkdirp'] == 'yes' then + local path = vim.fn.fnamemodify(info.filename, ':h') + utils.echo_info(('Should create the directory %s'):format(path)) + vim.fn.mkdir(path, "p") + end + if info.name then block_content_by_name[info.name] = parsed_content end From 24ff632bd819b2e5855ba4f9acaaabf93046dc33 Mon Sep 17 00:00:00 2001 From: Steve Beaulac Date: Mon, 10 Mar 2025 11:59:43 -0400 Subject: [PATCH 2/3] fix(babel): remove debug message --- lua/orgmode/babel/tangle.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/lua/orgmode/babel/tangle.lua b/lua/orgmode/babel/tangle.lua index 27a25dd44..c3fbd6215 100644 --- a/lua/orgmode/babel/tangle.lua +++ b/lua/orgmode/babel/tangle.lua @@ -57,7 +57,6 @@ function Tangle:tangle() if info.header_args[':mkdirp'] == 'yes' then local path = vim.fn.fnamemodify(info.filename, ':h') - utils.echo_info(('Should create the directory %s'):format(path)) vim.fn.mkdir(path, "p") end From 34b281dda6683a10391e2cbc1858fc3d2c2e63c4 Mon Sep 17 00:00:00 2001 From: Steve Beaulac Date: Tue, 11 Mar 2025 00:11:01 -0400 Subject: [PATCH 3/3] fix(babel): replace double quotes with single quotes. Coding style requires single quotes --- lua/orgmode/babel/tangle.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/orgmode/babel/tangle.lua b/lua/orgmode/babel/tangle.lua index c3fbd6215..0d317b65a 100644 --- a/lua/orgmode/babel/tangle.lua +++ b/lua/orgmode/babel/tangle.lua @@ -57,7 +57,7 @@ function Tangle:tangle() if info.header_args[':mkdirp'] == 'yes' then local path = vim.fn.fnamemodify(info.filename, ':h') - vim.fn.mkdir(path, "p") + vim.fn.mkdir(path, 'p') end if info.name then