Skip to content

Commit 93ab75f

Browse files
[BREAKING CHANGE] Update to latest tree sitter grammar version
1 parent 78ea0a8 commit 93ab75f

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

lua/orgmode/init.lua

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
_G.orgmode = _G.orgmode or {}
2-
local ts_revision = '1c3eb533a9cf6800067357b59e03ac3f91fc3a54'
2+
local ts_revision = '9a595e51c1f69b9ac986f0e0b788804eda0e755d'
33
local setup_ts_grammar_used = false
44
local instance = nil
55

@@ -75,10 +75,10 @@ local function setup_ts_grammar(revision)
7575
end
7676

7777
local function check_ts_grammar()
78-
if setup_ts_grammar_used then
79-
return
80-
end
8178
vim.defer_fn(function()
79+
if setup_ts_grammar_used then
80+
return
81+
end
8282
local parser_config = require('nvim-treesitter.parsers').get_parser_configs()
8383
if parser_config and parser_config.org and parser_config.org.install_info.revision ~= ts_revision then
8484
require('orgmode.utils').echo_error({

lua/orgmode/org/mappings.lua

+14-4
Original file line numberDiff line numberDiff line change
@@ -454,16 +454,26 @@ function OrgMappings:handle_return(suffix)
454454
item = Files.get_current_file():get_current_node()
455455
end
456456

457-
if item.type == 'itemtext' or item.type == 'bullet' or item.type == 'checkbox' or item.type == 'description' then
457+
if item.type == 'paragraph' or item.type == 'bullet' then
458458
local list_item = item.node:parent()
459459
if list_item:type() ~= 'listitem' then
460460
return
461461
end
462462
local line = vim.fn.getline(list_item:start() + 1)
463463
local end_row, _ = list_item:end_()
464+
local next_line_node = current_file:get_node_at_cursor({ end_row + 1, 0 })
465+
local second_line_node = current_file:get_node_at_cursor({ end_row + 2, 0 })
466+
local is_end_of_file = next_line_node
467+
and vim.tbl_contains({ 'paragraph', 'list' }, next_line_node:type())
468+
and second_line_node
469+
and second_line_node:type() == 'document'
470+
-- Range for list items at the very end of the file are not calculated properly
471+
if (end_row + 1) == vim.fn.line('$') and is_end_of_file then
472+
end_row = end_row + 1
473+
end
464474
local range = {
465-
start = { line = end_row + 1, character = 0 },
466-
['end'] = { line = end_row + 1, character = 0 },
475+
start = { line = end_row, character = 0 },
476+
['end'] = { line = end_row, character = 0 },
467477
}
468478

469479
local checkbox = line:match('^(%s*[%+%-])%s*%[[%sXx%-]?%]')
@@ -512,7 +522,7 @@ function OrgMappings:handle_return(suffix)
512522
if #text_edits > 0 then
513523
vim.lsp.util.apply_text_edits(text_edits, 0, constants.default_offset_encoding)
514524

515-
vim.fn.cursor(end_row + 2 + (add_empty_line and 1 or 0), 0) -- +1 for 0 index and +1 for next line
525+
vim.fn.cursor(end_row + 1 + (add_empty_line and 1 or 0), 0) -- +1 for next line
516526
vim.cmd([[startinsert!]])
517527
end
518528
end

queries/org/highlights.scm

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
(headline (stars) @stars (#eq? @stars "*******")) @OrgTSHeadlineLevel7
1010
(headline (stars) @stars (#eq? @stars "********")) @OrgTSHeadlineLevel8
1111
(bullet) @OrgTSBullet
12-
(checkbox) @OrgTSCheckbox
13-
((checkbox) @check (#eq? @check "\[-\]")) @OrgTSCheckboxHalfChecked
14-
((checkbox) @check (#eq? @check "\[ \]")) @OrgTSCheckboxUnchecked
15-
((checkbox) @check (#match? @check "\[[xX]\]")) @OrgTSCheckboxChecked
12+
(listitem . (bullet) . (paragraph . (expr "[" "str" @OrgCheckDone "]") @OrgTSCheckboxChecked (#match? @OrgTSCheckboxChecked "\[[xX]\]")))
13+
(listitem . (bullet) . (paragraph . (expr "[" "-" @OrgCheckInProgress "]") @OrgTSCheckboxHalfChecked (#eq? @OrgTSCheckboxHalfChecked "[-]")))
14+
(listitem . (bullet) . (paragraph . ((expr "[") @OrgTSCheckbox.left (#eq? @OrgTSCheckbox.left "[") . (expr "]") @OrgTSCheckbox.right (#eq? @OrgTSCheckbox.right "]"))))
1615
(property_drawer) @OrgTSPropertyDrawer
1716
(drawer) @OrgTSDrawer
1817
(tag) @OrgTSTag

0 commit comments

Comments
 (0)