" 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 non-complete symbols (chrono::moment) if match(symbol, "::") != -1 && &buftype == '' let [submodule, ident] = split(symbol, "::")[-2:-1] " try joining symbol with a use statement. " example: 'use time::chrono' -> 'time::chrono::moment' let use = getline(search('^use *.*::'..submodule, 'bnw')) if use != '' let symbol = substitute( \ use, \ '\(use *\|;\)', \ '', \ 'g' \ )..'::'..ident endif endif endif if popup && has('popupwin') && has('terminal') let buf = term_start( \ [ \ 'sh', '-c', \ "haredoc -Ftty '"..symbol.."' | LESS= less -RKX", \ ], \ #{ \ term_name: '[haredoc] '..symbol, \ hidden: 1, \ term_finish: 'close', \ }, \ ) call setbufvar(buf, "&bufhidden", 'wipe') let minheight = 1 + system( \ "haredoc -Ftty '"..symbol.."' 2>&1 | wc -l" \ ) let winid = popup_atcursor( \ buf, \ #{ \ title: "[haredoc] "..symbol, \ 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", \ ], \ #{ \ term_name: '[haredoc] '..symbol, \ }, \ ) set nonumber filetype=hare bufhidden=wipe nnoremap q :close nnoremap u nnoremap d elseif has('nvim') split execute 'terminal haredoc '..symbol tnoremap q nnoremap q :close nnoremap u nnoremap d startinsert else execute '!haredoc '..symbol endif endfunction