Files
org-vim/runtime/autoload/hare.vim
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

66 lines
1.6 KiB
VimL
Raw Normal View History

2025-09-08 15:30:41 -04:00
vim9script
# Helper functions for Hare.
2026-02-06 09:44:16 +00:00
# Language: Hare
# Maintainer: Amelia Clarke <selene@perilune.dev>
# Last Change: 2026 Jan 24
# Upstream: https://git.sr.ht/~sircmpwn/hare.vim
2025-09-08 15:30:41 -04:00
2026-02-06 09:44:16 +00:00
# Returns the value of $HAREPATH, if it exists. Otherwise, returns a safe
# default value.
2025-09-08 15:30:41 -04:00
export def GetPath(): string
var path: list<string>
if !empty($HAREPATH)
path = split($HAREPATH, ':')
else
path = ParsePath()
if empty(path)
return '/usr/src/hare/stdlib,/usr/src/hare/third-party'
endif
endif
2026-02-06 09:44:16 +00:00
return map(path, (_, n) => escape(n, ' ,;'))->join(',')
2025-09-08 15:30:41 -04:00
enddef
# Modifies quickfix or location list entries to refer to the correct paths after
# running :make or :lmake, respectively.
export def QuickFixPaths()
var GetList: func
var SetList: func
if expand('<amatch>') =~ '^l'
GetList = function('getloclist', [0])
SetList = function('setloclist', [0])
else
GetList = function('getqflist')
SetList = function('setqflist')
2024-05-24 08:05:00 +02:00
endif
2025-09-08 15:30:41 -04:00
final list = GetList({ items: 0 })
for n in list.items
if !empty(n.module)
n.filename = findfile(n.module)
endif
endfor
SetList([], 'r', list)
enddef
2026-02-06 09:44:16 +00:00
# Attempts to parse a list of directories from the output of `hare version -v`.
# Otherwise, returns an empty list.
2025-09-08 15:30:41 -04:00
def ParsePath(): list<string>
if !executable('hare')
return []
endif
2026-02-06 09:44:16 +00:00
silent final lines = systemlist('hare version -v')
2025-09-08 15:30:41 -04:00
const min = match(lines, '^HAREPATH') + 1
if min == 0
return []
endif
const max = match(lines, '^\S', min)
return (max < 0 ? slice(lines, min) : slice(lines, min, max))
2026-02-06 09:44:16 +00:00
->map((_, n) => matchstr(n, '^\s*\zs.*'))
2025-09-08 15:30:41 -04:00
enddef
# vim: et sts=2 sw=2 ts=8 tw=80