Skip to content

Commit 2a0dfed

Browse files
Move custom ts grammer configuration to setup function.
1 parent 914de06 commit 2a0dfed

File tree

8 files changed

+174
-82
lines changed

8 files changed

+174
-82
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
- v0.5.0
1818
- v0.5.1
1919
- v0.6.0
20+
- v0.6.1
2021
- nightly
2122
runs-on: ubuntu-latest
2223
steps:

DOCS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ Available options:
8686
* underline - `:underline on`
8787
* italic - `:slant italic`
8888

89+
---
90+
8991
Full configuration example with additional todo keywords and their colors:
9092
```lua
9193
require('orgmode').setup({
@@ -1183,6 +1185,7 @@ set statusline=%{v:lua.orgmode.statusline()}
11831185
```
11841186

11851187
## Changelog
1188+
To track breaking changes, subscribe to [Notice of breaking changes](https://github.com/nvim-orgmode/orgmode/issues/217) issue where those are announced.
11861189

11871190
#### 24 October 2021
11881191
* Help mapping was changed from `?` to `g?` to avoid conflict with built in backward search. See issue [#106](https://github.com/nvim-orgmode/orgmode/issues/106).

README.md

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,10 @@ call dein#add('nvim-orgmode/orgmode')
7171
```lua
7272
-- init.lua
7373

74-
local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
75-
parser_config.org = {
76-
install_info = {
77-
url = 'https://github.com/milisims/tree-sitter-org',
78-
revision = 'main',
79-
files = {'src/parser.c', 'src/scanner.cc'},
80-
},
81-
filetype = 'org',
82-
}
74+
-- Load custom tree-sitter grammar for org filetype
75+
require('orgmode').setup_ts_grammar()
8376

77+
-- Tree-sitter configuration
8478
require'nvim-treesitter.configs'.setup {
8579
-- If TS highlights are not enabled at all, or disabled via `disable` prop, highlighting will fallback to default Vim syntax highlighting
8680
highlight = {
@@ -101,16 +95,11 @@ Or if you are using `init.vim`:
10195
```vim
10296
" init.vim
10397
lua << EOF
104-
local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
105-
parser_config.org = {
106-
install_info = {
107-
url = 'https://github.com/milisims/tree-sitter-org',
108-
revision = 'main',
109-
files = {'src/parser.c', 'src/scanner.cc'},
110-
},
111-
filetype = 'org',
112-
}
11398
99+
-- Load custom tree-sitter grammar for org filetype
100+
require('orgmode').setup_ts_grammar()
101+
102+
-- Tree-sitter configuration
114103
require'nvim-treesitter.configs'.setup {
115104
-- If TS highlights are not enabled at all, or disabled via `disable` prop, highlighting will fallback to default Vim syntax highlighting
116105
highlight = {

doc/orgmode.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ Available options:
261261
* underline - `:underline on`
262262
* italic - `:slant italic`
263263

264+
--------------------------------------------------------------------------------
264265
Full configuration example with additional todo keywords and their colors:
265266
>
266267
require('orgmode').setup({
@@ -1572,6 +1573,8 @@ Show the currently clocked in headline (if any), with total clocked time / effor
15721573
--------------------------------------------------------------------------------
15731574
CHANGELOG *orgmode-changelog*
15741575

1576+
To track breaking changes, subscribe to Notice of breaking changes (https://github.com/nvim-orgmode/orgmode/issues/217) issue where those are announced.
1577+
15751578
24 OCTOBER 2021 *orgmode-24_october_2021*
15761579

15771580
* Help mapping was changed from `?` to `g?` to avoid conflict with built in backward search. See issue #106 (https://github.com/nvim-orgmode/orgmode/issues/106).

lua/orgmode/init.lua

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
_G.orgmode = _G.orgmode or {}
1+
_G.orgmode = _G.orgmode or {
2+
ts_revision = '1c3eb533a9cf6800067357b59e03ac3f91fc3a54',
3+
}
4+
local setup_ts_grammar_used = false
25
local instance = nil
36

47
---@class Org
@@ -58,10 +61,42 @@ function Org:setup_autocmds()
5861
vim.cmd([[augroup END]])
5962
end
6063

64+
--- @param revision string?
65+
local function setup_ts_grammar(revision)
66+
setup_ts_grammar_used = true
67+
local parser_config = require('nvim-treesitter.parsers').get_parser_configs()
68+
parser_config.org = {
69+
install_info = {
70+
url = 'https://github.com/milisims/tree-sitter-org',
71+
revision = revision or _G.orgmode.ts_revision,
72+
files = { 'src/parser.c', 'src/scanner.cc' },
73+
},
74+
filetype = 'org',
75+
}
76+
end
77+
78+
local function check_ts_grammar()
79+
if setup_ts_grammar_used then
80+
return
81+
end
82+
vim.defer_fn(function()
83+
local parser_config = require('nvim-treesitter.parsers').get_parser_configs()
84+
if parser_config and parser_config.org and parser_config.org.install_info.revision ~= _G.orgmode.ts_revision then
85+
require('orgmode.utils').echo_error({
86+
'You are using outdated version of tree-sitter grammar for Orgmode.',
87+
'To use latest version, replace current grammar installation with "require(\'orgmode\').setup_ts_grammar()" and run :TSUpdate org.',
88+
'More info in setup section of readme: https://github.com/nvim-orgmode/orgmode#setup',
89+
})
90+
end
91+
end, 200)
92+
end
93+
6194
---@param opts? table
6295
---@return Org
6396
local function setup(opts)
97+
opts = opts or {}
6498
instance = Org:new()
99+
check_ts_grammar()
65100
local config = require('orgmode.config'):extend(opts)
66101
vim.defer_fn(function()
67102
if config.notifications.enabled and #vim.api.nvim_list_uis() > 0 then
@@ -140,6 +175,7 @@ function _G.orgmode.statusline()
140175
end
141176

142177
return {
178+
setup_ts_grammar = setup_ts_grammar,
143179
setup = setup,
144180
reload = reload,
145181
action = action,

lua/orgmode/parser/file.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,12 +381,12 @@ function File:_parse_source_code_filetypes()
381381
end
382382

383383
function File:_parse_directives()
384-
local directives = self:get_ts_matches(
385-
[[(directive name: (expr) @name value: (value) @value (#match? @name "\\cfiletags"))]]
386-
)
384+
local directives = self:get_ts_matches([[(directive name: (expr) @name value: (value) @value)]])
387385
local tags = {}
388386
for _, directive in ipairs(directives) do
389-
utils.concat(tags, utils.parse_tags_string(directive.value.text), true)
387+
if directive.name.text:lower() == 'filetags' then
388+
utils.concat(tags, utils.parse_tags_string(directive.value.text), true)
389+
end
390390
end
391391
self.tags = tags
392392
end

0 commit comments

Comments
 (0)