From 2a80d6124d86b9cf9366b8d98dcc96ae2adb9282 Mon Sep 17 00:00:00 2001 From: BK Bolisetty Date: Thu, 2 Jun 2016 13:28:26 -0500 Subject: [PATCH 1/3] Support for OpenSCAD --- README.md | 1 + ftdetect/polyglot.vim | 3 ++ ftplugin/openscad.vim | 2 ++ syntax/openscad.vim | 77 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 ftplugin/openscad.vim create mode 100644 syntax/openscad.vim diff --git a/README.md b/README.md index c7d7cf9a8..9861984b0 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,7 @@ Optionally download one of the [releases](https://github.com/sheerun/vim-polyglo - [ocaml](https://github.com/jrk/vim-ocaml) (syntax, indent, ftplugin) - [octave](https://github.com/vim-scripts/octave.vim--) (syntax) - [opencl](https://github.com/petRUShka/vim-opencl) (syntax, indent, ftplugin, ftdetect) +- [openscad](https://github.com/sirtaj/vim-openscad) (syntax, ftplugin, ftdetect) - [perl](https://github.com/vim-perl/vim-perl) (syntax, indent, ftplugin, ftdetect) - [pgsql](https://github.com/exu/pgsql.vim) (syntax, ftdetect) - [php](https://github.com/StanAngeloff/php.vim) (syntax) diff --git a/ftdetect/polyglot.vim b/ftdetect/polyglot.vim index abadf0736..f3d674131 100644 --- a/ftdetect/polyglot.vim +++ b/ftdetect/polyglot.vim @@ -316,6 +316,9 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'opencl') == -1 au! BufRead,BufNewFile *.cl set filetype=opencl endif + +au! BufRead,BufNewFile *.scad set filetype=openscad + if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'perl') == -1 function! s:DetectPerl6() diff --git a/ftplugin/openscad.vim b/ftplugin/openscad.vim new file mode 100644 index 000000000..6cba22210 --- /dev/null +++ b/ftplugin/openscad.vim @@ -0,0 +1,2 @@ +au BufRead,BufNewFile *.scad setfiletype openscad +an 50.80.265 &Syntax.NO.OpenSCAD :cal SetSyn("openscad") diff --git a/syntax/openscad.vim b/syntax/openscad.vim new file mode 100644 index 000000000..dade411d2 --- /dev/null +++ b/syntax/openscad.vim @@ -0,0 +1,77 @@ +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'c/c++') == -1 + +" Vim syntax file +" Language: OpenSCAD +" Maintainer: Sirtaj Singh Kang +" Last Changed: 2011 April 19 + +if version < 600 + syntax clear +elseif exists("b:current_syntax") + finish +endif + + +"syn keyword openscadFunctionDef function +syn keyword openscadFunctionDef function nextgroup=openscadFunction skipwhite skipempty +syn match openscadFunction /\<\h\w*\>/ contained display + +"syn keyword openscadModuleDef module +syn keyword openscadModuleDef module nextgroup=openscadModule skipwhite skipempty +syn match openscadModule /\<\h\w*\>/ contained display + +syn keyword openscadStatement echo assign +syn keyword openscadConditional if else +syn keyword openscadRepeat for intersection_for +syn keyword openscadInclude include use +syn keyword openscadCsgKeyword union difference intersection render intersection_for +syn keyword openscadTransform scale rotate translate mirror multmatrix color minkowski +syn keyword openscadPrimitiveSolid cube sphere cylinder polyhedron surface + +syn match openscadSpecialVariable "\$[a-zA-Z]\+\>" display +syn match openscadModifier "^\s*[\*\!\#\%]" display + +syn match openscadNumbers "\<\d\|\.\d" contains=openscadNumber display transparent +syn match openscadNumber "\d\+" display contained +syn match openscadNumber "\.\d\+" display contained + +syn region openscadString start=/"/ skip=/\\"/ end=/"/ + +syn keyword openscadBoolean true false + +syn keyword openscadCommentTodo TODO FIXME XXX contained display +syn match openscadInlineComment ://.*$: contains=scadCommentTodo +syn region openscadBlockComment start=:/\*: end=:\*/: fold contains=openscadCommentTodo + +syn region openscadBlock start="{" end="}" transparent fold +syn region openscadVector start="\[" end="\]" transparent fold + +syn keyword openscadBuiltin abs acos asin atan atan2 ceil cos exp floor ln log +syn keyword openscadBuiltin lookup max min pow rands round sign sin sqrt tan +syn keyword openscadBuiltin str + +hi def link openscadFunctionDef Structure +hi def link openscadFunction Function +hi def link openscadModuleDef Structure +hi def link openscadModule Function +hi def link openscadBlockComment Comment +hi def link openscadBoolean Boolean +hi def link openscadBuiltin Function +hi def link openscadConditional Conditional +hi def link openscadCsgKeyword Structure +hi def link openscadInclude Include +hi def link openscadInlineComment Comment +hi def link openscadModifier Special +hi def link openscadStatement Statement +hi def link openscadNumbers Number +hi def link openscadNumber Number +hi def link openscadPrimitiveSolid Keyword +hi def link openscadRepeat Repeat +hi def link openscadSpecialVariable Special +hi def link openscadString String +hi def link openscadTransform Statement +hi def link openscadCommentTodo Todo + +let b:current_syntax = "openscad" + +endif From 7d96036a049cb1ff9fdc99716c9acf96e446ac85 Mon Sep 17 00:00:00 2001 From: BK Bolisetty Date: Thu, 2 Jun 2016 13:36:15 -0500 Subject: [PATCH 2/3] Correction. Copy paste error. The first line should say 'openscad' instead of 'c/c++'. --- syntax/openscad.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syntax/openscad.vim b/syntax/openscad.vim index dade411d2..d9646d26f 100644 --- a/syntax/openscad.vim +++ b/syntax/openscad.vim @@ -1,4 +1,4 @@ -if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'c/c++') == -1 +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'openscad') == -1 " Vim syntax file " Language: OpenSCAD From 8b0943799c77813268b485e00b1202e8249e33df Mon Sep 17 00:00:00 2001 From: BK Bolisetty Date: Thu, 2 Jun 2016 20:50:01 -0500 Subject: [PATCH 3/3] Update according to instructions from sheerun Use only the build file to add more languages. Then run build to download the new additions. --- autoload/rustfmt.vim | 2 +- build | 1 + ftdetect/polyglot.vim | 52 ++++++++++++++++++++++--------------------- ftplugin/openscad.vim | 20 +++++++++++++++-- ftplugin/slim.vim | 1 + syntax/openscad.vim | 28 ++++++++++++++++++----- 6 files changed, 70 insertions(+), 34 deletions(-) diff --git a/autoload/rustfmt.vim b/autoload/rustfmt.vim index 20fd5852a..ee6dd0ca4 100644 --- a/autoload/rustfmt.vim +++ b/autoload/rustfmt.vim @@ -31,7 +31,7 @@ function! rustfmt#Format() let out = systemlist(command . g:rustfmt_options . " " . shellescape(l:tmpname)) - if v:shell_error == 0 + if v:shell_error == 0 || v:shell_error == 3 " remove undo point caused via BufWritePre try | silent undojoin | catch | endtry diff --git a/build b/build index 49bf8c75a..7a1c7ec31 100755 --- a/build +++ b/build @@ -145,6 +145,7 @@ PACKS=" ocaml:jrk/vim-ocaml octave:vim-scripts/octave.vim-- opencl:petRUShka/vim-opencl + openscad:sirtaj/vim-openscad perl:vim-perl/vim-perl pgsql:exu/pgsql.vim php:StanAngeloff/php.vim diff --git a/ftdetect/polyglot.vim b/ftdetect/polyglot.vim index f3d674131..117f8b7dc 100644 --- a/ftdetect/polyglot.vim +++ b/ftdetect/polyglot.vim @@ -316,9 +316,11 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'opencl') == -1 au! BufRead,BufNewFile *.cl set filetype=opencl endif - -au! BufRead,BufNewFile *.scad set filetype=openscad - +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'openscad') == -1 + +au BufRead,BufNewFile *.scad setfiletype openscad +an 50.80.265 &Syntax.NO.OpenSCAD :cal SetSyn("openscad") +endif if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'perl') == -1 function! s:DetectPerl6() @@ -397,28 +399,6 @@ autocmd BufRead,BufNewFile *.qml setfiletype qml endif if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'ruby') == -1 -function! s:setf(filetype) abort - if &filetype !=# a:filetype - let &filetype = a:filetype - endif -endfunction -func! s:StarSetf(ft) - if expand("") !~ g:ft_ignore_pat - exe 'setf ' . a:ft - endif -endfunc -au BufNewFile,BufRead *.erb,*.rhtml call s:setf('eruby') -au BufNewFile,BufRead .irbrc,irbrc call s:setf('ruby') -au BufNewFile,BufRead *.rb,*.rbw,*.gemspec call s:setf('ruby') -au BufNewFile,BufRead *.ru call s:setf('ruby') -au BufNewFile,BufRead Gemfile call s:setf('ruby') -au BufNewFile,BufRead *.builder,*.rxml,*.rjs,*.ruby call s:setf('ruby') -au BufNewFile,BufRead [rR]akefile,*.rake call s:setf('ruby') -au BufNewFile,BufRead [rR]akefile* call s:StarSetf('ruby') -au BufNewFile,BufRead [rR]antfile,*.rant call s:setf('ruby') -endif -if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'ruby') == -1 - function! s:setf(filetype) abort if &filetype !=# a:filetype let &filetype = a:filetype @@ -443,6 +423,28 @@ au BufNewFile,BufRead .simplecov call s:setf('ruby) au BufNewFile,BufRead [tT]horfile,*.thor call s:setf('ruby') au BufNewFile,BufRead [vV]agrantfile call s:setf('ruby') endif +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'ruby') == -1 + +function! s:setf(filetype) abort + if &filetype !=# a:filetype + let &filetype = a:filetype + endif +endfunction +func! s:StarSetf(ft) + if expand("") !~ g:ft_ignore_pat + exe 'setf ' . a:ft + endif +endfunc +au BufNewFile,BufRead *.erb,*.rhtml call s:setf('eruby') +au BufNewFile,BufRead .irbrc,irbrc call s:setf('ruby') +au BufNewFile,BufRead *.rb,*.rbw,*.gemspec call s:setf('ruby') +au BufNewFile,BufRead *.ru call s:setf('ruby') +au BufNewFile,BufRead Gemfile call s:setf('ruby') +au BufNewFile,BufRead *.builder,*.rxml,*.rjs,*.ruby call s:setf('ruby') +au BufNewFile,BufRead [rR]akefile,*.rake call s:setf('ruby') +au BufNewFile,BufRead [rR]akefile* call s:StarSetf('ruby') +au BufNewFile,BufRead [rR]antfile,*.rant call s:setf('ruby') +endif if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'rust') == -1 au BufRead,BufNewFile *.rs set filetype=rust diff --git a/ftplugin/openscad.vim b/ftplugin/openscad.vim index 6cba22210..2933c2321 100644 --- a/ftplugin/openscad.vim +++ b/ftplugin/openscad.vim @@ -1,2 +1,18 @@ -au BufRead,BufNewFile *.scad setfiletype openscad -an 50.80.265 &Syntax.NO.OpenSCAD :cal SetSyn("openscad") +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'openscad') == -1 + +" Blatantly stolen from vim74\ftplugin\c.vim + +" Set 'formatoptions' to break comment lines but not other lines, +" and insert the comment leader when hitting or using "o". +setlocal fo-=t fo+=croql + +" Set 'comments' to format dashed lists in comments. +setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,:// + +" Win32 can filter files in the browse dialog +if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter") + let b:browsefilter = "OpenSCAD Source Files (*.scad)\t*.scad\n" . + \ "All Files (*.*)\t*.*\n" +endif + +endif diff --git a/ftplugin/slim.vim b/ftplugin/slim.vim index b3c711870..99ebeeb3f 100644 --- a/ftplugin/slim.vim +++ b/ftplugin/slim.vim @@ -8,5 +8,6 @@ let b:did_ftplugin = 1 let b:undo_ftplugin = "setl isk<" setlocal iskeyword+=- +setlocal commentstring=/%s endif diff --git a/syntax/openscad.vim b/syntax/openscad.vim index d9646d26f..ba1b34748 100644 --- a/syntax/openscad.vim +++ b/syntax/openscad.vim @@ -1,9 +1,9 @@ if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'openscad') == -1 - + " Vim syntax file " Language: OpenSCAD " Maintainer: Sirtaj Singh Kang -" Last Changed: 2011 April 19 +" Last Changed: 2013 March 05 if version < 600 syntax clear @@ -20,13 +20,15 @@ syn match openscadFunction /\<\h\w*\>/ contained display syn keyword openscadModuleDef module nextgroup=openscadModule skipwhite skipempty syn match openscadModule /\<\h\w*\>/ contained display -syn keyword openscadStatement echo assign +syn keyword openscadStatement echo assign let syn keyword openscadConditional if else syn keyword openscadRepeat for intersection_for syn keyword openscadInclude include use syn keyword openscadCsgKeyword union difference intersection render intersection_for -syn keyword openscadTransform scale rotate translate mirror multmatrix color minkowski +syn keyword openscadTransform scale rotate translate mirror multmatrix color minkowski hull projection linear_extrude rotate_extrude offset syn keyword openscadPrimitiveSolid cube sphere cylinder polyhedron surface +syn keyword openscadPrimitive2D square circle polygon import_dxf text +syn keyword openscadPrimitiveImport import child children syn match openscadSpecialVariable "\$[a-zA-Z]\+\>" display syn match openscadModifier "^\s*[\*\!\#\%]" display @@ -40,7 +42,7 @@ syn region openscadString start=/"/ skip=/\\"/ end=/"/ syn keyword openscadBoolean true false syn keyword openscadCommentTodo TODO FIXME XXX contained display -syn match openscadInlineComment ://.*$: contains=scadCommentTodo +syn match openscadInlineComment ://.*$: contains=openscadCommentTodo syn region openscadBlockComment start=:/\*: end=:\*/: fold contains=openscadCommentTodo syn region openscadBlock start="{" end="}" transparent fold @@ -48,7 +50,8 @@ syn region openscadVector start="\[" end="\]" transparent fold syn keyword openscadBuiltin abs acos asin atan atan2 ceil cos exp floor ln log syn keyword openscadBuiltin lookup max min pow rands round sign sin sqrt tan -syn keyword openscadBuiltin str +syn keyword openscadBuiltin str len search version version_num concat chr +syn keyword openscadBuiltin dxf_cross dxf_dim hi def link openscadFunctionDef Structure hi def link openscadFunction Function @@ -66,12 +69,25 @@ hi def link openscadStatement Statement hi def link openscadNumbers Number hi def link openscadNumber Number hi def link openscadPrimitiveSolid Keyword +hi def link openscadPrimitive2D Keyword +hi def link openscadPrimitiveImport Keyword hi def link openscadRepeat Repeat hi def link openscadSpecialVariable Special hi def link openscadString String hi def link openscadTransform Statement hi def link openscadCommentTodo Todo +" Blatantly stolen from vim74\syntax\c.vim +"when wanted, highlight trailing white space +if exists("openscad_space_errors") + if !exists("openscad_no_trail_space_error") + syn match openscadSpaceError display excludenl "\s\+$" + endif + if !exists("openscad_no_tab_space_error") + syn match openscadSpaceError display " \+\t"me=e-1 + endif +endif + let b:current_syntax = "openscad" endif