wallyqs / org-ruby

An Org mode parser written in Ruby.
218 stars 51 forks source link

#+INCLUDE support for embedding source code #75

Open falloutphil opened 4 years ago

falloutphil commented 4 years ago

Hi,

I'm using this on github for rendering my README.org file.

Whilst BEGIN_SRC and END_SRC blocks work a charm, you don't seem to be able to reference part of a file in the same repo, for example something like the below would use a relative path to the README.org file that contains the reference:

#+INCLUDE: "./elhome/settings/foo-settings.el" src emacs-lisp :lines "2-20"

This would be immensely useful for cases where I am unable to use literate programming techniques to refactor my elisp files into org file using babel.

My guess is the grunt work could reuse what is already there form BEGIN/END_SRC support.

melioratus commented 4 years ago

@falloutphil - The #+INCLUDE: syntax is available in org-ruby but requires two environmental variables to be set at run time to to enable the functionality. See parser.rb#L102

      #
      # Include file feature disabled by default since 
      # it would be dangerous in some environments
      #
      # http://orgmode.org/manual/Include-files.html
      #
      # It will be activated by one of the following:
      #
      # - setting an ORG_RUBY_ENABLE_INCLUDE_FILES env variable to 'true'
      # - setting an ORG_RUBY_INCLUDE_ROOT env variable with the root path
      # - explicitly enabling it by passing it as an option:
      #   e.g. Orgmode::Parser.new(org_text, { :allow_include_files => true })
      #
      # IMPORTANT: To avoid the feature altogether, it can be _explicitly disabled_ as follows:
      #   e.g. Orgmode::Parser.new(org_text, { :allow_include_files => false })
      #

As a workaround for this default configuration setting, I started to export README.org and other common files from a dedicated file, common-project-files.org.

Note: At the time of this post, the README.org section in common-project-files.org does not use #+INCLUDE: statements but I plan to add this feature because I would like to add usage and other code examples from other files in my projects.

Hope that helps.

Melioratus