add load_paths

This commit is contained in:
marshmallow 2023-06-30 14:54:59 +10:00
parent dd473593d5
commit d38c691151
No known key found for this signature in database
GPG key ID: 767B8880F5AAEB9C
2 changed files with 49 additions and 0 deletions

View file

@ -31,6 +31,9 @@ you to add anything extra to your ~init.el~.
opts = { opts = {
-- by default, none are enabled -- by default, none are enabled
langs = { "python", "lua", ... } langs = { "python", "lua", ... }
-- paths to emacs packages to additionally load
load_paths = {}
} }
}, },
#+end_src #+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 likely only contain the contents of the last block, which is expected
behaviour. 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

View file

@ -6,6 +6,7 @@ function M.setup(opts)
opts = opts or opts opts = opts or opts
M.langs = opts.langs and opts.langs or {} 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._here = vim.fn.fnamemodify(debug.getinfo(1).source:sub(2), ":p:h")
M._run_by_name = M._here .. "/run_by_name.el" M._run_by_name = M._here .. "/run_by_name.el"
@ -26,6 +27,17 @@ function M.setup(opts)
"(setq make-backup-files nil)", "(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, { vim.list_extend(M._base_cmd, {
"--eval", "--eval",
"(org-babel-do-load-languages 'org-babel-load-languages '(" .. vim.fn.reduce(M.langs, function(acc, value) "(org-babel-do-load-languages 'org-babel-load-languages '(" .. vim.fn.reduce(M.langs, function(acc, value)