vim

Fork of vim, an acceptable text editor
git clone git://git.laack.co/vim.git
Log | Files | Refs | README | LICENSE

hare.vim (1672B)


      1 vim9script
      2 
      3 # Helper functions for Hare.
      4 # Language:    Hare
      5 # Maintainer:  Amelia Clarke <selene@perilune.dev>
      6 # Last Change: 2026 Jan 24
      7 # Upstream:    https://git.sr.ht/~sircmpwn/hare.vim
      8 
      9 # Returns the value of $HAREPATH, if it exists. Otherwise, returns a safe
     10 # default value.
     11 export def GetPath(): string
     12   var path: list<string>
     13   if !empty($HAREPATH)
     14     path = split($HAREPATH, ':')
     15   else
     16     path = ParsePath()
     17     if empty(path)
     18       return '/usr/src/hare/stdlib,/usr/src/hare/third-party'
     19     endif
     20   endif
     21   return map(path, (_, n) => escape(n, ' ,;'))->join(',')
     22 enddef
     23 
     24 # Modifies quickfix or location list entries to refer to the correct paths after
     25 # running :make or :lmake, respectively.
     26 export def QuickFixPaths()
     27   var GetList: func
     28   var SetList: func
     29 
     30   if expand('<amatch>') =~ '^l'
     31     GetList = function('getloclist', [0])
     32     SetList = function('setloclist', [0])
     33   else
     34     GetList = function('getqflist')
     35     SetList = function('setqflist')
     36   endif
     37 
     38   final list = GetList({ items: 0 })
     39   for n in list.items
     40     if !empty(n.module)
     41       n.filename = findfile(n.module)
     42     endif
     43   endfor
     44   SetList([], 'r', list)
     45 enddef
     46 
     47 # Attempts to parse a list of directories from the output of `hare version -v`.
     48 # Otherwise, returns an empty list.
     49 def ParsePath(): list<string>
     50   if !executable('hare')
     51     return []
     52   endif
     53 
     54   silent final lines = systemlist('hare version -v')
     55   const min = match(lines, '^HAREPATH') + 1
     56   if min == 0
     57     return []
     58   endif
     59 
     60   const max = match(lines, '^\S', min)
     61   return (max < 0 ? slice(lines, min) : slice(lines, min, max))
     62     ->map((_, n) => matchstr(n, '^\s*\zs.*'))
     63 enddef
     64 
     65 # vim: et sts=2 sw=2 ts=8 tw=80