From dd473593d56ac350cc307a0c4fe8d472347eaa07 Mon Sep 17 00:00:00 2001 From: mrshmllow Date: Fri, 30 Jun 2023 03:12:06 +0000 Subject: [PATCH 01/10] Auto generate docs --- doc/orgmode-babel.nvim.txt | 52 +------------------------------------- 1 file changed, 1 insertion(+), 51 deletions(-) diff --git a/doc/orgmode-babel.nvim.txt b/doc/orgmode-babel.nvim.txt index 031d1da..f76b627 100644 --- a/doc/orgmode-babel.nvim.txt +++ b/doc/orgmode-babel.nvim.txt @@ -1,4 +1,4 @@ -*orgmode-babel.nvim.txt* For NVIM v0.9.0 Last change: 2023 June 27 +*orgmode-babel.nvim.txt* For NVIM v0.9.0 Last change: 2023 June 30 ============================================================================== Table of Contents *orgmode-babel.nvim-table-of-contents* @@ -7,7 +7,6 @@ Table of Contents *orgmode-babel.nvim-table-of-contents* - Requirements |orgmode-babel.nvim-orgmode-babel.nvim-requirements| - Setup |orgmode-babel.nvim-orgmode-babel.nvim-setup| - Usage |orgmode-babel.nvim-orgmode-babel.nvim-usage| - - Advanced Configuration|orgmode-babel.nvim-orgmode-babel.nvim-advanced-configuration| ============================================================================== 1. orgmode-babel.nvim *orgmode-babel.nvim-orgmode-babel.nvim* @@ -89,55 +88,6 @@ 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*orgmode-babel.nvim-orgmode-babel.nvim-advanced-configuration* - - -ADDING EXTRA ORG-MODE LANGUAGES ~ - -Your emacs `init.el` will be sourced during execution of `:OrgExecute` and -`:OrgTangle`, so packages you install there that provide extra babel languages -will be available! - -Follow the package's installation steps, and if they tell you to include it in -`org-babel-load-languages`, additionally make sure that you include it in -`opts.langs`. - -1. Example - -As an example, lets add ob-mermaid for -mermaid functionality in `orgmode-babel.nvim`! - -First, lets create a `~/.emacs.d/init.el`. - -> - ; ~/.emacs.d/init.el - - ; Add the melpa package manager - (require 'package) - (add-to-list 'package-archives - '("melpa" . "https://melpa.org/packages/") t) - (package-initialize) - - ; Install ob-mermaid - (unless (package-installed-p 'ob-mermaid) - (package-install 'ob-mermaid)) -< - -Then, in our plugin configuration, we can add `mermaid` to our `opts.langs`. - ->lua - { - "mrshmllow/orgmode-babel.nvim", - ... - opts = { - langs = { ..., "mermaid" } - } - }, -< - - - Generated by panvimdoc vim:tw=78:ts=8:noet:ft=help:norl: From d38c691151eb9570f7cd98ca43c5957e18878e78 Mon Sep 17 00:00:00 2001 From: marshmallow Date: Fri, 30 Jun 2023 14:54:59 +1000 Subject: [PATCH 02/10] 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) From f0d8aa0fd783eb7734a8e83ffcbac48c65698cff Mon Sep 17 00:00:00 2001 From: mrshmllow Date: Fri, 30 Jun 2023 04:55:19 +0000 Subject: [PATCH 03/10] Auto generate docs --- doc/orgmode-babel.nvim.txt | 43 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/doc/orgmode-babel.nvim.txt b/doc/orgmode-babel.nvim.txt index f76b627..dfd6044 100644 --- a/doc/orgmode-babel.nvim.txt +++ b/doc/orgmode-babel.nvim.txt @@ -7,6 +7,7 @@ Table of Contents *orgmode-babel.nvim-table-of-contents* - Requirements |orgmode-babel.nvim-orgmode-babel.nvim-requirements| - Setup |orgmode-babel.nvim-orgmode-babel.nvim-setup| - Usage |orgmode-babel.nvim-orgmode-babel.nvim-usage| + - Advanced Configuration|orgmode-babel.nvim-orgmode-babel.nvim-advanced-configuration| ============================================================================== 1. orgmode-babel.nvim *orgmode-babel.nvim-orgmode-babel.nvim* @@ -46,6 +47,9 @@ LAZY.NVIM ~ opts = { -- by default, none are enabled langs = { "python", "lua", ... } + + -- paths to emacs packages to additionally load + load_paths = {} } }, < @@ -88,6 +92,45 @@ 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*orgmode-babel.nvim-orgmode-babel.nvim-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. + +1. Example + +As an example, lets add 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. + +>example + git clone https://github.com/arnm/ob-mermaid ~/.../clone-location/ob-mermaid +< + +>lua + { + "mrshmllow/orgmode-babel.nvim", + ... + opts = { + langs = { ..., "mermaid" } + load_paths = { "~/.../clone-location/ob-mermaid" } + } + }, +< + + + Generated by panvimdoc vim:tw=78:ts=8:noet:ft=help:norl: From b987927c4c8b545b7f9bc38c9ae85210eedbd67b Mon Sep 17 00:00:00 2001 From: marshmallow Date: Fri, 21 Jul 2023 12:07:17 +1000 Subject: [PATCH 04/10] add my best guess to a packer configuration --- README.org | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.org b/README.org index d0a037f..bd2ffa7 100644 --- a/README.org +++ b/README.org @@ -38,6 +38,29 @@ you to add anything extra to your ~init.el~. }, #+end_src +*** Packer + +#+begin_src lua +use { + "mrshmllow/orgmode-babel.nvim", + requires = { + "nvim-orgmode/orgmode", + "nvim-treesitter/nvim-treesitter" + }, + cmd = { "OrgExecute", "OrgTangle" }, + opt = true, + config = function () + require("orgmode-babel").setup({ + -- by default, none are enabled + langs = { "python", "lua", ... } + + -- paths to emacs packages to additionally load + load_paths = {} + }) + end +} +#+end_src + ** Usage All commands accept a ~!~ to skip confirmation. From da8c98632c6c56a76f378df80dfdfb5fea4d0e70 Mon Sep 17 00:00:00 2001 From: mrshmllow Date: Fri, 21 Jul 2023 02:07:47 +0000 Subject: [PATCH 05/10] Auto generate docs --- doc/orgmode-babel.nvim.txt | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/doc/orgmode-babel.nvim.txt b/doc/orgmode-babel.nvim.txt index dfd6044..c68a2a1 100644 --- a/doc/orgmode-babel.nvim.txt +++ b/doc/orgmode-babel.nvim.txt @@ -1,4 +1,4 @@ -*orgmode-babel.nvim.txt* For NVIM v0.9.0 Last change: 2023 June 30 +*orgmode-babel.nvim.txt* For NVIM v0.9.0 Last change: 2023 July 21 ============================================================================== Table of Contents *orgmode-babel.nvim-table-of-contents* @@ -55,6 +55,30 @@ LAZY.NVIM ~ < +PACKER ~ + +>lua + use { + "mrshmllow/orgmode-babel.nvim", + requires = { + "nvim-orgmode/orgmode", + "nvim-treesitter/nvim-treesitter" + }, + cmd = { "OrgExecute", "OrgTangle" }, + opt = true, + config = function () + require("orgmode-babel").setup({ + -- by default, none are enabled + langs = { "python", "lua", ... } + + -- paths to emacs packages to additionally load + load_paths = {} + }) + end + } +< + + USAGE *orgmode-babel.nvim-orgmode-babel.nvim-usage* All commands accept a `!` to skip confirmation. From 2f431e8f8ea676e2ae769c4d95a5a76e0d33d5fb Mon Sep 17 00:00:00 2001 From: marshmallow Date: Sat, 22 Jul 2023 12:04:25 +1000 Subject: [PATCH 06/10] fix bug in opts setup --- lua/orgmode-babel/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/orgmode-babel/init.lua b/lua/orgmode-babel/init.lua index e1f4fd9..b076c7f 100644 --- a/lua/orgmode-babel/init.lua +++ b/lua/orgmode-babel/init.lua @@ -3,7 +3,7 @@ local M = { } function M.setup(opts) - opts = opts or opts + opts = opts or {} M.langs = opts.langs and opts.langs or {} M.load_paths = opts.load_paths and opts.load_paths or {} From c1c209c90108d1fc3aed3c650fab9287d86cad87 Mon Sep 17 00:00:00 2001 From: mrshmllow Date: Sat, 22 Jul 2023 02:05:06 +0000 Subject: [PATCH 07/10] Auto generate docs --- doc/orgmode-babel.nvim.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/orgmode-babel.nvim.txt b/doc/orgmode-babel.nvim.txt index c68a2a1..2e7ad0a 100644 --- a/doc/orgmode-babel.nvim.txt +++ b/doc/orgmode-babel.nvim.txt @@ -1,4 +1,4 @@ -*orgmode-babel.nvim.txt* For NVIM v0.9.0 Last change: 2023 July 21 +*orgmode-babel.nvim.txt* For NVIM v0.9.0 Last change: 2023 July 22 ============================================================================== Table of Contents *orgmode-babel.nvim-table-of-contents* From 29e1efd20aeadb2d215ff7f1ee7f50e97b1c04d9 Mon Sep 17 00:00:00 2001 From: marshmallow Date: Sun, 23 Jul 2023 14:51:08 +1000 Subject: [PATCH 08/10] fix missing , in lua examples Co-authored-by: refaelsh --- README.org | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.org b/README.org index bd2ffa7..06219ec 100644 --- a/README.org +++ b/README.org @@ -30,7 +30,7 @@ you to add anything extra to your ~init.el~. cmd = { "OrgExecute", "OrgTangle" }, opts = { -- by default, none are enabled - langs = { "python", "lua", ... } + langs = { "python", "lua", ... }, -- paths to emacs packages to additionally load load_paths = {} @@ -52,7 +52,7 @@ use { config = function () require("orgmode-babel").setup({ -- by default, none are enabled - langs = { "python", "lua", ... } + langs = { "python", "lua", ... }, -- paths to emacs packages to additionally load load_paths = {} From cf5c90c07985188ad5f25160430f8663ecdb58e3 Mon Sep 17 00:00:00 2001 From: mrshmllow Date: Sun, 23 Jul 2023 04:52:10 +0000 Subject: [PATCH 09/10] Auto generate docs --- doc/orgmode-babel.nvim.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/orgmode-babel.nvim.txt b/doc/orgmode-babel.nvim.txt index 2e7ad0a..2d97cd1 100644 --- a/doc/orgmode-babel.nvim.txt +++ b/doc/orgmode-babel.nvim.txt @@ -1,4 +1,4 @@ -*orgmode-babel.nvim.txt* For NVIM v0.9.0 Last change: 2023 July 22 +*orgmode-babel.nvim.txt* For NVIM v0.9.0 Last change: 2023 July 23 ============================================================================== Table of Contents *orgmode-babel.nvim-table-of-contents* @@ -46,7 +46,7 @@ LAZY.NVIM ~ cmd = { "OrgExecute", "OrgTangle" }, opts = { -- by default, none are enabled - langs = { "python", "lua", ... } + langs = { "python", "lua", ... }, -- paths to emacs packages to additionally load load_paths = {} @@ -69,7 +69,7 @@ PACKER ~ config = function () require("orgmode-babel").setup({ -- by default, none are enabled - langs = { "python", "lua", ... } + langs = { "python", "lua", ... }, -- paths to emacs packages to additionally load load_paths = {} From 437ddcbc87aedcab5c3b70266e43682abd4703dd Mon Sep 17 00:00:00 2001 From: "Haoyuan (Bill) Xing" Date: Wed, 16 Apr 2025 21:44:39 -0700 Subject: [PATCH 10/10] fixed tree-sitter iterators. --- lua/orgmode-babel/init.lua | 47 +++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/lua/orgmode-babel/init.lua b/lua/orgmode-babel/init.lua index b076c7f..ffe7e29 100644 --- a/lua/orgmode-babel/init.lua +++ b/lua/orgmode-babel/init.lua @@ -89,26 +89,29 @@ function M.get_names_in_buffer(bufnr, line1, line2) local passed = not range local name - for id, node in pairs(match) do - local row1, col1, row2, col2 = node:range() - local text = vim.api.nvim_buf_get_text(bufnr, row1, col1, row2, col2, {})[1] + for id, nodes in pairs(match) do + for _, node in ipairs(nodes) do + local row1, col1, row2, col2 = node:range() - if named_blocks_query.captures[id] == "block" and not passed then - if single and line1 - 1 > row1 and line1 - 1 < row2 then - passed = true - elseif not single and line1 - 1 <= row1 and row2 <= line2 - 1 then - passed = true + local text = vim.api.nvim_buf_get_text(bufnr, row1, col1, row2, col2, {})[1] + + if named_blocks_query.captures[id] == "block" and not passed then + if single and line1 - 1 > row1 and line1 - 1 < row2 then + passed = true + elseif not single and line1 - 1 <= row1 and row2 <= line2 - 1 then + passed = true + end + end + + if named_blocks_query.captures[id] == "name" then + name = text end end - if named_blocks_query.captures[id] == "name" then - name = text + if passed then + table.insert(names, name) end end - - if passed then - table.insert(names, name) - end end return names end @@ -130,14 +133,16 @@ function M.get_blocks_in_buffer(bufnr, line1, line2) for _, match in unnamed_blocks_query:iter_matches(root, bufnr, 0, -1) do local passed = not range - for id, node in pairs(match) do - local row1, _, row2 = node:range() + for id, nodes in pairs(match) do + for _, node in ipairs(nodes) do + local row1, _, row2 = node:range() - if unnamed_blocks_query.captures[id] == "block" and not passed then - if single and line1 - 1 > row1 and line1 - 1 < row2 then - passed = true - elseif not single and line1 - 1 <= row1 and row2 <= line2 - 1 then - passed = true + if unnamed_blocks_query.captures[id] == "block" and not passed then + if single and line1 - 1 > row1 and line1 - 1 < row2 then + passed = true + elseif not single and line1 - 1 <= row1 and row2 <= line2 - 1 then + passed = true + end end end end