Skip to content

Commit 6d68508

Browse files
selenebunchrisbra
authored andcommitted
runtime(hare): update for Hare 0.25.2
closes: #18222 Signed-off-by: Amelia Clarke <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent 6bb16d2 commit 6d68508

11 files changed

Lines changed: 847 additions & 398 deletions

File tree

runtime/autoload/dist/ft.vim

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ vim9script
33
# Vim functions for file type detection
44
#
55
# Maintainer: The Vim Project <https://github.com/vim/vim>
6-
# Last Change: 2025 Sep 04
6+
# Last Change: 2025 Sep 08
77
# Former Maintainer: Bram Moolenaar <[email protected]>
88

99
# These functions are moved here from runtime/filetype.vim to make startup
@@ -441,29 +441,29 @@ export def FTfs()
441441
endif
442442
enddef
443443

444-
# Recursively search for Hare source files in a directory and any
445-
# subdirectories, up to a given depth.
444+
# Recursively searches for Hare source files within a directory, up to a given
445+
# depth.
446446
def IsHareModule(dir: string, depth: number): bool
447-
if depth <= 0
448-
return !empty(glob(dir .. '/*.ha'))
447+
if depth < 1
448+
return false
449+
elseif depth == 1
450+
return !glob(dir .. '/*.ha')->empty()
449451
endif
450452

