robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1-- Highlighting 2local ns =vim . api . nvim_create_namespace ( 'nvim.pack.confirm' ) 3vim . api . nvim_buf_clear_namespace ( 0 , ns , 0 , - 1 ) 4 5local priority =100 6 7--- @param lnum integer 8--- @param start_col integer 9--- @param end_col integer 10--- @param hl string? 11--- @param pr? integer 12local function hi_range ( lnum , start_col , end_col , hl , pr ) 13vim . api . nvim_buf_set_extmark ( 0 , ns , lnum - 1 , start_col , { 14end_row =lnum - 1 , 15end_col =end_col , 16hl_group =hl , 17priority =pr or priority , 18-- Set expanding gravity for easier testing. Should not make big difference. 19right_gravity =false , 20end_right_gravity =true , 21} ) 22end 23 24local header_hl_groups = 25{ Error ='DiagnosticError' , Update ='DiagnosticWarn' , Same ='DiagnosticHint' } 26local cur_header_hl_group --- @type string? 27 28local lines =vim . api . nvim_buf_get_lines ( 0 , 0 , - 1 , false ) 29for i , l in ipairs ( lines ) do 30local cur_group =l : match ( '^# (%S+)' ) 31local cur_info =l : match ( '^Path: +' ) or l : match ( '^Source: +' ) or l : match ( '^Revision[^:]*: +' ) 32if cur_group ~= nil then 33--- @cast cur_group string 34-- Header 1 35cur_header_hl_group =header_hl_groups [ cur_group ] 36hi_range ( i , 0 , l : len (), cur_header_hl_group ) 37elseif l : find ( '^## (.+)$' ) ~= nil then 38-- Header 2 with possibly "(not active)" suffix 39hi_range ( i , 0 , l : len (), cur_header_hl_group ) 40local col =( l : match ( '() %(not active%)$' ) or l : len ()) --[[@as integer]] 41hi_range ( i , col , l : len (), 'DiagnosticError' , priority + 1 ) 42elseif cur_info ~= nil then 43-- Plugin info 44local end_col =( l : match ( '(). +%b()$' ) or l : len ()) --[[@as integer]] 45hi_range ( i , cur_info : len (), end_col , 'DiagnosticInfo' ) 46 47-- Plugin version after update 48local col =l : match ( '() %b()$' ) --[[@as integer?]] 49if col then 50hi_range ( i , col , l : len (), 'DiagnosticHint' ) 51end 52elseif l : match ( '^> ' ) then 53-- Added change with possibly "breaking message" 54hi_range ( i , 0 , l : len (), 'Added' ) 55local col =( l : match ( '│() %S+!:' ) or l : match ( '│() %S+%b()!:' ) or l : len ()) --[[@as integer]] 56hi_range ( i , col , l : len (), 'DiagnosticWarn' , priority + 1 ) 57elseif l : match ( '^< ' ) then 58-- Removed change 59hi_range ( i , 0 , l : len (), 'Removed' ) 60elseif l : match ( '^• ' ) then 61-- Available newer tags 62hi_range ( i , 4 , l : len (), 'DiagnosticHint' ) 63end 64end 65 66--- Mappings 67--- @param lhs string 68--- @param search_flags string 69--- @param desc string 70local function map_section_jump ( lhs , search_flags , desc ) 71vim . keymap . set ( { 'n' , 'x' } , lhs , function () 72for _ =1 , vim . v . count1 do 73vim . fn . search ( '^## ' , search_flags ) 74end 75end , { buf =0 , desc =desc } ) 76end 77 78map_section_jump ( '[[' , 'bsW' , 'Previous plugin' ) 79map_section_jump ( ']]' , 'sW' , 'Next plugin' )