Skip to content

Commit 0939e49

Browse files
feat(globals): Add install_treesitter_grammar to global command
1 parent 4916587 commit 0939e49

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

docs/index.org

+3
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,13 @@ List of available actions:
6262
- =:Org helpgrep= - Open search agenda view that allows searching through the documentation
6363
- =:Org agenda {type?}= - Open agenda view by the shortcut, for example =:Org agenda M= will open =tags_todo= view. When =type= is omitted, it opens up Agenda view.
6464
- =:Org capture {type?}= - Open capture template by the shortcut, for example =:Org capture t=. When =type= is omitted, it opens up Capture prompt.
65+
- =:Org install_treesitter_grammar= - Install the treesitter grammar for orgmode. If installed, prompt to reinstall. Grammar is installed automatically
66+
on first run, but this is useful in case when there are issues with the grammar.
6567

6668
All of the commands above can be executed through the global Lua =Org= variable. Examples:
6769
- =Org.help()=
6870
- =Org.helpgrep()=
71+
- =Org.install_treesitter_grammar()=
6972
- =Org.agenda()= - Opens =agenda= prompt
7073
- =Org.agenda.m()= - Opens =tags= view
7174
- =Org.capture()= - Opens capture prompt

docs/troubleshoot.org

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Make sure you are not overriding indentexpr in Org buffers with [[https://github
66
*** I get ~treesitter/query.lua~ errors when opening agenda/capture prompt or org files
77

88
Tree-sitter parser might not be installed.
9-
Try running ~:lua require('orgmode.config'):reinstall_grammar()~ to reinstall it.
9+
Try running ~:Org install_treesitter_grammar~ to reinstall it.
1010

1111
*** Dates are not in English
1212
Dates are generated with Lua native date support, and it reads your current locale when creating them.

lua/orgmode/config/init.lua

+2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ function Config:install_grammar()
3333
local ok, result, err = pcall(vim.treesitter.language.add, 'org')
3434
if not ok or (not result and err ~= nil) then
3535
require('orgmode.utils.treesitter.install').run()
36+
return true
3637
end
38+
return false
3739
end
3840

3941
---@param url? string

lua/orgmode/org/global.lua

+11
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@ local build = function(orgmode)
6262
})
6363
end,
6464

65+
install_treesitter_grammar = function()
66+
local installed = require('orgmode.config'):install_grammar()
67+
if not installed then
68+
local choice =
69+
vim.fn.confirm('Treesitter grammar is already installed. Do you want to re-install it?', '&Yes\n&No', 2)
70+
if choice == 1 then
71+
return require('orgmode.config'):reinstall_grammar()
72+
end
73+
end
74+
end,
75+
6576
agenda = generate_agenda_object(orgmode, config),
6677
capture = generate_capture_object(orgmode, config),
6778
}

0 commit comments

Comments
 (0)