raku.vim 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. " Vim indent file
  2. " Language: Perl 6
  3. " Maintainer: vim-perl <vim-perl@googlegroups.com>
  4. " Homepage: https://github.com/vim-perl/vim-perl
  5. " Bugs/requests: https://github.com/vim-perl/vim-perl/issues
  6. " Last Change: 2020 Apr 15
  7. " Contributors: Andy Lester <andy@petdance.com>
  8. " Hinrik Örn Sigurðsson <hinrik.sig@gmail.com>
  9. "
  10. " Adapted from indent/perl.vim by Rafael Garcia-Suarez <rgarciasuarez@free.fr>
  11. " Suggestions and improvements by :
  12. " Aaron J. Sherman (use syntax for hints)
  13. " Artem Chuprina (play nice with folding)
  14. " TODO:
  15. " This file still relies on stuff from the Perl 5 syntax file, which Perl 6
  16. " does not use.
  17. "
  18. " Things that are not or not properly indented (yet) :
  19. " - Continued statements
  20. " print "foo",
  21. " "bar";
  22. " print "foo"
  23. " if bar();
  24. " - Multiline regular expressions (m//x)
  25. " (The following probably needs modifying the perl syntax file)
  26. " - qw() lists
  27. " - Heredocs with terminators that don't match \I\i*
  28. " Only load this indent file when no other was loaded.
  29. if exists("b:did_indent")
  30. finish
  31. endif
  32. let b:did_indent = 1
  33. " Is syntax highlighting active ?
  34. let b:indent_use_syntax = has("syntax")
  35. setlocal indentexpr=GetRakuIndent()
  36. " we reset it first because the Perl 5 indent file might have been loaded due
  37. " to a .pl/pm file extension, and indent files don't clean up afterwards
  38. setlocal indentkeys&
  39. setlocal indentkeys+=0=,0),0],0>,0»,0=or,0=and
  40. if !b:indent_use_syntax
  41. setlocal indentkeys+=0=EO
  42. endif
  43. let s:cpo_save = &cpo
  44. set cpo-=C
  45. function! GetRakuIndent()
  46. " Get the line to be indented
  47. let cline = getline(v:lnum)
  48. " Indent POD markers to column 0
  49. if cline =~ '^\s*=\L\@!'
  50. return 0
  51. endif
  52. " Get current syntax item at the line's first char
  53. let csynid = ''
  54. if b:indent_use_syntax
  55. let csynid = synIDattr(synID(v:lnum,1,0),"name")
  56. endif
  57. " Don't reindent POD and heredocs
  58. if csynid =~ "^rakuPod"
  59. return indent(v:lnum)
  60. endif
  61. " Now get the indent of the previous perl line.
  62. " Find a non-blank line above the current line.
  63. let lnum = prevnonblank(v:lnum - 1)
  64. " Hit the start of the file, use zero indent.
  65. if lnum == 0
  66. return 0
  67. endif
  68. let line = getline(lnum)
  69. let ind = indent(lnum)
  70. " Skip heredocs, POD, and comments on 1st column
  71. if b:indent_use_syntax
  72. let skippin = 2
  73. while skippin
  74. let synid = synIDattr(synID(lnum,1,0),"name")
  75. if (synid =~ "^rakuPod" || synid =~ "rakuComment")
  76. let lnum = prevnonblank(lnum - 1)
  77. if lnum == 0
  78. return 0
  79. endif
  80. let line = getline(lnum)
  81. let ind = indent(lnum)
  82. let skippin = 1
  83. else
  84. let skippin = 0
  85. endif
  86. endwhile
  87. endif
  88. if line =~ '[<«\[{(]\s*\(#[^)}\]»>]*\)\=$'
  89. let ind = ind + &sw
  90. endif
  91. if cline =~ '^\s*[)}\]»>]'
  92. let ind = ind - &sw
  93. endif
  94. " Indent lines that begin with 'or' or 'and'
  95. if cline =~ '^\s*\(or\|and\)\>'
  96. if line !~ '^\s*\(or\|and\)\>'
  97. let ind = ind + &sw
  98. endif
  99. elseif line =~ '^\s*\(or\|and\)\>'
  100. let ind = ind - &sw
  101. endif
  102. return ind
  103. endfunction
  104. let &cpo = s:cpo_save
  105. unlet s:cpo_save
  106. " vim:ts=8:sts=4:sw=4:expandtab:ft=vim