@@ -294,9 +294,59 @@ parts.indent = function (buffer, _, config)
294294 vim .fn .getbufline (buffer , vim .v .foldstart )
295295 );
296296
297- return {
298- { line :match (" ^(%s*)" ), config .hl }
299- };
297+ if vim .o .list == false then
298+ return {
299+ { line :match (" ^(%s*)" ), config .hl }
300+ };
301+ end
302+
303+ local listchars = vim .o .listchars ;
304+
305+ local tabchar = string.match (listchars , " tab:([^,]*)" );
306+ local spacechar = string.match (listchars , " space:([^,]*)" );
307+ local multispacechar = string.match (listchars , " multispace:([^,]*)" );
308+
309+ local space_segment = multispacechar and string.rep (" " , vim .fn .strchars (multispacechar )) or nil ;
310+
311+ local output = {};
312+ --- @type string
313+ local indent = line :match (" ^(%s*)" );
314+
315+ while # indent > 0 do
316+ if space_segment and string.match (indent , " ^" .. space_segment ) then
317+ table.insert (output , {
318+ multispacechar ,
319+ config .hl or " LineNr"
320+ });
321+ indent = string.gsub (indent , " ^" .. space_segment , " " );
322+ elseif tabchar and string.match (indent , " ^\t " ) then
323+ local tab_width = vim .fn .strdisplaywidth (" \t " );
324+
325+ indent = string.gsub (indent , " ^\t " , " " );
326+ table.insert (output , {
327+ tabchar .. string.rep (" " , tab_width - vim .fn .strdisplaywidth (tabchar )),
328+ config .hl or " LineNr"
329+ });
330+ else
331+ local segment = string.match (indent , " ^%s" );
332+
333+ if spacechar then
334+ table.insert (output , {
335+ string.rep (spacechar , vim .fn .strchars (segment )),
336+ config .hl or " LineNr"
337+ });
338+ else
339+ table.insert (output , {
340+ segment ,
341+ config .hl or " LineNr"
342+ });
343+ end
344+
345+ indent = string.gsub (indent , " ^%s" , " " );
346+ end
347+ end
348+
349+ return output ;
300350
301351 --- | fE
302352end
0 commit comments