diff options
author | Adam Stankiewicz <sheerun@sher.pl> | 2020-09-10 16:38:32 +0200 |
---|---|---|
committer | Adam Stankiewicz <sheerun@sher.pl> | 2020-09-10 16:38:32 +0200 |
commit | 05ff14bfdaeca8def902c644d119f3946009bf14 (patch) | |
tree | e6e9dbb371a1e4ecf4d4f72e05589248f82494ae | |
parent | 9243367ba376050621e4c05e8f0439742c1f0f82 (diff) | |
download | vim-polyglot-05ff14bfdaeca8def902c644d119f3946009bf14.tar.gz vim-polyglot-05ff14bfdaeca8def902c644d119f3946009bf14.zip |
Add odin support, closes #544
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | README.md | 3 | ||||
-rw-r--r-- | autoload/polyglot.vim | 36 | ||||
-rw-r--r-- | autoload/sleuth.vim | 1 | ||||
-rw-r--r-- | ftdetect/polyglot.vim | 4 | ||||
-rw-r--r-- | indent/odin.vim | 41 | ||||
-rw-r--r-- | packages.yaml | 6 | ||||
-rwxr-xr-x | scripts/build | 59 | ||||
-rw-r--r-- | scripts/test_filetypes.vim | 1 | ||||
-rw-r--r-- | syntax/odin.vim | 170 |
10 files changed, 263 insertions, 60 deletions
@@ -7,4 +7,4 @@ test: @ scripts/test dev: - @ (ls && find scripts) | DEV=1 entr bash -c 'make && make test' + @ echo "packages.yaml\nheuristics.yaml\nscripts/test\nscripts/build\nscripts/test_extensions.vim" | DEV=1 entr bash -c 'make && make test' @@ -7,7 +7,7 @@ A collection of language packs for Vim. > One to rule them all, one to find them, one to bring them all and in the darkness bind them. - It **won't affect your startup time**, as scripts are loaded only on demand\*. -- It **installs and updates 120+ times faster** than the <!--Package Count-->195<!--/Package Count--> packages it consists of. +- It **installs and updates 120+ times faster** than the <!--Package Count-->196<!--/Package Count--> packages it consists of. - It is more secure because scripts loaded for all extensions are generated by vim-polyglot (ftdetect). - Solid syntax and indentation support (other features skipped). Only the best language packs. - All unnecessary files are ignored (like enormous documentation from php support). @@ -169,6 +169,7 @@ If you need full functionality of any plugin, please use it directly with your p - [objc](https://github.com/b4winckler/vim-objc) - [ocaml](https://github.com/rgrinberg/vim-ocaml) - [octave](https://github.com/McSinyx/vim-octave) +- [odin](https://github.com/Tetralux/odin.vim) - [opencl](https://github.com/petRUShka/vim-opencl) - [perl](https://github.com/vim-perl/vim-perl) - [pgsql](https://github.com/lifepillar/pgsql.vim) diff --git a/autoload/polyglot.vim b/autoload/polyglot.vim index d89108aa..bc8791f5 100644 --- a/autoload/polyglot.vim +++ b/autoload/polyglot.vim @@ -4,9 +4,9 @@ set cpo&vim func! polyglot#Heuristics() " Try to detect filetype from shebang - let filetype = polyglot#Shebang() - if filetype != "" - exec "setf " . filetype + let l:filetype = polyglot#Shebang() + if l:filetype != "" + exec "setf " . l:filetype return 1 endif @@ -88,41 +88,37 @@ let s:r_envflag = '%(\S\+=\S\+\|-[iS]\|--ignore-environment\|--split-string\)' let s:r_env = '^\%(\' . s:r_envflag . '\s\+\)*\(\S\+\)' func! polyglot#Shebang() - let line1 = getline(1) + let l:line1 = getline(1) - if line1 !~# "^#!" + if l:line1 !~# "^#!" return endif - let pathrest = matchlist(line1, s:r_hashbang) + let l:pathrest = matchlist(l:line1, s:r_hashbang) - if len(pathrest) == 0 + if len(l:pathrest) == 0 return endif - let [_, path, rest; __] = pathrest + let [_, l:path, l:rest; __] = l:pathrest - let script = split(path, "/")[-1] + let l:script = split(l:path, "/")[-1] - if len(script) == 0 - return - endif - - if script == "env" - let argspath = matchlist(rest, s:r_env) - if len(argspath) == 0 + if l:script == "env" + let l:argspath = matchlist(l:rest, s:r_env) + if len(l:argspath) == 0 return endif - let script = argspath[1] + let l:script = l:argspath[1] endif - if has_key(s:interpreters, script) - return s:interpreters[script] + if has_key(s:interpreters, l:script) + return s:interpreters[l:script] endif for interpreter in keys(s:interpreters) - if script =~# '^' . interpreter + if l:script =~# '^' . interpreter return s:interpreters[interpreter] endif endfor diff --git a/autoload/sleuth.vim b/autoload/sleuth.vim index 81974413..05459ccd 100644 --- a/autoload/sleuth.vim +++ b/autoload/sleuth.vim @@ -144,6 +144,7 @@ let s:globs = { \ 'ocpbuild': '*.ocp', \ 'ocpbuildroot': '*.root', \ 'octave': '*.oct,*.m', + \ 'odin': '*.odin', \ 'omake': '*.om,OMakefile,OMakeroot,OMakeroot.in', \ 'opam': '*.opam,*.opam.template,opam', \ 'opencl': '*.cl,*.opencl', diff --git a/ftdetect/polyglot.vim b/ftdetect/polyglot.vim index 0fa71e9c..ab7e639b 100644 --- a/ftdetect/polyglot.vim +++ b/ftdetect/polyglot.vim @@ -1908,6 +1908,10 @@ if !has_key(s:disabled_packages, 'dosini') au BufNewFile,BufRead php.ini-* call s:StarSetf('dosini') endif +if !has_key(s:disabled_packages, 'odin') + au BufNewFile,BufRead *.odin setf odin +endif + " end filetypes diff --git a/indent/odin.vim b/indent/odin.vim new file mode 100644 index 00000000..b00b5387 --- /dev/null +++ b/indent/odin.vim @@ -0,0 +1,41 @@ +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'odin') == -1 + +if exists("b:did_indent") + finish +endif +let b:did_indent = 1 + +setlocal nosmartindent +setlocal nolisp +setlocal autoindent + +setlocal indentexpr=GetOdinIndent(v:lnum) + +if exists("*GetOdinIndent") + finish +endif + +function! GetOdinIndent(lnum) + let prev = prevnonblank(a:lnum-1) + + if prev == 0 + return 0 + endif + + let prevline = getline(prev) + let line = getline(a:lnum) + + let ind = indent(prev) + + if prevline =~ '[({]\s*$' + let ind += &sw + endif + + if line =~ '^\s*[)}]' + let ind -= &sw + endif + + return ind +endfunction + +endif diff --git a/packages.yaml b/packages.yaml index 4d302f11..c2e0d312 100644 --- a/packages.yaml +++ b/packages.yaml @@ -1827,3 +1827,9 @@ filetypes: - '*/etc/yum.repos.d/*' ignored_warnings: - php.ini +--- +name: odin +remote: Tetralux/odin.vim +filetypes: +- name: odin + linguist: Odin diff --git a/scripts/build b/scripts/build index 982e0f3a..fabec033 100755 --- a/scripts/build +++ b/scripts/build @@ -97,25 +97,6 @@ def load_data() [packages, transform_patterns(heuristics)] end -def parallel(*procs) - threads = procs.map { |p| Thread.new { method(p).call } } - threads.map(&:join).map(&:value) -end - -def read_strings(data, keys, print=false) - if data.is_a?(Hash) - data.flat_map do |key, val| - read_strings(val, keys, keys.include?(key)) - end - elsif data.is_a?(Array) - data.flat_map { |d| read_strings(d, keys, print) } - elsif data.is_a?(String) - print ? [data] : [] - else - [] - end -end - def patterns_to_vim_patterns(patterns) stdin, stdout, stderr = Open3.popen3('vim', '-V', '--clean', '/dev/stdin', '-es', '-c', "echo expand('%:p:h') | source #{__dir__}/eregex.vim", '-c', "for line in range(0, line('$')) | call setline(line, ExtendedRegex2VimRegex(getline(line))) | endfor", '-c', ':wq! /dev/stdout', chdir: __dir__) stdin.write(patterns.join("\n")) @@ -168,28 +149,30 @@ def copy_file(package, src, dest) FileUtils.mkdir_p(File.dirname(dest)) name = package.fetch("name") - header = '" Polyglot metafile' - if File.exist?(dest) - meta_dest = dest - new_dest = dest - i = 0 - while File.exist?(new_dest) - i += 1 - new_dest = "#{dest.gsub(/\.vim$/, '')}-#{i}.vim" - end + if dest.end_with?(".vim") + header = '" Polyglot metafile' + if File.exist?(dest) + meta_dest = dest + new_dest = dest + i = 0 + while File.exist?(new_dest) + i += 1 + new_dest = "#{dest.gsub(/\.vim$/, '')}-#{i}.vim" + end - if File.read(dest).include?(header) - dest = new_dest - else - FileUtils.mv(dest, new_dest) - File.write(meta_dest, "#{header}\n") + if File.read(dest).include?(header) + dest = new_dest + else + FileUtils.mv(dest, new_dest) + File.write(meta_dest, "#{header}\n") + open(meta_dest, "a+") do |output| + output << "source <sfile>:h/#{File.basename(new_dest)}\n" + end + dest = "#{dest.gsub(/\.vim$/, '')}-#{i+1}.vim" + end open(meta_dest, "a+") do |output| - output << "source <sfile>:h/#{File.basename(new_dest)}\n" + output << "source <sfile>:h/#{File.basename(dest)}\n" end - dest = "#{dest.gsub(/\.vim$/, '')}-#{i+1}.vim" - end - open(meta_dest, "a+") do |output| - output << "source <sfile>:h/#{File.basename(dest)}\n" end end diff --git a/scripts/test_filetypes.vim b/scripts/test_filetypes.vim index 74eeb4d0..4d7cc0d8 100644 --- a/scripts/test_filetypes.vim +++ b/scripts/test_filetypes.vim @@ -231,3 +231,4 @@ call TestFiletype('trasys') call TestFiletype('basic') call TestFiletype('vb') call TestFiletype('dosini') +call TestFiletype('odin') diff --git a/syntax/odin.vim b/syntax/odin.vim new file mode 100644 index 00000000..a8ad7482 --- /dev/null +++ b/syntax/odin.vim @@ -0,0 +1,170 @@ +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'odin') == -1 + +if exists("b:current_syntax") + finish +endif + +syntax keyword odinUsing using +syntax keyword odinTransmute transmute +syntax keyword odinDistinct distinct +syntax keyword odinOpaque opaque + +syntax keyword odinStruct struct +syntax keyword odinEnum enum +syntax keyword odinUnion union +syntax keyword odinBitField bit_field +syntax keyword odinBitSet bit_set + +syntax keyword odinIf if +syntax keyword odinElse else +syntax keyword odinDo do +syntax keyword odinFor for +syntax keyword odinSwitch switch +syntax keyword odinCase case +syntax keyword odinContinue continue +syntax keyword odinBreak break +syntax keyword odinSizeOf size_of +syntax keyword odinTypeInfoOf type_info_of +syntax keyword odinTypeIdOf typeid_of +syntax keyword odinTypeOf type_of +syntax keyword odinAlignOf align_of + +syntax match odinTodo "TODO" +syntax match odinNote "NOTE" +syntax match odinXXX "XXX" +syntax match odinFixMe "FIXME" +syntax match odinNoCheckin "NOCHECKIN" +syntax match odinHack "HACK" + +syntax keyword odinDataType string bool b8 b16 b32 b64 rune any rawptr f32 f64 f32le f32be f64le f64be u8 u16 u32 u64 u128 u16le u32le u64le u128le u16be u32be u64be u128be uint i8 i16 i32 i64 i128 i16le i32le i64le i128le i16be i32be i64be i128be int +syntax keyword odinBool true false +syntax keyword odinNull nil +syntax keyword odinDynamic dynamic +syntax keyword odinProc proc +syntax keyword odinIn in +syntax keyword odinNotIn notin +syntax keyword odinNotIn not_in +syntax keyword odinImport import +syntax keyword odinExport export +syntax keyword odinForeign foreign +syntax keyword odinConst const +syntax match odinNoinit "---" +syntax keyword odinPackage package + +syntax keyword odinReturn return +syntax keyword odinDefer defer + +syntax region odinChar start=/\v'/ skip=/\v\\./ end=/\v'/ +syntax region odinString start=/\v"/ skip=/\v\\./ end=/\v"/ + +syntax match odinFunction "\v<\w*>(\s*::\s*)@=" +syntax match odinDynamicFunction "\v<\w*(\s*:\=\s*\(.*\))@=" + +syntax match odinTagNote "@\<\w\+\>" display + +syntax match odinClass "\v<[A-Z]\w+>" display +syntax match odinConstant "\v<[A-Z0-9,_]+>" display +syntax match odinRange "\.\." display +syntax match odinHalfRange "\.\.\<" display +syntax match odinTernaryQMark "?" display +syntax match odinDeclaration "\:\:\?" display +syntax match odinDeclAssign ":=" display +syntax match odinReturnOp "->" display + +syntax match odinInteger "\-\?\<\d\+\>" display +syntax match odinFloat "\-\?\<[0-9][0-9_]*\%(\.[0-9][0-9_]*\)\%([eE][+-]\=[0-9_]\+\)\=" display +syntax match odinHex "\-\?\<0x[0-9A-Fa-f]\+\>" display +syntax match odinAddressOf "&" display +syntax match odinDeref "\^" display + +syntax match odinMacro "#\<\w\+\>" display + +syntax match odinTemplate "$\<\w\+\>" + +syntax match odinCommentNote "@\<\w\+\>" contained display +syntax region odinLineComment start=/\/\// end=/$/ contains=odinLineComment, odinCommentNote, odinTodo, odinNote, odinXXX, odinFixMe, odinNoCheckin, odinHack +syntax region odinBlockComment start=/\v\/\*/ end=/\v\*\// contains=odinBlockComment, odinCommentNote, odinTodo, odinNote, odinXXX, odinFixMe, odinNoCheckin, odinHack + +highlight link odinUsing Keyword +highlight link odinTransmute Keyword +highlight link odinDistinct Keyword +highlight link odinOpaque Keyword +highlight link odinReturn Keyword +highlight link odinSwitch Keyword +highlight link odinCase Keyword +highlight link odinProc Keyword +highlight link odinIn Keyword +highlight link odinNotIn Keyword +highlight link odinContinue Keyword +highlight link odinBreak Keyword +highlight link odinSizeOf Keyword +highlight link odinTypeOf Keyword +highlight link odinTypeInfoOf Keyword +highlight link odinTypeIdOf Keyword +highlight link odinAlignOf Keyword +highlight link odinPackage Keyword + +highlight link odinImport Keyword +highlight link odinExport Keyword +highlight link odinForeign Keyword +highlight link odinNoinit Keyword +highlight link odinDo Keyword + +highlight link odinDefer Operator +highlight link odinDynamic Operator +highlight link odinRange Operator +highlight link odinHalfRange Operator +highlight link odinAssign Operator +highlight link odinAddressOf Operator +highlight link odinDeref Operator + +highlight link odinDeclaration Operator +highlight link odinDeclAssign Operator +highlight link odinAssign Operator +highlight link odinTernaryQMark Operator +highlight link odinReturnOp Operator + +highlight link odinString String +highlight link odinChar String + +highlight link odinStruct Structure +highlight link odinEnum Structure +highlight link odinUnion Structure +highlight link odinBitField Structure +highlight link odinBitSet Structure + +highlight link odinFunction Function +highlight link odinDynamicFunction Function + +highlight link odinMacro Macro +highlight link odinIf Conditional +highlight link odinElse Conditional +highlight link odinFor Repeat + +highlight link odinLineComment Comment +highlight link odinBlockComment Comment +highlight link odinCommentNote Todo + +highlight link odinTodo Todo +highlight link odinNote Todo +highlight link odinXXX Todo +highlight link odinFixMe Todo +highlight link odinNoCheckin Todo +highlight link odinHack Todo + +highlight link odinClass Type + +highlight link odinTemplate Constant + +highlight link odinTagNote Identifier +highlight link odinDataType Type +highlight link odinBool Boolean +highlight link odinConstant Constant +highlight link odinNull Type +highlight link odinInteger Number +highlight link odinFloat Float +highlight link odinHex Number + +let b:current_syntax = "odin" + +endif |