raku.vim 3.4 KB

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