Skip to content

Commit

Permalink
add load_paths
Browse files Browse the repository at this point in the history
  • Loading branch information
mrshmllow committed Jun 30, 2023
1 parent dd47359 commit d38c691
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
37 changes: 37 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

12 changes: 12 additions & 0 deletions lua/orgmode-babel/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down

0 comments on commit d38c691

Please sign in to comment.