File: hare.vim

package info (click to toggle)
vim 2%3A9.1.2141-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 95,004 kB
  • sloc: ansic: 433,946; cpp: 6,440; makefile: 4,625; sh: 2,397; java: 2,312; xml: 2,099; python: 1,619; perl: 1,419; awk: 730; lisp: 501; cs: 458; objc: 369; csh: 9; sed: 8; haskell: 1
file content (65 lines) | stat: -rw-r--r-- 1,672 bytes parent folder | download
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
vim9script

# Helper functions for Hare.
# Language:    Hare
# Maintainer:  Amelia Clarke <selene@perilune.dev>
# Last Change: 2026 Jan 24
# Upstream:    https://git.sr.ht/~sircmpwn/hare.vim

# Returns the value of $HAREPATH, if it exists. Otherwise, returns a safe
# default value.
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
  return map(path, (_, n) => escape(n, ' ,;'))->join(',')
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')
  endif

  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

# Attempts to parse a list of directories from the output of `hare version -v`.
# Otherwise, returns an empty list.
def ParsePath(): list<string>
  if !executable('hare')
    return []
  endif

  silent final lines = systemlist('hare version -v')
  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))
    ->map((_, n) => matchstr(n, '^\s*\zs.*'))
enddef

# vim: et sts=2 sw=2 ts=8 tw=80