From 3c3b977dff916aecf5b2d63747896691c70639df Mon Sep 17 00:00:00 2001 From: Ben Lubas <56943754+benlubas@users.noreply.github.com> Date: Mon, 15 Jul 2024 17:29:24 -0400 Subject: [PATCH] fix!: tangle files relative to norg file (#1415) --- lua/neorg/modules/core/tangle/module.lua | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lua/neorg/modules/core/tangle/module.lua b/lua/neorg/modules/core/tangle/module.lua index 5aeca9de2..998121154 100644 --- a/lua/neorg/modules/core/tangle/module.lua +++ b/lua/neorg/modules/core/tangle/module.lua @@ -13,8 +13,10 @@ The `tangle` module currently provides a single command: - `:Neorg tangle current-file` - performs all possible tangling operations on the current file ### Usage Tutorial -By default, *zero* code blocks are tangled. You must provide where you'd like to tangle each code block manually (global configuration will be discussed later). -To do so, add a `#tangle ` tag above the code block you'd wish to export. For example: +By default, *zero* code blocks are tangled. You must provide where you'd like to tangle each code +block manually (global configuration will be discussed later). To do so, add a `#tangle +` tag above the code block you'd wish to export, where is relative to the +current file. For example: ```norg #tangle init.lua @@ -163,6 +165,7 @@ local neorg = require("neorg.core") local lib, modules, utils = neorg.lib, neorg.modules, neorg.utils local module = modules.create("core.tangle") +local Path = require("pathlib") module.setup = function() return { @@ -262,6 +265,7 @@ module.public = { local previous_headings = {} local commentstrings = {} local file_content_line_start = {} + local buf_name = vim.api.nvim_buf_get_name(buffer) for id, node in query:iter_captures(document_root, buffer, 0, -1) do local capture = query.captures[id] @@ -321,6 +325,12 @@ module.public = { goto skip_tag end + local path_lib_path = Path.new(file_to_tangle_to) + if path_lib_path:is_relative() then + local buf_path = Path.new(buf_name) + file_to_tangle_to = tostring(buf_path:parent():child(file_to_tangle_to):resolve()) + end + local delimiter_content if options.delimiter == "heading" or options.delimiter == "file-content" then local language