1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-02 22:30:04 +08:00

Add lang#povray layer (#3724)

This commit is contained in:
Wang Shidong 2020-12-20 19:41:17 +08:00 committed by GitHub
parent f8e828e9dd
commit 426fa6fbb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 407 additions and 0 deletions

View File

@ -0,0 +1,40 @@
"=============================================================================
" povray.vim --- POV-Ray language support
" Copyright (c) 2016-2019 Wang Shidong & Contributors
" Author: Wang Shidong < wsdjeg@outlook.com >
" URL: https://spacevim.org
" License: GPLv3
"=============================================================================
if exists('s:povray_command')
finish
else
let s:povray_command = 'povray'
endif
function! SpaceVim#layers#lang#povray#plugins() abort
let plugins = []
call add(plugins, [g:_spacevim_root_dir . 'bundle/vim-povray', { 'merged' : 0}])
return plugins
endfunction
function! SpaceVim#layers#lang#povray#config() abort
let g:povray_command = s:povray_command
call SpaceVim#mapping#space#regesit_lang_mappings('povray', function('s:language_specified_mappings'))
endfunction
function! SpaceVim#layers#lang#povray#set_variable(opt) abort
let s:povray_command = get(a:opt, 'povray_command', s:povray_command)
endfunction
function! s:language_specified_mappings() abort
call SpaceVim#mapping#space#langSPC('nmap', ['l','v'],
\ 'call povray#view()',
\ 'view-image', 1)
call SpaceVim#mapping#space#langSPC('nmap', ['l','c'],
\ 'call povray#cleanPreviousImage()',
\ 'clean-previous-image', 1)
call SpaceVim#mapping#space#langSPC('nmap', ['l','b'],
\ 'call povray#CompileSilent()',
\ 'build-silent', 1)
endfunction

View File

@ -0,0 +1,3 @@
# vim-povray
> POV-Ray language support for Vim

View File

@ -0,0 +1,2 @@
au BufNewFile,BufRead *.pov set filetype=povray

View File

@ -0,0 +1,77 @@
"=============================================================================
" povray.vim --- povray ftplugin
" Copyright (c) 2016-2019 Wang Shidong & Contributors
" Author: Wang Shidong < wsdjeg@outlook.com >
" URL: https://spacevim.org
" License: GPLv3
"=============================================================================
if !exists("g:povray_command")
let g:povray_command = "povray"
endif
if !empty(glob("~/.vim/*/vim-do"))
let g:execute_command = "DoQuietly"
else
let g:execute_command = "silent !"
endif
let s:compilation_failed = 0
function! povray#cleanPreviousImage()
let l:remove = system("rm " . expand("%:r") . ".png")
redraw!
endfunction
function! povray#CompileSilent()
call povray#cleanPreviousImage()
execute 'w!'
let g:compile_output = system(g:povray_command . " "
\ . expand("%"))
if empty(glob(expand("%:r") . ".png"))
let s:compilation_failed = 1
call povray#showCompilationOutput()
else
let s:compilation_failed = 0
endif
endfunction
function! povray#showCompilationOutput()
execute 'silent pedit [POVRAY]' . expand("%:r") . ".png"
wincmd P
setlocal filetype=povray_output
setlocal buftype=nofile
setlocal noswapfile
setlocal bufhidden=wipe
setlocal modifiable
call append(0, split(g:compile_output, '\v\n'))
setlocal nomodifiable
nnoremap <silent> <buffer> q :silent bd!<CR>
endfunction
" Compile asynchronously if vim-do is installed
function! povray#CompileAsync()
call povraycleanPreviousImage()
execute 'w!'
execute g:execute_command . " "
\ . g:povray_command . " "
\ . expand("%")
redraw!
endfunction
function! povray#showImage() abort
if exists("g:image_viewer")
execute "silent ! " . g:image_viewer . " "
\ . expand("%:r") . ".png" . "&"
redraw!
else
echom "Define an image viewer - let g:image_viewer = <viewer>"
endif
endfunction
function! povray#CompileAndShow()
call povray#CompileSilent()
if !s:compilation_failed
call povray#showImage()
endif
endfunction

View File

