blob: c7f3b6b41e4d7aca73bada066e0da2c0d4c0c0cb [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
Eisuke Kawashimafbbaa6e2025-04-16 18:20:59 +02005" 2025 Apr 16 by Vim Project (set 'cpoptions' for line continuation, #17121)
Riley Bruinsfc533c92024-07-11 22:50:36 +02006
7if exists('b:did_ftplugin')
8 finish
9endif
10let b:did_ftplugin = 1
11
Eisuke Kawashimafbbaa6e2025-04-16 18:20:59 +020012let s:cpo_save = &cpo
13set cpo&vim
14
Riley Bruinsfc533c92024-07-11 22:50:36 +020015setlocal include=^\\s*\\(from\\\|import\\)
16setlocal define=^\\s*\\(\\(async\\s\\+\\)\\?def\\\|class\\)
17
18" For imports with leading .., append / and replace additional .s with ../
19let b:grandparent_match = '^\(.\.\)\(\.*\)'
20let b:grandparent_sub = '\=submatch(1)."/".repeat("../",strlen(submatch(2)))'
21
22" For imports with a single leading ., replace it with ./
23let b:parent_match = '^\.\(\.\)\@!'
24let b:parent_sub = './'
25
26" Replace any . sandwiched between word characters with /
27let b:child_match = '\(\w\)\.\(\w\)'
28let b:child_sub = '\1/\2'
29
30setlocal includeexpr=substitute(substitute(substitute(
31 \v:fname,
32 \b:grandparent_match,b:grandparent_sub,''),
33 \b:parent_match,b:parent_sub,''),
34 \b:child_match,b:child_sub,'g')
35
36setlocal suffixesadd=.mojo
37setlocal comments=b:#,fb:-
38setlocal commentstring=#\ %s
39
40let b:undo_ftplugin = 'setlocal include<'
41 \ . '|setlocal define<'
42 \ . '|setlocal includeexpr<'
43 \ . '|setlocal suffixesadd<'
44 \ . '|setlocal comments<'
45 \ . '|setlocal commentstring<'
Eisuke Kawashimafbbaa6e2025-04-16 18:20:59 +020046
47let &cpo = s:cpo_save
48unlet s:cpo_save