@@ -87,11 +87,11 @@ function Headline:promote(amount, recursive, dryRun)
87
87
if line :sub (1 , 1 ) == ' *' then
88
88
lines [i ] = line :sub (1 + amount )
89
89
elseif vim .trim (line :sub (1 , amount )) == ' ' then
90
- if config . org_adapt_indentation then
90
+ if config : should_indent ( self . file : bufnr ()) then
91
91
lines [i ] = line :sub (1 + amount )
92
92
else
93
93
line , _ = line :gsub (' ^%s+' , ' ' )
94
- local indent_amount = indent .indentexpr (start_line + i )
94
+ local indent_amount = indent .indentexpr (start_line + i , self . file : bufnr () )
95
95
lines [i ] = string.rep (' ' , indent_amount ) .. line
96
96
end
97
97
end
@@ -113,11 +113,11 @@ function Headline:demote(amount, recursive, dryRun)
113
113
if line :sub (1 , 1 ) == ' *' then
114
114
lines [i ] = string.rep (' *' , amount ) .. line
115
115
else
116
- if config . org_adapt_indentation then
117
- lines [i ] = config : apply_indent (line , amount )
116
+ if config : should_indent ( self . file : bufnr ()) then
117
+ lines [i ] = self : _apply_indent (line , amount )
118
118
else
119
119
line , _ = line :gsub (' ^%s+' , ' ' )
120
- local indent_amount = indent .indentexpr (start_line + i )
120
+ local indent_amount = indent .indentexpr (start_line + i , self . file : bufnr () )
121
121
lines [i ] = string.rep (' ' , indent_amount ) .. line
122
122
end
123
123
end
@@ -384,7 +384,7 @@ function Headline:set_property(name, value)
384
384
local properties = self :get_properties ()
385
385
if not properties then
386
386
local append_line = self :get_append_line ()
387
- local property_drawer = self :_apply_indent ({ ' :PROPERTIES:' , ' :END:' })
387
+ local property_drawer = self :_apply_indent ({ ' :PROPERTIES:' , ' :END:' }) --[[ @as string[] ]]
388
388
vim .api .nvim_buf_set_lines (0 , append_line , append_line , false , property_drawer )
389
389
properties = self :refresh ():get_properties ()
390
390
end
@@ -395,7 +395,9 @@ function Headline:set_property(name, value)
395
395
return self :_set_node_text (property_node , property )
396
396
end
397
397
local property_end = properties and properties :end_ ()
398
- vim .api .nvim_buf_set_lines (0 , property_end - 1 , property_end - 1 , false , self :_apply_indent (property ))
398
+
399
+ local new_line = self :_apply_indent (property ) --[[ @as string]]
400
+ vim .api .nvim_buf_set_lines (0 , property_end - 1 , property_end - 1 , false , { new_line })
399
401
return self :refresh ()
400
402
end
401
403
@@ -782,7 +784,7 @@ function Headline:get_drawer_append_line(name)
782
784
783
785
if not drawer then
784
786
local append_line = self :get_append_line ()
785
- local new_drawer = self :_apply_indent ({ ' :' .. name .. ' :' , ' :END:' })
787
+ local new_drawer = self :_apply_indent ({ ' :' .. name .. ' :' , ' :END:' }) --[[ @as string[] ]]
786
788
vim .api .nvim_buf_set_lines (0 , append_line , append_line , false , new_drawer )
787
789
drawer = self :get_drawer (name )
788
790
end
@@ -806,6 +808,12 @@ function Headline:get_headline_line_content()
806
808
return line
807
809
end
808
810
811
+ --- @param amount ? number
812
+ --- @return string
813
+ function Headline :get_indent (amount )
814
+ return config :get_indent (amount or self :get_level () + 1 , self .file :bufnr ())
815
+ end
816
+
809
817
function Headline :is_same (other_headline )
810
818
return self .file .filename == other_headline .filename
811
819
and self :get_headline_line_content () == other_headline :get_headline_line_content ()
@@ -829,9 +837,8 @@ function Headline:_add_date(type, date, active)
829
837
local _ , date_nodes , has_plan_dates = self :get_plan_dates ()
830
838
local text = type .. ' : ' .. date :to_wrapped_string (active )
831
839
if not has_plan_dates then
832
- local indentation = config :get_indent (self :get_level () + 1 )
833
840
local start_line = self :node ():start ()
834
- vim .fn .append (start_line + 1 , ( ' %s%s ' ): format ( indentation , text ))
841
+ vim .fn .append (start_line + 1 , self : _apply_indent ( text ))
835
842
return self :refresh ()
836
843
end
837
844
if date_nodes [type ] then
@@ -869,13 +876,23 @@ function Headline:_remove_date(type)
869
876
end
870
877
871
878
--- @param text string[] | string
872
- --- @return string[]
873
- function Headline :_apply_indent (text )
874
- local indented = config :apply_indent (text , self :get_level () + 1 )
875
- if type (indented ) == ' string' then
876
- return { indented }
879
+ --- @param amount ? number
880
+ function Headline :_apply_indent (text , amount )
881
+ local indent_text = self :get_indent (amount )
882
+
883
+ if indent_text == ' ' then
884
+ return text
877
885
end
878
- return indented
886
+
887
+ if type (text ) ~= ' table' then
888
+ return indent_text .. text
889
+ end
890
+
891
+ for i , line in ipairs (text ) do
892
+ text [i ] = indent_text .. line
893
+ end
894
+
895
+ return text
879
896
end
880
897
881
898
function Headline :_get_child_node (name )
0 commit comments