blob: ff502299341525efc4ddb3720f5e1bafb457707e [file] [log] [blame]
Riley Bruinsfc533c92024-07-11 22:50:36 +02001" Vim filetype plugin
2" Language: Mojo
3" Maintainer: Riley Bruins <ribru17@gmail.com>
4" Last Change: 2024 Jul 07
5
6if exists('b:did_ftplugin')
7 finish
8endif
9let b:did_ftplugin = 1
10
11setlocal include=^\\s*\\(from\\\|import\\)
12setlocal define=^\\s*\\(\\(async\\s\\+\\)\\?def\\\|class\\)
13
14" For imports with leading .., append / and replace additional .s with ../
15let b:grandparent_match = '^\(.\.\)\(\.*\)'
16let b:grandparent_sub = '\=submatch(1)."/".repeat("../",strlen(submatch(2)))'
17
18" For imports with a single leading ., replace it with ./
19let b:parent_match = '^\.\(\.\)\@!'
20let b:parent_sub = './'
21
22" Replace any . sandwiched between word characters with /
23let b:child_match = '\(\w\)\.\(\w\)'
24let b:child_sub = '\1/\2'
25
26setlocal includeexpr=substitute(substitute(substitute(
27 \v:fname,
28 \b:grandparent_match,b:grandparent_sub,''),
29 \b:parent_match,b:parent_sub,''),
30 \b:child_match,b:child_sub,'g')
31
32setlocal suffixesadd=.mojo
33setlocal comments=b:#,fb:-
34setlocal commentstring=#\ %s
35
36let b:undo_ftplugin = 'setlocal include<'
37 \ . '|setlocal define<'
38 \ . '|setlocal includeexpr<'
39 \ . '|setlocal suffixesadd<'
40 \ . '|setlocal comments<'
41 \ . '|setlocal commentstring<'