Working an org-tangle functionality for neovim orgmode. In a nutshell, it’s like tagging all the fenced code blocks in a markdown file to actual code files, then those code blocks get concatenated into their respective targets. For example, I’ve got a tmux.org that tangles to install.sh, tmux.conf, and base.conf.
I just got to the point where it’s parsing header args from document directives, property drawers, and directly on code blocks. My implementation is based on nvim-personal-config/org.lua at cc2a12075eca8a72927f28703df5d0746c10ac07 · andreadev-it/nvim-personal-config · GitHub.
Now that it’s working, there’s one last feature I really want to include:
When tangling, I’d really like it to prepend each write to the file with a comment indicating the org file it was tangled from and the line where the code block starts.
Since most the heavy lifting was done by tree-sitter I got the filename, and the line number already. What I need some help/pointers/links/examples for are two problems:
- How would I generate a valid comment in a target language to write to files when tangling?
- Are there any built-ins for calculating relative paths from pwd to the abspath of a file? In node I’d use
path.relative(cwd, absoluteDest)
.
Any hints or advice would be helpful!