@@ -240,9 +240,10 @@ function Headline:set_tags(tags)
240
240
return nil
241
241
end
242
242
243
+ local bufnr = self .file :get_valid_bufnr ()
243
244
local txt = self .file :get_node_text (predecessor )
244
245
local pred_end_row , pred_end_col , _ = predecessor :end_ ()
245
- local line = vim .fn . getline ( pred_end_row + 1 )
246
+ local line = vim .api . nvim_buf_get_lines ( bufnr , pred_end_row , pred_end_row + 1 , false )[ 1 ]
246
247
local stars = line :match (' ^%*+%s*' )
247
248
local end_col = line :len ()
248
249
@@ -261,7 +262,7 @@ function Headline:set_tags(tags)
261
262
text = string.rep (' ' , spaces ) .. tags
262
263
end
263
264
264
- vim .api .nvim_buf_set_text (0 , pred_end_row , pred_end_col , pred_end_row , end_col , { text })
265
+ vim .api .nvim_buf_set_text (bufnr , pred_end_row , pred_end_col , pred_end_row , end_col , { text })
265
266
end
266
267
267
268
function Headline :align_tags ()
@@ -389,10 +390,11 @@ end
389
390
--- @param value ? string
390
391
--- @return OrgHeadline
391
392
function Headline :set_property (name , value )
393
+ local bufnr = self .file :get_valid_bufnr ()
392
394
if not value then
393
395
local existing_property , property_node = self :get_property (name )
394
396
if existing_property and property_node then
395
- vim .fn .deletebufline (vim . api . nvim_get_current_buf () , property_node :start () + 1 )
397
+ vim .fn .deletebufline (bufnr , property_node :start () + 1 )
396
398
end
397
399
self :refresh ()
398
400
local properties_node , properties = self :get_properties ()
@@ -406,7 +408,7 @@ function Headline:set_property(name, value)
406
408
if not properties then
407
409
local append_line = self :get_append_line ()
408
410
local property_drawer = self :_apply_indent ({ ' :PROPERTIES:' , ' :END:' }) --[[ @as string[] ]]
409
- vim .api .nvim_buf_set_lines (0 , append_line , append_line , false , property_drawer )
411
+ vim .api .nvim_buf_set_lines (bufnr , append_line , append_line , false , property_drawer )
410
412
properties = self :refresh ():get_properties ()
411
413
end
412
414
@@ -418,7 +420,7 @@ function Headline:set_property(name, value)
418
420
local property_end = properties and properties :end_ ()
419
421
420
422
local new_line = self :_apply_indent (property ) --[[ @as string]]
421
- vim .api .nvim_buf_set_lines (0 , property_end - 1 , property_end - 1 , false , { new_line })
423
+ vim .api .nvim_buf_set_lines (bufnr , property_end - 1 , property_end - 1 , false , { new_line })
422
424
return self :refresh ()
423
425
end
424
426
@@ -824,9 +826,10 @@ function Headline:get_drawer_append_line(name)
824
826
local drawer = self :get_drawer (name )
825
827
826
828
if not drawer then
829
+ local bufnr = self .file :get_valid_bufnr ()
827
830
local append_line = self :get_append_line ()
828
831
local new_drawer = self :_apply_indent ({ ' :' .. name .. ' :' , ' :END:' }) --[[ @as string[] ]]
829
- vim .api .nvim_buf_set_lines (0 , append_line , append_line , false , new_drawer )
832
+ vim .api .nvim_buf_set_lines (bufnr , append_line , append_line , false , new_drawer )
830
833
drawer = self :get_drawer (name )
831
834
end
832
835
local name_row = drawer and drawer :field (' name' )[1 ]:end_ () or 0
@@ -880,7 +883,7 @@ function Headline:_add_date(type, date, active)
880
883
local text = type .. ' : ' .. date :to_wrapped_string (active )
881
884
if not has_plan_dates then
882
885
local start_line = self :node ():start ()
883
- vim .fn .append ( start_line + 1 , self :_apply_indent (text ))
886
+ vim .fn .appendbufline ( self . file : get_valid_bufnr (), start_line + 1 , self :_apply_indent (text ) --[[ @as string ]] )
884
887
return self :refresh ()
885
888
end
886
889
if date_nodes [type ] then
@@ -909,10 +912,12 @@ function Headline:_remove_date(type)
909
912
if vim .tbl_count (date_nodes ) == 0 or not date_nodes [type ] then
910
913
return
911
914
end
912
- local line_nr = date_nodes [type ]:start () + 1
915
+ local line_nr = date_nodes [type ]:start ()
913
916
self .file :set_node_text (date_nodes [type ], ' ' , true )
914
- if vim .trim (vim .fn .getline (line_nr )) == ' ' then
915
- vim .fn .deletebufline (vim .api .nvim_get_current_buf (), line_nr )
917
+ local bufnr = self .file :get_valid_bufnr ()
918
+ local cur_line = vim .api .nvim_buf_get_lines (bufnr , line_nr , line_nr + 1 , false )[1 ]
919
+ if vim .trim (cur_line ) == ' ' then
920
+ vim .fn .deletebufline (bufnr , line_nr + 1 )
916
921
end
917
922
return self :refresh ()
918
923
end
@@ -1005,11 +1010,12 @@ function Headline:_handle_promote_demote(recursive, modifier, dryRun)
1005
1010
1006
1011
local start = self :node ():start ()
1007
1012
local end_line = first_child_section :start ()
1008
- local lines = modifier (start , vim .api .nvim_buf_get_lines (0 , start , end_line , false ))
1013
+ local bufnr = self .file :get_valid_bufnr ()
1014
+ local lines = modifier (start , vim .api .nvim_buf_get_lines (bufnr , start , end_line , false ))
1009
1015
if dryRun then
1010
1016
return lines
1011
1017
end
1012
- vim .api .nvim_buf_set_lines (0 , start , end_line , false , lines )
1018
+ vim .api .nvim_buf_set_lines (bufnr , start , end_line , false , lines )
1013
1019
return self :refresh ()
1014
1020
end
1015
1021
0 commit comments