Skip to content

Commit

Permalink
fix!: tangle files relative to norg file (#1415)
Browse files Browse the repository at this point in the history
  • Loading branch information
benlubas authored Jul 15, 2024
1 parent 1347eeb commit 3c3b977
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lua/neorg/modules/core/tangle/module.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 <output-file>` 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
<output-file>` tag above the code block you'd wish to export, where <output-file> is relative to the
current file. For example:
```norg
#tangle init.lua
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3c3b977

Please sign in to comment.