@@ -240,9 +240,10 @@ function Headline:set_tags(tags)
240240 return nil
241241 end
242242
243+ local bufnr = self .file :get_valid_bufnr ()
243244 local txt = self .file :get_node_text (predecessor )
244245 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 ]
246247 local stars = line :match (' ^%*+%s*' )
247248 local end_col = line :len ()
248249
@@ -261,7 +262,7 @@ function Headline:set_tags(tags)
261262 text = string.rep (' ' , spaces ) .. tags
262263 end
263264
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 })
265266end
266267
267268function Headline :align_tags ()
@@ -389,10 +390,11 @@ end
389390--- @param value ? string
390391--- @return OrgHeadline
391392function Headline :set_property (name , value )
393+ local bufnr = self .file :get_valid_bufnr ()
392394 if not value then
393395 local existing_property , property_node = self :get_property (name )
394396 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 )
396398 end
397399 self :refresh ()
398400 local properties_node , properties = self :get_properties ()
@@ -406,7 +408,7 @@ function Headline:set_property(name, value)
406408 if not properties then
407409 local append_line = self :get_append_line ()
408410 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 )
410412 properties = self :refresh ():get_properties ()
411413 end
412414
@@ -418,7 +420,7 @@ function Headline:set_property(name, value)
418420 local property_end = properties and properties :end_ ()
419421
420422 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 })
422424 return self :refresh ()
423425end
424426
@@ -824,9 +826,10 @@ function Headline:get_drawer_append_line(name)
824826 local drawer = self :get_drawer (name )
825827
826828 if not drawer then
829+ local bufnr = self .file :get_valid_bufnr ()
827830 local append_line = self :get_append_line ()
828831 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 )
830833 drawer = self :get_drawer (name )
831834 end
832835 local name_row = drawer and drawer :field (' name' )[1 ]:end_ () or 0
@@ -880,7 +883,7 @@ function Headline:_add_date(type, date, active)
880883 local text = type .. ' : ' .. date :to_wrapped_string (active )
881884 if not has_plan_dates then
882885 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 ]] )
884887 return self :refresh ()
885888 end
886889 if date_nodes [type ] then
@@ -909,10 +912,12 @@ function Headline:_remove_date(type)
909912 if vim .tbl_count (date_nodes ) == 0 or not date_nodes [type ] then
910913 return
911914 end
912- local line_nr = date_nodes [type ]:start () + 1
915+ local line_nr = date_nodes [type ]:start ()
913916 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 )
916921 end
917922 return self :refresh ()
918923end
@@ -1005,11 +1010,12 @@ function Headline:_handle_promote_demote(recursive, modifier, dryRun)
10051010
10061011 local start = self :node ():start ()
10071012 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 ))
10091015 if dryRun then
10101016 return lines
10111017 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 )
10131019 return self :refresh ()
10141020end
10151021
0 commit comments