@ -0,0 +1,84 @@
" Vim indent file
" Language: PoV-Ray Scene Description Language
" Maintainer: David Necas (Yeti) <yeti@physics.muni.cz>
" Last Change: 2017 Jun 13
" URI: http://trific.ath.cx/Ftp/vim/indent/pov.vim
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
" Some preliminary settings.
setlocal nolisp " Make sure lisp indenting doesn't supersede us.
setlocal indentexpr=GetPoVRayIndent()
setlocal indentkeys+==else,=end,0]
" Only define the function once.
if exists("*GetPoVRayIndent")
finish
endif
" Counts matches of a regexp <rexp> in line number <line>.
" Doesn't count matches inside strings and comments (as defined by current
" syntax).
function! s:MatchCount(line, rexp)
let str = getline(a:line)
let i = 0
let n = 0
while i >= 0
let i = matchend(str, a:rexp, i)
if i >= 0 && synIDattr(synID(a:line, i, 0), "name") !~? "string\|comment"
let n = n + 1
endif
endwhile
return n
endfunction
" The main function. Returns indent amount.
function GetPoVRayIndent()
" If we are inside a comment (may be nested in obscure ways), give up
if synIDattr(synID(v:lnum, indent(v:lnum)+1, 0), "name") =~? "string\|comment"
return -1
endif
" Search backwards for the frist non-empty, non-comment line.
let plnum = prevnonblank(v:lnum - 1)
let plind = indent(plnum)
while plnum > 0 && synIDattr(synID(plnum, plind+1, 0), "name") =~? "comment"
let plnum = prevnonblank(plnum - 1)
let plind = indent(plnum)
endwhile
" Start indenting from zero
if plnum == 0
return 0
endif
" Analyse previous nonempty line.
let chg = 0
let chg = chg + s:MatchCount(plnum, '[[{(]')
let chg = chg + s:MatchCount(plnum, '#\s*\%(if\|ifdef\|ifndef\|switch\|while\|macro\|else\)\>')
let chg = chg - s:MatchCount(plnum, '#\s*end\>')
let chg = chg - s:MatchCount(plnum, '[]})]')
" Dirty hack for people writing #if and #else on the same line.
let chg = chg - s:MatchCount(plnum, '#\s*\%(if\|ifdef\|ifndef\|switch\)\>.*#\s*else\>')
" When chg > 0, then we opened groups and we should indent more, but when
" chg < 0, we closed groups and this already affected the previous line,
" so we should not dedent. And when everything else fails, scream.
let chg = chg > 0 ? chg : 0
" Analyse current line
" FIXME: If we have to dedent, we should try to find the indentation of the
" opening line.
let cur = s:MatchCount(v:lnum, '^\s*\%(#\s*\%(end\|else\)\>\|[]})]\)')
if cur > 0
let final = plind + (chg - cur) * shiftwidth()
else
let final = plind + chg * shiftwidth()
endif
return final < 0 ? 0 : final
endfunction

View File

