@@ -101,17 +101,16 @@ local colorize_ls_long = function(bufnr, data, sections)
101101 local section = sections [lnum ]
102102 for i = 1 , section [1 ].end_index - 1 do -- Highlight permissions
103103 local c = line :sub (i , i )
104- vim .api . nvim_buf_add_highlight (bufnr , ns_previewer , color_hash [c ], lnum - 1 , i - 1 , i )
104+ vim .hl . range (bufnr , ns_previewer , color_hash [c ], { lnum - 1 , i - 1 }, { lnum - 1 , i } )
105105 end
106106 for i = 2 , # section do -- highlights size, (user, group), date and name
107107 local hl_group = color_hash [i + (i ~= 2 and windows_add or 0 )]
108- vim .api . nvim_buf_add_highlight (
108+ vim .hl . range (
109109 bufnr ,
110110 ns_previewer ,
111111 type (hl_group ) == " function" and hl_group (line ) or hl_group ,
112- lnum - 1 ,
113- section [i ].start_index - 1 ,
114- section [i ].end_index - 1
112+ { lnum - 1 , section [i ].start_index - 1 },
113+ { lnum - 1 , section [i ].end_index - 1 }
115114 )
116115 end
117116 end
@@ -133,7 +132,7 @@ local handle_directory_preview = function(filepath, bufnr, opts)
133132 vim .api .nvim_buf_set_lines (bufnr , 0 , - 1 , false , paths )
134133 for i , path in ipairs (paths ) do
135134 local hl = color_hash [6 ](data [i ])
136- vim .api . nvim_buf_add_highlight (bufnr , ns_previewer , hl , i - 1 , 0 , # path )
135+ vim .hl . range (bufnr , ns_previewer , hl , { i - 1 , 0 }, { i - 1 , # path } )
137136 end
138137 end
139138 else
@@ -531,13 +530,12 @@ previewers.vimgrep = defaulter(function(opts)
531530
532531 for i = lnum , lnend do
533532 pcall (
534- vim .api . nvim_buf_add_highlight ,
533+ vim .hl . range ,
535534 bufnr ,
536535 ns_previewer ,
537536 " TelescopePreviewLine" ,
538- i ,
539- i == lnum and col or 0 ,
540- i == lnend and colend or - 1
537+ { i , i == lnum and col or 0 },
538+ { i , i == lnend and colend or - 1 }
541539 )
542540 end
543541
@@ -623,7 +621,7 @@ previewers.ctags = defaulter(function(opts)
623621 if self .state .last_set_bufnr then
624622 pcall (vim .api .nvim_buf_clear_namespace , self .state .last_set_bufnr , ns_previewer , 0 , - 1 )
625623 end
626- pcall (vim .api . nvim_buf_add_highlight , bufnr , ns_previewer , " TelescopePreviewMatch" , entry .lnum - 1 , 0 , - 1 )
624+ pcall (vim .hl . range , bufnr , ns_previewer , " TelescopePreviewMatch" , { entry .lnum - 1 , 0 }, { entry . lnum - 1 , - 1 } )
627625 pcall (vim .api .nvim_win_set_cursor , self .state .winid , { entry .lnum , 0 })
628626 self .state .last_set_bufnr = bufnr
629627 end
@@ -750,43 +748,19 @@ previewers.git_branch_log = defaulter(function(opts)
750748 local hstart , hend = line :find " [0-9a-fA-F]+"
751749 if hstart then
752750 if hend < # line then
753- pcall (
754- vim .api .nvim_buf_add_highlight ,
755- bufnr ,
756- ns_previewer ,
757- " TelescopeResultsIdentifier" ,
758- i - 1 ,
759- hstart - 1 ,
760- hend
761- )
751+ pcall (vim .hl .range , bufnr , ns_previewer , " TelescopeResultsIdentifier" , { i - 1 , hstart - 1 }, { i - 1 , hend })
762752 end
763753 end
764754 local _ , cstart = line :find " - %("
765755 if cstart then
766756 local cend = string.find (line , " %) " )
767757 if cend then
768- pcall (
769- vim .api .nvim_buf_add_highlight ,
770- bufnr ,
771- ns_previewer ,
772- " TelescopeResultsConstant" ,
773- i - 1 ,
774- cstart - 1 ,
775- cend
776- )
758+ pcall (vim .hl .range , bufnr , ns_previewer , " TelescopeResultsConstant" , { i - 1 , cstart - 1 }, { i - 1 , cend })
777759 end
778760 end
779761 local dstart , _ = line :find " %(%d"
780762 if dstart then
781- pcall (
782- vim .api .nvim_buf_add_highlight ,
783- bufnr ,
784- ns_previewer ,
785- " TelescopeResultsSpecialComment" ,
786- i - 1 ,
787- dstart ,
788- # line
789- )
763+ pcall (vim .hl .range , bufnr , ns_previewer , " TelescopeResultsSpecialComment" , { i - 1 , dstart }, { # line })
790764 end
791765 end
792766 end
@@ -965,7 +939,7 @@ previewers.git_commit_message = defaulter(function(opts)
965939 for k , v in ipairs (hl_map ) do
966940 local _ , s = content [k ]:find " %s"
967941 if s then
968- vim .api . nvim_buf_add_highlight (bufnr , ns_previewer , v , k - 1 , s , # content [k ])
942+ vim .hl . range (bufnr , ns_previewer , v , { k - 1 , s }, { k - 1 , # content [k ] } )
969943 end
970944 end
971945 end ,
@@ -1054,7 +1028,7 @@ previewers.autocommands = defaulter(function(_)
10541028
10551029 vim .api .nvim_buf_set_option (self .state .bufnr , " filetype" , " vim" )
10561030 vim .api .nvim_buf_set_lines (self .state .bufnr , 0 , - 1 , false , display )
1057- vim .api . nvim_buf_add_highlight (self .state .bufnr , 0 , " TelescopeBorder" , 1 , 0 , - 1 )
1031+ vim .hl . range (self .state .bufnr , 0 , " TelescopeBorder" , { 1 , 0 }, { 1 , - 1 } )
10581032 else
10591033 for idx , item in ipairs (results ) do
10601034 if item == entry then
@@ -1064,7 +1038,13 @@ previewers.autocommands = defaulter(function(_)
10641038 end
10651039 end
10661040
1067- vim .api .nvim_buf_add_highlight (self .state .bufnr , ns_previewer , " TelescopePreviewLine" , selected_row + 1 , 0 , - 1 )
1041+ vim .hl .range (
1042+ self .state .bufnr ,
1043+ ns_previewer ,
1044+ " TelescopePreviewLine" ,
1045+ { selected_row + 1 , 0 },
1046+ { selected_row + 1 , - 1 }
1047+ )
10681048 -- set the cursor position after self.state.bufnr is connected to the
10691049 -- preview window (which is scheduled in new_buffer_previewer)
10701050 vim .schedule (function ()
@@ -1109,7 +1089,7 @@ previewers.highlights = defaulter(function(_)
11091089 local startPos = string.find (v , " xxx" , 1 , true ) - 1
11101090 local endPos = startPos + 3
11111091 local hlgroup = string.match (v , " ([^ ]*)%s+.*" )
1112- pcall (vim .api . nvim_buf_add_highlight , self .state .bufnr , 0 , hlgroup , k - 1 , startPos , endPos )
1092+ pcall (vim .hl . range , self .state .bufnr , 0 , hlgroup , { k - 1 , startPos }, { k - 1 , endPos } )
11131093 end
11141094 end
11151095
@@ -1120,13 +1100,12 @@ previewers.highlights = defaulter(function(_)
11201100 local lnum = vim .api .nvim_win_get_cursor (self .state .winid )[1 ]
11211101 -- That one is actually a match but its better to use it like that then matchadd
11221102 pcall (vim .api .nvim_buf_clear_namespace , self .state .bufnr , ns_previewer , 0 , - 1 )
1123- vim .api . nvim_buf_add_highlight (
1103+ vim .hl . range (
11241104 self .state .bufnr ,
11251105 ns_previewer ,
11261106 " TelescopePreviewMatch" ,
1127- lnum - 1 ,
1128- 0 ,
1129- # entry .value
1107+ { lnum - 1 , 0 },
1108+ { lnum - 1 , # entry .value }
11301109 )
11311110 -- we need to zz after the highlighting otherwise highlighting doesnt work
11321111 vim .cmd " norm! zz"
@@ -1194,24 +1173,22 @@ previewers.pickers = defaulter(function(_)
11941173
11951174 if display_highlight ~= nil then
11961175 for _ , hl_block in ipairs (display_highlight ) do
1197- vim .api . nvim_buf_add_highlight (
1176+ vim .hl . range (
11981177 self .state .bufnr ,
11991178 ns_telescope_entry ,
12001179 hl_block [2 ],
1201- row ,
1202- hl_block [1 ][1 ],
1203- hl_block [1 ][2 ]
1180+ { row , hl_block [1 ][1 ] },
1181+ { row , hl_block [1 ][2 ] }
12041182 )
12051183 end
12061184 end
12071185 if picker ._multi :is_selected (e ) then
1208- vim .api . nvim_buf_add_highlight (
1186+ vim .hl . range (
12091187 self .state .bufnr ,
12101188 ns_telescope_multiselection ,
12111189 " TelescopeMultiSelection" ,
1212- row ,
1213- 0 ,
1214- - 1
1190+ { row , 0 },
1191+ { row , - 1 }
12151192 )
12161193 end
12171194 end
0 commit comments