robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqMerge pull request #40472 from zeertzjq/vim-1f337327945732ed7

master
2.2 KiB73 linesraw
1" Vim filetype plugin file
2" Language: gdscript (Godot game engine scripting language)
3" Maintainer: Maxim Kim <habamax@gmail.com>
4" Website: https://github.com/habamax/vim-gdscript
5"
6" This file has been manually translated from Vim9 script.
7
8if exists("b:did_ftplugin") | finish | endif
9
10let s:save_cpo = &cpo
11set cpo&vim
12
13let b:did_ftplugin = 1
14let b:undo_ftplugin = 'setlocal cinkeys<'
15      \ .. '| setlocal indentkeys<'
16      \ .. '| setlocal commentstring<'
17      \ .. '| setlocal suffixesadd<'
18      \ .. '| setlocal foldexpr<'
19      \ .. '| setlocal foldignore<'
20
21setlocal cinkeys-=0#
22setlocal indentkeys-=0#
23setlocal suffixesadd=.gd
24setlocal commentstring=#\ %s
25setlocal foldignore=
26setlocal foldexpr=s:GDScriptFoldLevel()
27
28if get(g:, 'gdscript_recommended_style', get(g:, 'filetype_recommended_style', 1))
29    setlocal noexpandtab tabstop=4 softtabstop=0 shiftwidth=0
30    let b:undo_ftplugin ..= ' | setlocal expandtab< tabstop< softtabstop< shiftwidth<'
31endif
32
33
34function s:GDScriptFoldLevel() abort
35    let line = getline(v:lnum)
36    if line =~? '^\s*$'
37        return "-1"
38    endif
39
40    let sw = shiftwidth()
41    let indent = indent(v:lnum) / sw
42    let indent_next = indent(nextnonblank(v:lnum + 1)) / sw
43
44    if indent_next > indent && line =~# ':\s*$'
45        return $">{indent_next}"
46    else
47        return $"{indent}"
48    endif
49endfunction
50
51
52if !exists("g:no_plugin_maps")
53    " Next/Previous section
54    function s:NextSection(back, cnt) abort
55        for n in range(a:cnt)
56            call search('^\s*func\s', a:back ? 'bW' : 'W')
57        endfor
58    endfunction
59
60    " Nvim: <scriptcmd> hasn't been ported yet.
61    " nnoremap <silent><buffer> ]] <scriptcmd>NextSection(false, v:count1)<CR>
62    " nnoremap <silent><buffer> [[ <scriptcmd>NextSection(true, v:count1)<CR>
63    nnoremap <silent><buffer> ]] <Cmd>call <SID>NextSection(v:false, v:count1)<CR>
64    nnoremap <silent><buffer> [[ <Cmd>call <SID>NextSection(v:true, v:count1)<CR>
65    xmap <buffer><expr> ]] $'<C-\><C-N>{v:count1}]]m>gv'
66    xmap <buffer><expr> [[ $'<C-\><C-N>{v:count1}[[m>gv'
67    let b:undo_ftplugin ..=
68          \    " | silent exe 'unmap <buffer> [['"
69          \ .. " | silent exe 'unmap <buffer> ]]'"
70endif
71
72let &cpo = s:save_cpo
73unlet s:save_cpo