@ -0,0 +1,145 @@
" Vim syntax file
" Language: PoV-Ray(tm) 3.7 Scene Description Language
" Maintainer: David Necas (Yeti) <yeti@physics.muni.cz>
" Last Change: 2011-04-23
" Required Vim Version: 6.0
" Setup
" quit when a syntax file was already loaded
if exists("b:current_syntax")
finish
endif
syn case match
" Top level stuff
syn keyword povCommands global_settings
syn keyword povObjects array atmosphere background bicubic_patch blob box camera component cone cubic cylinder disc fog height_field isosurface julia_fractal lathe light_group light_source mesh mesh2 object ovus parametric pattern photons plane poly polygon polynomial prism quadric quartic rainbow sky_sphere smooth_triangle sor sphere sphere_sweep spline superellipsoid text torus triangle
syn keyword povCSG clipped_by composite contained_by difference intersection merge union
syn keyword povAppearance interior material media texture interior_texture texture_list
syn keyword povGlobalSettings ambient_light assumed_gamma charset hf_gray_16 irid_wavelength max_intersections max_trace_level number_of_waves radiosity noise_generator
syn keyword povTransform inverse matrix rotate scale translate transform
" Descriptors
syn keyword povDescriptors finish inside_vector normal pigment uv_mapping uv_vectors vertex_vectors
syn keyword povDescriptors adc_bailout always_sample brightness count error_bound distance_maximum gray_threshold load_file low_error_factor maximum_reuse max_sample media minimum_reuse mm_per_unit nearest_count normal pretrace_end pretrace_start recursion_limit save_file
syn keyword povDescriptors color colour rgb rgbt rgbf rgbft srgb srgbf srgbt srgbft
syn match povDescriptors "\<\(red\|green\|blue\|gray\)\>"
syn keyword povDescriptors bump_map color_map colour_map image_map material_map pigment_map quick_color quick_colour normal_map texture_map image_pattern pigment_pattern
syn keyword povDescriptors ambient brilliance conserve_energy crand diffuse fresnel irid metallic phong phong_size refraction reflection reflection_exponent roughness specular subsurface
syn keyword povDescriptors cylinder fisheye mesh_camera omnimax orthographic panoramic perspective spherical ultra_wide_angle
syn keyword povDescriptors agate aoi average brick boxed bozo bumps cells checker crackle cylindrical dents facets function gradient granite hexagon julia leopard magnet mandel marble onion pavement planar quilted radial ripples slope spherical spiral1 spiral2 spotted square tiles tile2 tiling toroidal triangular waves wood wrinkles
syn keyword povDescriptors density_file
syn keyword povDescriptors area_light shadowless spotlight parallel
syn keyword povDescriptors absorption confidence density emission intervals ratio samples scattering variance
syn keyword povDescriptors distance fog_alt fog_offset fog_type turb_depth
syn keyword povDescriptors b_spline bezier_spline cubic_spline evaluate face_indices form linear_spline max_gradient natural_spline normal_indices normal_vectors quadratic_spline uv_indices
syn keyword povDescriptors target
" Modifiers
syn keyword povModifiers caustics dispersion dispersion_samples fade_color fade_colour fade_distance fade_power ior
syn keyword povModifiers bounded_by double_illuminate hierarchy hollow no_shadow open smooth sturm threshold water_level
syn keyword povModifiers importance no_radiosity
syn keyword povModifiers hypercomplex max_iteration precision quaternion slice
syn keyword povModifiers conic_sweep linear_sweep
syn keyword povModifiers flatness type u_steps v_steps
syn keyword povModifiers aa_level aa_threshold adaptive area_illumination falloff jitter looks_like media_attenuation media_interaction method point_at radius tightness
syn keyword povModifiers angle aperture bokeh blur_samples confidence direction focal_point h_angle location look_at right sky up v_angle variance
syn keyword povModifiers all bump_size gamma interpolate map_type once premultiplied slope_map use_alpha use_color use_colour use_index
syn match povModifiers "\<\(filter\|transmit\)\>"
syn keyword povModifiers black_hole agate_turb brick_size control0 control1 cubic_wave density_map flip frequency interpolate inverse lambda metric mortar octaves offset omega phase poly_wave ramp_wave repeat scallop_wave sine_wave size strength triangle_wave thickness turbulence turb_depth type warp
syn keyword povModifiers eccentricity extinction
syn keyword povModifiers arc_angle falloff_angle width
syn keyword povModifiers accuracy all_intersections altitude autostop circular collect coords cutaway_textures dist_exp expand_thresholds exponent exterior gather global_lights major_radius max_trace no_bump_scale no_image no_reflection orient orientation pass_through precompute projected_through range_divider solid spacing split_union tolerance
" Words not marked `reserved' in documentation, but...
syn keyword povBMPType alpha exr gif hdr iff jpeg pgm png pot ppm sys tga tiff
syn keyword povFontType ttf contained
syn keyword povDensityType df3 contained
syn keyword povCharset ascii utf8 contained
" Math functions on floats, vectors and strings
syn keyword povFunctions abs acos acosh asc asin asinh atan atan2 atanh bitwise_and bitwise_or bitwise_xor ceil cos cosh defined degrees dimensions dimension_size div exp file_exists floor inside int internal ln log max min mod pow prod radians rand seed select sin sinh sqrt strcmp strlen sum tan tanh val vdot vlength vstr vturbulence
syn keyword povFunctions min_extent max_extent trace vcross vrotate vaxis_rotate vnormalize vturbulence
syn keyword povFunctions chr concat datetime now substr str strupr strlwr
syn keyword povJuliaFunctions acosh asinh atan cosh cube pwr reciprocal sinh sqr tanh
" Specialities
syn keyword povConsts clock clock_delta clock_on final_clock final_frame frame_number initial_clock initial_frame input_file_name image_width image_height false no off on pi true version yes
syn match povConsts "\<[tuvxyz]\>"
syn match povDotItem "\.\@<=\(blue\|green\|gray\|filter\|red\|transmit\|hf\|t\|u\|v\|x\|y\|z\)\>" display
" Comments
syn region povComment start="/\*" end="\*/" contains=povTodo,povComment
syn match povComment "//.*" contains=povTodo
syn match povCommentError "\*/"
syn sync ccomment povComment
syn sync minlines=50
syn keyword povTodo TODO FIXME XXX NOT contained
syn cluster povPRIVATE add=povTodo
" Language directives
syn match povConditionalDir "#\s*\(else\|end\|for\|if\|ifdef\|ifndef\|switch\|while\)\>"
syn match povLabelDir "#\s*\(break\|case\|default\|range\)\>"
syn match povDeclareDir "#\s*\(declare\|default\|local\|macro\|undef\|version\)\>" nextgroup=povDeclareOption skipwhite
syn keyword povDeclareOption deprecated once contained nextgroup=povDeclareOption skipwhite
syn match povIncludeDir "#\s*include\>"
syn match povFileDir "#\s*\(fclose\|fopen\|read\|write\)\>"
syn keyword povFileDataType uint8 sint8 unit16be uint16le sint16be sint16le sint32le sint32be
syn match povMessageDir "#\s*\(debug\|error\|render\|statistics\|warning\)\>"
syn region povFileOpen start="#\s*fopen\>" skip=+"[^"]*"+ matchgroup=povOpenType end="\<\(read\|write\|append\)\>" contains=ALLBUT,PovParenError,PovBraceError,@PovPRIVATE transparent keepend
" Literal strings
syn match povSpecialChar "\\u\x\{4}\|\\\d\d\d\|\\." contained
syn region povString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=povSpecialChar oneline
syn cluster povPRIVATE add=povSpecialChar
" Catch errors caused by wrong parenthesization
syn region povParen start='(' end=')' contains=ALLBUT,povParenError,@povPRIVATE transparent
syn match povParenError ")"
syn region povBrace start='{' end='}' contains=ALLBUT,povBraceError,@povPRIVATE transparent
syn match povBraceError "}"
" Numbers
syn match povNumber "\(^\|\W\)\@<=[+-]\=\(\d\+\)\=\.\=\d\+\([eE][+-]\=\d\+\)\="
" Define the default highlighting
hi def link povComment Comment
hi def link povTodo Todo
hi def link povNumber Number
hi def link povString String
hi def link povFileOpen Constant
hi def link povConsts Constant
hi def link povDotItem povSpecial
hi def link povBMPType povSpecial
hi def link povCharset povSpecial
hi def link povDensityType povSpecial
hi def link povFontType povSpecial
hi def link povOpenType povSpecial
hi def link povSpecialChar povSpecial
hi def link povSpecial Special
hi def link povConditionalDir PreProc
hi def link povLabelDir PreProc
hi def link povDeclareDir Define
hi def link povDeclareOption Define
hi def link povIncludeDir Include
hi def link povFileDir PreProc
hi def link povFileDataType Special
hi def link povMessageDir Debug
hi def link povAppearance povDescriptors
hi def link povObjects povDescriptors
hi def link povGlobalSettings povDescriptors
hi def link povDescriptors Type
hi def link povJuliaFunctions PovFunctions
hi def link povModifiers povFunctions
hi def link povFunctions Function
hi def link povCommands Operator
hi def link povTransform Operator
hi def link povCSG Operator
hi def link povParenError povError
hi def link povBraceError povError
hi def link povCommentError povError
hi def link povError Error
let b:current_syntax = "povray"

