• R/O
  • SSH

vim: Commit

Mirror of the Vim source from https://github.com/vim/vim


Commit MetaInfo

Revisionc2a3b642d4cb2ae7c6591bf932eca3339ce316da (tree)
Time2024-01-17 01:45:03
AuthorChristian Brabandt <cb@256b...>
CommiterChristian Brabandt

Log Message

runtime(odin): include ftplugin, syntax and indent script (#13867)

Commit: https://github.com/vim/vim/commit/211211052d0426394cbd5f42f3f3f78a64822e2a
Author: Maxim Kim <habamax@gmail.com>
Date: Wed Jan 17 03:33:51 2024 +1100

runtime(odin): include ftplugin, syntax and indent script (https://github.com/vim/vim/issues/13867)
Note for Neovim Contributors: this is bundled as Vim9 Script. If you want to use this on Neovim, you need to convert the Vim9 scripts to Vim Script or Lua or leave it out.
Signed-off-by: Maxim Kim <habamax@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>

Change Summary

Incremental Difference

diff -r ecd5d60298df -r c2a3b642d4cb runtime/ftplugin/odin.vim
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/runtime/ftplugin/odin.vim Tue Jan 16 17:45:03 2024 +0100
@@ -0,0 +1,20 @@
1+vim9script
2+
3+# Vim filetype plugin file
4+# Language: Odin
5+# Maintainer: Maxim Kim <habamax@gmail.com>
6+# Website: https://github.com/habamax/vim-odin
7+# Last Change: 2024-01-15
8+
9+if exists("b:did_ftplugin")
10+ finish
11+endif
12+b:did_ftplugin = 1
13+
14+b:undo_ftplugin = 'setlocal commentstring<'
15+ \ .. '| setlocal comments<'
16+ \ .. '| setlocal suffixesadd<'
17+
18+setlocal suffixesadd=.odin
19+setlocal commentstring=//%s
20+setlocal comments=s1:/*,mb:*,ex:*/,://
diff -r ecd5d60298df -r c2a3b642d4cb runtime/indent/odin.vim
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/runtime/indent/odin.vim Tue Jan 16 17:45:03 2024 +0100
@@ -0,0 +1,119 @@
1+vim9script
2+
3+# Vim indent plugin file
4+# Language: Odin
5+# Maintainer: Maxim Kim <habamax@gmail.com>
6+# Website: https://github.com/habamax/vim-odin
7+# Last Change: 2024-01-15
8+
9+if exists("b:did_indent")
10+ finish
11+endif
12+b:did_indent = 1
13+
14+b:undo_indent = 'setlocal cindent< cinoptions< cinkeys< indentexpr<'
15+
16+setlocal cindent
17+setlocal cinoptions=L0,m1,(s,j1,J1,l1,+0,:0,#1
18+setlocal cinkeys=0{,0},0),0],!^F,:,o,O
19+
20+setlocal indentexpr=GetOdinIndent(v:lnum)
21+
22+def PrevLine(lnum: number): number
23+ var plnum = lnum - 1
24+ var pline: string
25+ while plnum > 1
26+ plnum = prevnonblank(plnum)
27+ pline = getline(plnum)
28+ # XXX: take into account nested multiline /* /* */ */ comments
29+ if pline =~ '\*/\s*$'
30+ while getline(plnum) !~ '/\*' && plnum > 1
31+ plnum -= 1
32+ endwhile
33+ if getline(plnum) =~ '^\s*/\*'
34+ plnum -= 1
35+ else
36+ break
37+ endif
38+ elseif pline =~ '^\s*//'
39+ plnum -= 1
40+ else
41+ break
42+ endif
43+ endwhile
44+ return plnum
45+enddef
46+
47+def GetOdinIndent(lnum: number): number
48+ var plnum = PrevLine(lnum)
49+ var pline = getline(plnum)
50+ var pindent = indent(plnum)
51+ # workaround of cindent "hang"
52+ # if the previous line looks like:
53+ # : #{}
54+ # : #whatever{whateverelse}
55+ # and variations where : # { } are in the string
56+ # cindent(lnum) hangs
57+ if pline =~ ':\s\+#.*{.*}'
58+ return pindent
59+ endif
60+
61+ var indent = cindent(lnum)
62+ var line = getline(lnum)
63+
64+ if line =~ '^\s*#\k\+'
65+ if pline =~ '[{:]\s*$'
66+ indent = pindent + shiftwidth()
67+ else
68+ indent = pindent
69+ endif
70+ elseif pline =~ 'switch\s.*{\s*$'
71+ indent = pindent
72+ elseif pline =~ 'case\s*.*,\s*\(//.*\)\?$' # https://github.com/habamax/vim-odin/issues/8
73+ indent = pindent + matchstr(pline, 'case\s*')->strcharlen()
74+ elseif line =~ '^\s*case\s\+.*,\s*$'
75+ indent = pindent - shiftwidth()
76+ elseif pline =~ 'case\s*.*:\s*\(//.*\)\?$'
77+ if line !~ '^\s*}\s*$' && line !~ '^\s*case[[:space:]:]'
78+ indent = pindent + shiftwidth()
79+ endif
80+ elseif pline =~ '^\s*@.*' && line !~ '^\s*}'
81+ indent = pindent
82+ elseif pline =~ ':[:=].*}\s*$'
83+ indent = pindent
84+ elseif pline =~ '^\s*}\s*$'
85+ if line !~ '^\s*}' && line !~ 'case\s*.*:\s*$'
86+ indent = pindent
87+ else
88+ indent = pindent - shiftwidth()
89+ endif
90+ elseif pline =~ '\S:\s*$'
91+ # looking up for a case something,
92+ # whatever,
93+ # anything:
94+ # ... 20 lines before
95+ for idx in range(plnum - 1, plnum - 21, -1)
96+ if plnum < 1
97+ break
98+ endif
99+ if getline(idx) =~ '^\s*case\s.*,\s*$'
100+ indent = indent(idx) + shiftwidth()
101+ break
102+ endif
103+ endfor
104+ elseif pline =~ '{[^{]*}\s*$' && line !~ '^\s*[})]\s*$' # https://github.com/habamax/vim-odin/issues/2
105+ indent = pindent
106+ elseif pline =~ '^\s*}\s*$' # https://github.com/habamax/vim-odin/issues/3
107+ # Find line with opening { and check if there is a label:
108+ # If there is, return indent of the closing }
109+ cursor(plnum, 1)
110+ silent normal! %
111+ var brlnum = line('.')
112+ var brline = getline('.')
113+ if plnum != brlnum && (brline =~ '^\s*\k\+:\s\+for' || brline =~ '^\s*\k\+\s*:=')
114+ indent = pindent
115+ endif
116+ endif
117+
118+ return indent
119+enddef
diff -r ecd5d60298df -r c2a3b642d4cb runtime/syntax/odin.vim
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/runtime/syntax/odin.vim Tue Jan 16 17:45:03 2024 +0100
@@ -0,0 +1,103 @@
1+vim9script
2+
3+# Vim indent plugin file
4+# Language: Odin
5+# Maintainer: Maxim Kim <habamax@gmail.com>
6+# Website: https://github.com/habamax/vim-odin
7+# Last Change: 2024-01-15
8+
9+if exists("b:current_syntax")
10+ finish
11+endif
12+
13+syntax keyword odinKeyword using transmute cast distinct opaque where dynamic
14+syntax keyword odinKeyword struct enum union const bit_field bit_set
15+syntax keyword odinKeyword package proc map import export foreign
16+syntax keyword odinKeyword size_of offset_of type_info_of typeid_of type_of align_of
17+syntax keyword odinKeyword return defer
18+syntax keyword odinKeyword or_return or_else
19+syntax keyword odinKeyword inline no_inline
20+
21+syntax keyword odinConditional if when else do for switch case continue break
22+syntax keyword odinType string cstring bool b8 b16 b32 b64 rune any rawptr
23+syntax keyword odinType f16 f32 f64 f16le f16be f32le f32be f64le f64be
24+syntax keyword odinType u8 u16 u32 u64 u128 u16le u32le u64le u128le u16be
25+syntax keyword odinType u32be u64be u128be uint uintptr i8 i16 i32 i64 i128
26+syntax keyword odinType i16le i32le i64le i128le i16be i32be i64be i128be
27+syntax keyword odinType int complex complex32 complex64 complex128 matrix typeid
28+syntax keyword odinType quaternion quaternion64 quaternion128 quaternion256
29+syntax keyword odinBool true false
30+syntax keyword odinNull nil
31+syntax match odinUninitialized '\s\+---\(\s\|$\)'
32+
33+syntax keyword odinOperator in notin not_in
34+syntax match odinOperator "?" display
35+syntax match odinOperator "->" display
36+
37+syntax match odinTodo "TODO" contained
38+syntax match odinTodo "XXX" contained
39+syntax match odinTodo "FIXME" contained
40+syntax match odinTodo "HACK" contained
41+
42+syntax region odinRawString start=+`+ end=+`+
43+syntax region odinChar start=+'+ skip=+\\\\\|\\'+ end=+'+
44+syntax region odinString start=+"+ skip=+\\\\\|\\'+ end=+"+ contains=odinEscape
45+syntax match odinEscape display contained /\\\([nrt\\'"]\|x\x\{2}\)/
46+
47+syntax match odinProcedure "\v<\w*>(\s*::\s*proc)@="
48+
49+syntax match odinAttribute "@\ze\<\w\+\>" display
50+syntax region odinAttribute
51+ \ matchgroup=odinAttribute
52+ \ start="@\ze(" end="\ze)"
53+ \ transparent oneline
54+
55+syntax match odinInteger "\-\?\<\d\+\>" display
56+syntax match odinFloat "\-\?\<[0-9][0-9_]*\%(\.[0-9][0-9_]*\)\%([eE][+-]\=[0-9_]\+\)\=" display
57+syntax match odinHex "\<0[xX][0-9A-Fa-f]\+\>" display
58+syntax match odinDoz "\<0[zZ][0-9a-bA-B]\+\>" display
59+syntax match odinOct "\<0[oO][0-7]\+\>" display
60+syntax match odinBin "\<0[bB][01]\+\>" display
61+
62+syntax match odinAddressOf "&" display
63+syntax match odinDeref "\^" display
64+
65+syntax match odinMacro "#\<\w\+\>" display
66+
67+syntax match odinTemplate "$\<\w\+\>"
68+
69+syntax region odinLineComment start=/\/\// end=/$/ contains=@Spell,odinTodo
70+syntax region odinBlockComment start=/\/\*/ end=/\*\// contains=@Spell,odinTodo,odinBlockComment
71+syn sync ccomment odinBlockComment
72+
73+highlight def link odinKeyword Statement
74+highlight def link odinConditional Conditional
75+highlight def link odinOperator Operator
76+
77+highlight def link odinString String
78+highlight def link odinRawString String
79+highlight def link odinChar Character
80+highlight def link odinEscape Special
81+
82+highlight def link odinProcedure Function
83+
84+highlight def link odinMacro PreProc
85+
86+highlight def link odinLineComment Comment
87+highlight def link odinBlockComment Comment
88+
89+highlight def link odinTodo Todo
90+
91+highlight def link odinAttribute Statement
92+highlight def link odinType Type
93+highlight def link odinBool Boolean
94+highlight def link odinNull Constant
95+highlight def link odinUninitialized Constant
96+highlight def link odinInteger Number
97+highlight def link odinFloat Float
98+highlight def link odinHex Number
99+highlight def link odinOct Number
100+highlight def link odinBin Number
101+highlight def link odinDoz Number
102+
103+b:current_syntax = "odin"
Show on old repository browser