1
1
local Files = require (' orgmode.parser.files' )
2
2
local Table = require (' orgmode.treesitter.table' )
3
+ local ts_org = require (' orgmode.treesitter' )
4
+
5
+ local function format_line (linenr )
6
+ local line_text = vim .fn .getline (linenr )
7
+
8
+ if line_text :match (' ^%*+%s' ) then
9
+ local headline = ts_org .closest_headline ({ linenr , 1 })
10
+ if headline then
11
+ headline :align_tags ()
12
+ return true
13
+ end
14
+ end
15
+
16
+ if Table .format (linenr ) then
17
+ return true
18
+ end
19
+
20
+ local ok , item = pcall (Files .get_closest_headline , linenr )
21
+ if ok and item and item .logbook and item .logbook .range :is_in_line_range (linenr ) then
22
+ item .logbook :recalculate_estimate (linenr )
23
+ return true
24
+ end
25
+
26
+ return false
27
+ end
3
28
4
29
local function format ()
5
30
if vim .tbl_contains ({ ' i' , ' R' , ' ic' , ' ix' }, vim .fn .mode ()) then
@@ -8,16 +33,17 @@ local function format()
8
33
return 1
9
34
end
10
35
11
- local table = Table .format ()
36
+ local start_line = vim .v .lnum
37
+ local end_line = vim .v .lnum + vim .v .count - 1
38
+ local formatted = false
12
39
13
- if table then
14
- return 0
40
+ for linenr = start_line , end_line do
41
+ local line_formatted = format_line (linenr )
42
+ formatted = formatted or line_formatted
15
43
end
16
44
17
- local line = vim .fn .line (' .' )
18
- local ok , item = pcall (Files .get_closest_headline , line )
19
- if ok and item and item .logbook and item .logbook .range :is_in_line_range (line ) then
20
- return item .logbook :recalculate_estimate (line )
45
+ if formatted then
46
+ return 0
21
47
end
22
48
23
49
return 1
0 commit comments