aboutsummaryrefslogtreecommitdiff
path: root/ftplugin/hare.vim
blob: 9a8be3cbca9bfd9c7371943c52fb84b7a5eedfbc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
" Haredoc plugin -- Hare documentation in vim
" Maintainer: Byron Torres <b@torresjrjr.com>
" Last Updated: 2022-05-22
" License: Vim License

set keywordprg=haredoc
nnoremap K  :call Haredoc('.')<CR>
command -nargs=? Haredoc  :call Haredoc(<q-args>)
function Haredoc(symbol)
	let symbol = a:symbol
	let popup = 0
	if symbol == '.'
		let popup = 1
		let oldiskeyword = &iskeyword
		setlocal iskeyword+=:
		let symbol = expand('<cword>')
		let &iskeyword = oldiskeyword
	endif
	if has('terminal') && has('popupwin') && popup == 1
		let minheight = 1 + system(
		\	"haredoc -Ftty '"..symbol.."' 2>&1 | wc -l"
		\ )
		let buf = term_start(
		\	[
		\		'sh', '-c',
		\		"haredoc -Ftty '"..symbol.."' 2>&1 | less -RK",
		\	],
		\	#{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')
		execute 'terminal ++noclose haredoc '..symbol
		set nonumber
		nnoremap <buffer> q  :close<CR>
	else
		execute '!haredoc '..symbol
	endif
endfunction