orgmode icon indicating copy to clipboard operation
orgmode copied to clipboard

Added tangle functionality to org files

Open andreadev-it opened this issue 1 year ago • 7 comments

This PR has been created to propose a way to implement the tangling functionality existing in ORG Mode (following Discussion #275 ). The current code will add a tangle function as a method of an Org File, since this seemed the most flexible way to implement this.

With this PR, you can write the following in order to tangle block files found under specific headings:

* Heading 1
  :PROPERTY:
  :TANGLE: ./filename.lua
  :END:
  
  #+begin_src lua
  print("Test")
  #+end_src

Since this is a stub, I've not yet thought if the action should be triggered by a keymap or by a command. Currently, you can tangle the file from lua using this code:

local file = require("orgmode.parse.files").get_current_file()
file:tangle()

This is not a 1:1 copy of the syntax that is implemented in the original Org Mode, since it seems like treesitter isn't able to comprehend the original one.

Things that I'd like to discuss about this implementations are:

  • The currently used syntax is different from what Org Mode does. It was meant to be more easily parsed by treesitter, but other options are welcome
  • How to handle when the filename isn't defined (the original uses the filename + an extension based on the code block language)
  • How to expose this functionality to the user
  • I've added a function that changes a relative path to an absolute one. This has been done elsewere in the code, but I think it could need some improment, maybe we can create a function in utils.lua?

Of course, if there are other questions or suggestions, don't hold back! Hope this can be of some help 🙂

andreadev-it avatar Nov 02 '22 13:11 andreadev-it