View File

@ -141,6 +141,7 @@ Vim 插件以及相关配置。而 SpaceVim 是以模块的方式来组织和管
| [lang#php](lang/php/) | 这一模块为 SpaceVim 提供了 PHP 的开发支持,包括代码补全、语法检查、代码格式化等特性。 | | [lang#php](lang/php/) | 这一模块为 SpaceVim 提供了 PHP 的开发支持,包括代码补全、语法检查、代码格式化等特性。 |
| [lang#plantuml](lang/plantuml/) | 这一模块为 SpaceVim 提供了 PlantUML 的开发支持,包括语法高亮、实时预览等特性。 | | [lang#plantuml](lang/plantuml/) | 这一模块为 SpaceVim 提供了 PlantUML 的开发支持,包括语法高亮、实时预览等特性。 |
| [lang#pony](lang/pony/) | 这一模块为 pony 开发提供支持,包括交互式编程、一键运行等特性。 | | [lang#pony](lang/pony/) | 这一模块为 pony 开发提供支持,包括交互式编程、一键运行等特性。 |
| [lang#povray](lang/povray/) | POV-Ray 语言模块,包括语法高亮、图片生成等特性。 |
| [lang#powershell](lang/powershell/) | 这一模块为 powershell 开发提供支持,包括交互式编程、一键运行等特性。 | | [lang#powershell](lang/powershell/) | 这一模块为 powershell 开发提供支持,包括交互式编程、一键运行等特性。 |
| [lang#prolog](lang/prolog/) | 这一模块为 Prolog 开发提供支持,包括交互式编程、一键运行等特性。 | | [lang#prolog](lang/prolog/) | 这一模块为 Prolog 开发提供支持,包括交互式编程、一键运行等特性。 |
| [lang#puppet](lang/puppet/) | 这一模块为 SpaceVim 提供了 Puppet 的开发支持,包括语法高亮、语言服务器支持。 | | [lang#puppet](lang/puppet/) | 这一模块为 SpaceVim 提供了 Puppet 的开发支持,包括语法高亮、语言服务器支持。 |

View File

@ -0,0 +1,27 @@
---
title: "SpaceVim lang#povray 模块"
description: "POV-Ray 语言模块,包括语法高亮、图片生成等特性。"
lang: zh
---
# [可用模块](../../) >> lang#povray
<!-- vim-markdown-toc GFM -->
- [模块简介](#模块简介)
- [启用模块](#启用模块)
<!-- vim-markdown-toc -->
## 模块简介
该模块为 SpaceVim 提供了 [POV-Ray](https://www.povray.org/) 语言的支持,包括语法高亮,图片生成等功能。
## 启用模块
可通过在配置文件内加入如下配置来启用该模块:
```toml
[[layers]]
name = "lang#povray"
```

View File

@ -150,6 +150,7 @@ Some layers are enabled by default. The following example shows how to disable `
| [lang#php](lang/php/) | PHP language support, including code completion, syntax lint and code runner | | [lang#php](lang/php/) | PHP language support, including code completion, syntax lint and code runner |
| [lang#plantuml](lang/plantuml/) | This layer is for PlantUML development, syntax highlighting for PlantUML file. | | [lang#plantuml](lang/plantuml/) | This layer is for PlantUML development, syntax highlighting for PlantUML file. |
| [lang#pony](lang/pony/) | This layer is for pony development, provide syntax checking, code runner and repl support for pony file. | | [lang#pony](lang/pony/) | This layer is for pony development, provide syntax checking, code runner and repl support for pony file. |
| [lang#povray](lang/povray/) | This layer is for povray development, provide syntax highlighting, viewing images. |
| [lang#powershell](lang/powershell/) | This layer is for powershell development, provide syntax checking, code runner and repl support for powershell file. | | [lang#powershell](lang/powershell/) | This layer is for powershell development, provide syntax checking, code runner and repl support for powershell file. |
| [lang#processing](lang/processing/) | This layer is for working on Processing sketches. It provides sytnax checking and an app runner | | [lang#processing](lang/processing/) | This layer is for working on Processing sketches. It provides sytnax checking and an app runner |
| [lang#prolog](lang/prolog/) | This layer is for Prolog development, provide syntax checking, code runner and repl support for prolog file. | | [lang#prolog](lang/prolog/) | This layer is for Prolog development, provide syntax checking, code runner and repl support for prolog file. |

View File

@ -0,0 +1,27 @@
---
title: "SpaceVim lang#povray layer"
description: "This layer is for povray development, provide syntax highlighting, viewing images."
---
# [Available Layers](../../) >> lang#povray
<!-- vim-markdown-toc GFM -->
- [Description](#description)
- [Install](#install)
<!-- vim-markdown-toc -->
## Description
This layer is for writing [POV-Ray](https://www.povray.org/) code, including syntax highlighting for `*.pov` files.
## Install
To use this configuration layer, update custom configuration file with:
```toml
[[layers]]
name = "lang#povray"
```