From d38c691151eb9570f7cd98ca43c5957e18878e78 Mon Sep 17 00:00:00 2001 From: marshmallow Date: Fri, 30 Jun 2023 14:54:59 +1000 Subject: [PATCH] add `load_paths` --- README.org | 37 +++++++++++++++++++++++++++++++++++++ lua/orgmode-babel/init.lua | 12 ++++++++++++ 2 files changed, 49 insertions(+) diff --git a/README.org b/README.org index 802c1db..d0a037f 100644 --- a/README.org +++ b/README.org @@ -31,6 +31,9 @@ you to add anything extra to your ~init.el~. opts = { -- by default, none are enabled langs = { "python", "lua", ... } + + -- paths to emacs packages to additionally load + load_paths = {} } }, #+end_src @@ -67,3 +70,37 @@ Tangles all blocks in range. If the range is NOT ~%~, the tangled file will likely only contain the contents of the last block, which is expected behaviour. +** Advanced Configuration +*** Adding extra org-mode languages + +Your emacs ~init.el~ will *not* be sourced during execution of ~:OrgExecute~ and +~:OrgTangle~, so packages you install there wont be available. + +However, ~orgmode-babel.nvim~ allows us to specify extra load paths, so we can +make packages available that way. + +**** Example + +As an example, lets add [[https://github.com/arnm/ob-mermaid][ob-mermaid]] for +mermaid functionality in ~orgmode-babel.nvim~! + +We have two options to get the package. We could either create an +=~/.emacs.d/init.el= and install it through a package manager, which will likely +have a randomish name, or for the sake of simplicity and this being a neovim +plugin, we can simply manually clone the repo to a known location. + +#+begin_example +git clone https://github.com/arnm/ob-mermaid ~/.../clone-location/ob-mermaid +#+end_example + +#+begin_src lua +{ + "mrshmllow/orgmode-babel.nvim", + ... + opts = { + langs = { ..., "mermaid" } + load_paths = { "~/.../clone-location/ob-mermaid" } + } +}, +#+end_src + diff --git a/lua/orgmode-babel/init.lua b/lua/orgmode-babel/init.lua index c8ab345..e1f4fd9 100644 --- a/lua/orgmode-babel/init.lua +++ b/lua/orgmode-babel/init.lua @@ -6,6 +6,7 @@ function M.setup(opts) opts = opts or opts M.langs = opts.langs and opts.langs or {} + M.load_paths = opts.load_paths and opts.load_paths or {} M._here = vim.fn.fnamemodify(debug.getinfo(1).source:sub(2), ":p:h") M._run_by_name = M._here .. "/run_by_name.el" @@ -26,6 +27,17 @@ function M.setup(opts) "(setq make-backup-files nil)", } + vim.list_extend( + M._base_cmd, + vim.fn.reduce(M.load_paths, function(acc, value) + vim.list_extend(acc, { + "--eval", + [[(add-to-list 'load-path "]] .. value .. [[")]], + }) + return acc + end, {}) + ) + vim.list_extend(M._base_cmd, { "--eval", "(org-babel-do-load-languages 'org-babel-load-languages '(" .. vim.fn.reduce(M.langs, function(acc, value)