451-
return reduce(sort(glob(dir .. '/*', true, true),
452-
(a, b) => isdirectory(a) - isdirectory(b)),
453-
(acc, n) => acc
453+
# Check all files in the directory before recursing into subdirectories.
454+
return glob(dir .. '/*', true, true)
455+
->sort((a, b) => isdirectory(a) - isdirectory(b))
456+
->reduce((acc, n) => acc
454457
|| n =~ '\.ha$'
455-
|| isdirectory(n)
456-
&& IsHareModule(n, depth - 1),
458+
|| isdirectory(n) && IsHareModule(n, depth - 1),
457459
false)
458460
enddef
459461

460-
# Determine if a README file exists within a Hare module and should be given the
461-
# Haredoc filetype.
462+
# Determines whether a README file is inside a Hare module and should receive
463+
# the 'haredoc' filetype.
462464
export def FTharedoc()
463-
if exists('g:filetype_haredoc')
464-
if IsHareModule('<afile>:h', get(g:, 'haredoc_search_depth', 1))
465-
setf haredoc
466-
endif
465+
if IsHareModule('<afile>:h', get(g:, 'filetype_haredoc', 1))
466+
setf haredoc
467467
endif
468468
enddef
469469

runtime/autoload/hare.vim

Lines changed: 78 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,82 @@
1-
" Vim autoload file.
2-
" Language: Hare
3-
" Maintainer: Amelia Clarke <[email protected]>
4-
" Last Updated: 2024-05-10
5-
" Upstream: https://git.sr.ht/~sircmpwn/hare.vim
6-
7-
" Attempt to find the directory for a given Hare module.
8-
function hare#FindModule(str)
9-
let path = substitute(trim(a:str, ':', 2), '::', '/', 'g')
10-
let dir = finddir(path)
11-
while !empty(path) && empty(dir)
12-
let path = substitute(path, '/\?\h\w*$', '', '')
13-
let dir = finddir(path)
1+
vim9script
2+
3+
# Helper functions for Hare.
4+
# Language: Hare
5+
# Maintainer: Amelia Clarke <[email protected]>
6+
# Last Updated: 2025 Sep 06
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.
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 mapnew(path, (_, n) => escape(n, ' ,;'))->join(',')
22+
enddef
23+
24+
# Converts a module identifier into a path.
25+
export def IncludeExpr(): string
26+
var path = trim(v:fname, ':', 2)->substitute('::', '/', 'g')
27+
28+
# If the module cannot be found, it might be a member instead. Try removing
29+
# the final component until a directory is found.
30+
while !finddir(path)
31+
const head = fnamemodify(path, ':h')
32+
if head == '.'
33+
break
34+
endif
35+
path = head
1436
endwhile
15-
return dir
16-
endfunction
1737

18-
" Return the value of HAREPATH if it exists. Otherwise use a reasonable default.
19-
function hare#GetPath()
20-
if empty($HAREPATH)
21-
return '/usr/src/hare/stdlib,/usr/src/hare/third-party'
38+
return path
39+
enddef
40+
41+
# Modifies quickfix or location list entries to refer to the correct paths after
42+
# running :make or :lmake, respectively.
43+
export def QuickFixPaths()
44+
var GetList: func
45+
var SetList: func
46+
47+
if expand('<amatch>') =~ '^l'
48+
GetList = function('getloclist', [0])
49+
SetList = function('setloclist', [0])
50+
else
51+
GetList = function('getqflist')
52+
SetList = function('setqflist')
2253
endif
23-
return substitute($HAREPATH, ':', ',', 'g')
24-
endfunction
2554

26-
" vim: et sts=2 sw=2 ts=8
55+
final list = GetList({ items: 0 })
56+
for n in list.items
57+
if !empty(n.module)
58+
n.filename = findfile(n.module)
59+
endif
60+
endfor
61+
SetList([], 'r', list)
62+
enddef
63+
64+
# Attempts to parse the directories in $HAREPATH from the output of `hare
65+
# version -v`. Otherwise, returns an empty list.
66+
def ParsePath(): list<string>
67+
if !executable('hare')
68+
return []
69+
endif
70+
71+
silent const lines = systemlist('hare version -v')
72+
const min = match(lines, '^HAREPATH') + 1
73+
if min == 0
74+
return []
75+
endif
76+
77+
const max = match(lines, '^\S', min)
78+
return (max < 0 ? slice(lines, min) : slice(lines, min, max))
79+
->mapnew((_, n) => matchstr(n, '^\s*\zs.*'))
80+
enddef
81+
82+
# vim: et sts=2 sw=2 ts=8 tw=80

runtime/compiler/hare.vim

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
1-
" Vim compiler file.
2-
" Compiler: Hare
3-
" Maintainer: Amelia Clarke <[email protected]>
4-
" Last Change: 2024-05-23
5-
" Upstream: https://git.sr.ht/~sircmpwn/hare.vim
1+
vim9script
62

7-
if exists('current_compiler')
3+
# Vim compiler file.
4+
# Compiler: Hare
5+
# Maintainer: Amelia Clarke <[email protected]>
6+
# Last Change: 2025 Sep 06
7+
# Upstream: https://git.sr.ht/~sircmpwn/hare.vim
8+
9+
if exists('g:current_compiler')
810
finish
911
endif
10-
let current_compiler = 'hare'
11-
12-
let s:cpo_save = &cpo
13-
set cpo&vim
1412

1513
if filereadable('Makefile') || filereadable('makefile')
1614
CompilerSet makeprg=make
1715
else
18-
CompilerSet makeprg=hare\ build
16+
const makeprg = 'hare build '
17+
.. get(b:, 'hare_makeprg_params', get(g:, 'hare_makeprg_params', '-q'))
18+
execute 'CompilerSet makeprg=' .. escape(makeprg, ' "\|')
1919
endif
2020

2121
CompilerSet errorformat=
22-
\%f:%l:%c:\ syntax\ error:\ %m,
23-
\%f:%l:%c:\ error:\ %m,
22+
\%o:%l:%v:\ syntax\ error:\ %m,
23+
\%o:%l:%v:\ error:\ %m,
24+
\Error:\ %m,
2425
\%-G%.%#
2526

26-
let &cpo = s:cpo_save
27-
unlet s:cpo_save
27+
augroup HareQuickFix
28+
autocmd!
29+
autocmd QuickFixCmdPost make hare#QuickFixPaths()
30+
autocmd QuickFixCmdPost lmake hare#QuickFixPaths()
31+
augroup END
32+
33+
g:current_compiler = 'hare'
2834

29-
" vim: et sts=2 sw=2 ts=8
35+
# vim: et sts=2 sw=2 ts=8 tw=80

runtime/doc/ft_hare.txt

Lines changed: 106 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,134 @@
11
*ft_hare.txt* Support for the Hare programming language
22

33
==============================================================================
4-
CONTENTS *hare*
4+
CONTENTS *hare* *hare.vim*
55

6-
1. Introduction |hare-intro|
7-
2. Filetype plugin |hare-plugin|
8-
3. Settings |hare-settings|
6+
1. Introduction |ft-hare-intro|
7+
2. Filetype plugin |ft-hare-plugin|
8+
3. Haredoc filetype |ft-haredoc-plugin|
9+
4. Indentation settings |ft-hare-indent|
10+
5. Compiler support |compiler-hare|
911

1012
==============================================================================
11-
INTRODUCTION *hare-intro*
13+
INTRODUCTION *ft-hare-intro*
1214

13-
This plugin provides syntax highlighting, indentation, and other functionality
14-
for the Hare programming language. Support is also provided for README files
15-
inside Hare modules, but this must be enabled by setting |g:filetype_haredoc|.
15+
This plugin provides syntax highlighting, indentation, and other supporting
16+
functionality for the Hare programming language.
1617

17-
==============================================================================
18-
FILETYPE PLUGIN *hare-plugin*
1918

20-
This plugin automatically sets the value of 'path' to include the contents of
21-
the HAREPATH environment variable, allowing commands such as |gf| to directly
22-
open standard library or third-party modules. If HAREPATH is not set, it
23-
defaults to the recommended paths for most Unix-like filesystems, namely
24-
/usr/src/hare/stdlib and /usr/src/hare/third-party.
19+
FILETYPE PLUGIN *ft-hare-plugin*
2520

26-
==============================================================================
27-
SETTINGS *hare-settings*
21+
This plugin has a few different variables that can be defined inside your
22+
|vimrc| to tweak its behavior.
2823

29-
This plugin provides a small number of variables that you can define in your
30-
vimrc to configure its behavior.
24+
Additionally, support is provided for folding `{ }` blocks. To enable folding,
25+
add the following to a file inside your |after-directory| (e.g.
26+
~/.vim/after/ftplugin/hare.vim): >
3127
32-
*g:filetype_haredoc*
33-
This plugin is able to automatically detect Hare modules and set the "haredoc"
34-
filetype for any README files. As the recursive directory search used as a
35-
heuristic has a minor performance impact, this feature is disabled by default
36-
and must be specifically opted into: >
37-
let g:filetype_haredoc = 1
38-
<
39-
See |g:haredoc_search_depth| for ways to tweak the searching behavior.
28+
setlocal foldmethod=syntax
29+
30+
Because block-based folding tends to create many small folds, consider setting
31+
a few related options, such as 'foldminlines' and 'foldnestmax'.
4032

4133
*g:hare_recommended_style*
42-
The following options are set by default, in accordance with the official Hare
34+
The following options are set by default, in accordance with Hare's official
4335
style guide: >
36+
4437
setlocal noexpandtab
4538
setlocal shiftwidth=0
4639
setlocal softtabstop=0
4740
setlocal tabstop=8
4841
setlocal textwidth=80
49-
<
50-
To disable this behavior: >
42+
43+
To disable this behavior, add the following to your |vimrc|: >
44+
5145
let g:hare_recommended_style = 0
46+
<
47+
*g:hare_symbol_operators*
48+
By default, symbolic operators do not receive any special highlighting (with
49+
`!`, `?`, and `::` being the only exceptions). To enable syntax highlighting
50+
for most other operators, add the following to your |vimrc|: >
51+
52+
let g:hare_symbol_operators = 1
5253
<
5354
*g:hare_space_error*
54-
By default, trailing whitespace and tabs preceded by space characters are
55-
highlighted as errors. This is automatically turned off when in insert mode.
56-
To disable this highlighting completely: >
55+
By default, trailing whitespace and spaces followed by <Tab> characters will
56+
be highlighted as errors. This is automatically disabled in Insert mode. To
57+
turn off this highlighting completely, add the following to your |vimrc|: >
58+
5759
let g:hare_space_error = 0
58-
<
59-
*g:haredoc_search_depth*
60-
By default, when |g:filetype_haredoc| is enabled, only the current directory
61-
and its immediate subdirectories are searched for Hare files. The maximum
62-
search depth may be adjusted with: >
63-
let g:haredoc_search_depth = 2
64-
<
60+
61+
62+
HAREDOC FILETYPE *ft-haredoc-plugin*
63+
64+
This plugin will automatically detect README files inside Hare modules, using
65+
a recursive directory search, and give them the "haredoc" filetype. Because
66+
this is such a common filename, this plugin only searches for Hare source
67+
files within the same directory by default.
68+
69+
*g:filetype_haredoc*
70+
The |g:filetype_haredoc| variable can be used to tweak the depth of this
71+
search, or bypass the detection of Hare documentation files altogether:
72+
6573
Value Effect~
66-
0 Only search the current directory.
67-
1 Search the current directory and immediate
68-
subdirectories.
69-
2 Search the current directory and two levels of
70-
subdirectories.
74+
0 No automatic detection
75+
1 Search current directory only (this is the default)
76+
2 Search one level of subdirectories
77+
3 Search two levels of subdirectories
78+
79+
The search depth may be any positive integer, but values higher than `2` are
80+
unlikely to provide a tangible benefit in most situations.
81+
82+
83+
INDENTATION SETTINGS *ft-hare-indent*
84+
85+
Unlike most other settings for this plugin, the indentation settings may also
86+
be set per-buffer, overriding any global configuration that exists. To do
87+
this, simply prefix the variable with |b:| instead of |g:|.
88+
89+
*g:hare_indent_match_switch*
90+
By default, continuation lines for "match" and "switch" conditions are
91+
indented only one level: >hare
92+
93+
const file = match (os::create(path, 0o644,
94+
flag::WRONLY | flag::TRUNC)) {
95+
case let file: io::file =>
96+
yield file;
97+
// ...
98+
99+
If you instead prefer indenting them two levels, to more closely resemble "if"
100+
and "for" conditions, add the following line to your |vimrc|: >
101+
102+
let g:hare_indent_match_switch = 2
103+
<
104+
*g:hare_indent_case*
105+
By default, continuation lines for cases in "match" and "switch" expressions
106+
are indented two levels, to visually distinguish them from the body of the
107+
case: >hare
108+
109+
case ltok::I8, ltok::I16, ltok::I32,
110+
ltok::I64, ltok::INT =>
111+
// ...
112+
113+
If you prefer a different amount of indentation, you can adjust it using
114+
|g:hare_indent_case|. Valid values include `0`, `1`, and `2`.
115+
116+
117+
COMPILER SUPPORT *compiler-hare*
118+
119+
If this plugin detects a Makefile in the current directory, it will assume you
120+
wish to use `make` for your build system, and will leave 'makeprg' untouched.
121+
Otherwise, `hare build` will be used.
122+
123+
*g:hare_makeprg_params*
124+
When `hare build` is used, additional compiler options may be appended to
125+
'makeprg' with the |g:hare_makeprg_params| variable. It may also be set on a
126+
per-buffer basis (using |b:| instead of |g:|), overriding any global
127+
configuration that exists. For example: >
128+
129+
let b:hare_makeprg_params = '-lc -t o'
71130
72-
The maximum search depth can be set to any integer, but using values higher
73-
than 2 is not recommended, and will likely provide no tangible benefit in most
74-
situations.
131+
The global default is "-q", to suppress writing to stdout while building.
75132

76133
==============================================================================
77-
vim:tw=78:ts=8:noet:ft=help:norl:
134+
vim:ft=help:noet:ts=8:tw=78:norl:

0 commit comments

Comments
 (0)