mojo.vim 1.2 KB

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