" Haredoc plugin -- Hare documentation in vim " Maintainer: Byron Torres " Last Updated: 2022-06-15 " License: Vim License command -nargs=? Haredoc :call Haredoc() function Haredoc(symbol) let symbol = a:symbol let popup = symbol == '.' if (symbol == '.' || symbol == ',') let oldiskeyword = &iskeyword setlocal iskeyword+=: let symbol = expand('') let &iskeyword = oldiskeyword " resolve possibly partial symbols (chrono::moment) if match(symbol, "::") != -1 let [parent, base] = split(symbol, "::")[-2:-1] " try joining symbol with a use statement. " example: 'use time::chrono' -> 'time::chrono::moment' let resolvecmd =<< trim eval CMD awk '/use [a-zA-Z:]*{parent};/ {{ gsub("(use *|;.*)", ""); print $1 "::" "{base}" }}' {expand("%")} 2>&- CMD let joined_symbol = system(join(resolvecmd)) if len(joined_symbol) != 0 let symbol = joined_symbol endif endif endif if popup && has('popupwin') && has('terminal') let minheight = 1 + system( \ "haredoc -Ftty '"..symbol.."' 2>&1 | wc -l" \ ) let buf = term_start( \ [ \ 'sh', '-c', \ "haredoc -Ftty '"..symbol.."' | less -RKX", \ ], \ #{hidden: 1, term_finish: 'close'}, \ ) let winid = popup_atcursor( \ buf, \ #{ \ col: 'cursor-'..virtcol('.'), \ minwidth: 84, \ minheight: minheight, \ fixed: v:false, \ wrap: v:false, \ border: [1, 1, 1, 1], \ }, \ ) elseif has('terminal') call term_start( \ [ \ 'sh', '-c', \ "haredoc -Ftty '"..symbol.."' | less -RKX", \ ], \ ) set nonumber filetype=hare nnoremap q :close nnoremap u nnoremap d else execute '!haredoc '..symbol endif endfunction