robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
8a79e3398a
master
1" Vim filetype plugin file 2" Language: Julia 3" Maintainer: Carlo Baldassi <carlobaldassi@gmail.com> 4" Homepage: https://github.com/JuliaEditorSupport/julia-vim 5" Last Change: 2021 Aug 04 6" 2026 Feb 27 sync with upstream repo 7 8if exists ( "b:did_ftplugin" ) 9finish 10endif 11let b: did_ftplugin = 1 12 13let s: save_cpo = & cpo 14set cpo & vim 15 16setlocal include = ^\\s*\\%(reload\\\|include\\)\\> 17setlocal suffixesadd = .jl 18setlocal comments = :# 19setlocal commentstring = #\ %s 20setlocal cinoptions += #1 21setlocal define = ^\\s*macro\\> 22setlocal fo -= tfo += croql 23 24let b: julia_vim_loaded = 1 25 26let b: undo_ftplugin = "setlocal include< suffixesadd< comments< commentstring<" 27 \. " define< fo< cinoptions< completefunc<" 28 \. " | unlet! b:julia_vim_loaded" 29 30" MatchIt plugin support 31if exists ( "loaded_matchit" ) 32let b: match_ignorecase = 0 33 34" note: begin_keywords must contain all blocks, in order 35" for nested-structures-skipping to work properly 36" note: 'mutable struct' and 'struct' are defined separately because 37" using \? puts the cursor on 'struct' instead of 'mutable' for some reason 38let b: julia_begin_keywords = '\%(\.\s*\|@\)\@<!\<\%(function\|macro\|begin\|mutable\s\+struct\|\%(mutable\s\+\)\@<!struct\|\%(abstract\|primitive\)\s\+type\|let\|do\|\%(bare\)\?module\|quote\|if\|for\|while\|try\)\>' 39" note: the following regex not only recognizes macros, but also local/global keywords. 40" the purpose is recognizing things like `@inline myfunction()` 41" or `global myfunction(...)` etc, for matchit and block movement functionality 42let s: macro_regex = '\%(@\%([#(]\@!\S\)\+\|\<\%(local\|global\)\)\s\+' 43let s: nomacro = '\%(' . s: macro_regex . '\)\@<!' 44let s: yesmacro = s: nomacro . '\%(' . s: macro_regex . '\)\+' 45let b: julia_begin_keywordsm = '\%(' . s: yesmacro . b: julia_begin_keywords . '\)\|' 46 \. '\%(' . s: nomacro . b: julia_begin_keywords . '\)' 47let b: julia_end_keywords = '\<end\>' 48 49" note: this function relies heavily on the syntax file 50function ! JuliaGetMatchWords () 51let [ l , c ] = [ line ( '.' ), col ( '.' )] 52let attr = synIDattr ( synID ( l , c , 1 ), "name" ) 53let c1 = c 54while attr == 'juliaMacro' || expand ( '<cword>' ) =~# '\<\%(global\|local\)\>' 55normal ! W 56if line ( '.' ) > l || col ( '.' ) == c1 57call cursor ( l , c ) 58return '' 59endif 60let attr = synIDattr ( synID ( l , col ( '.' ), 1 ), "name" ) 61let c1 = col ( '.' ) 62endwhile 63call cursor ( l , c ) 64if attr == 'juliaConditional' 65return b: julia_begin_keywordsm . ':\<\%(elseif\|else\)\>:' . b: julia_end_keywords 66elseif attr =~# '\<\%(juliaRepeat\|juliaRepKeyword\)\>' 67return b: julia_begin_keywordsm . ':\<\%(break\|continue\)\>:' . b: julia_end_keywords 68elseif attr == 'juliaBlKeyword' 69return b: julia_begin_keywordsm . ':' . b: julia_end_keywords 70elseif attr == 'juliaException' 71return b: julia_begin_keywordsm . ':\<\%(catch\|else\|finally\)\>:' . b: julia_end_keywords 72endif 73return '\<\>:\<\>' 74endfunction 75 76let b: match_words = 'JuliaGetMatchWords()' 77 78" we need to skip everything within comments, strings and 79" the 'begin' and 'end' keywords when they are used as a range rather than as 80" the delimiter of a block 81let b: match_skip = 'synIDattr(synID(line("."),col("."),0),"name") =~# ' 82 \. '"\\<julia\\%(Comprehension\\%(For\\|If\\)\\|RangeKeyword\\|Comment\\%([LM]\\|Delim\\)\\|\\%([bs]\\|Shell\\|Printf\\|Doc\\)\\?String\\|StringPrefixed\\|DocStringM\\(Raw\\)\\?\\|RegEx\\|SymbolS\\?\\|Dotted\\)\\>"' 83 84let b: undo_ftplugin = b: undo_ftplugin 85 \. " | unlet! b:match_words b:match_skip b:match_ignorecase" 86 \. " | unlet! b:julia_begin_keywords b:julia_end_keywords" 87 \. " | delfunction JuliaGetMatchWords" 88 89endif 90 91let & cpo = s: save_cpo 92unlet s: save_cpo