22" File: glsl.vim
33" Description: Syntax checker for OpenGL Shading Language
44" Maintainer: Joshua Rahm <[email protected] >5- " Notes: Add the special comment line "// profile: " somewhere in the file
6- " Followed by what profile to use for the cgc compiler when
7- " checking the file. The defalt behavior is to pick the profile
8- " based on the entries of dictionary g:syntastic_glsl_extensions
9- " or a default dictionary if that variable does not exist
10- " Use the variable g:syntastic_glsl_extra_args to specify extra
11- " arguments to pass to the cgc compiler
125" License: This program is free software. It comes without any warranty,
136" to the extent permitted by applicable law. You can redistribute
147" it and/or modify it under the terms of the Do What The Fuck You
1710"
1811" ============================================================================
1912
20-
2113if exists (" g:loaded_syntastic_glsl_cgc_checker" )
2214 finish
2315endif
2416
25- let g: loaded_syntastic_glsl_cgc_checker= 1
26-
27- function ! SyntaxCheckers_glsl_cgc_checker_IsAvailable () dict
28- return executable (self .getExec ());
29- endfunction
30-
31- function ! SyntaxCheckers_glsl_cgc_checker_GetProfile ()
32- let magic = ' ^// profile: '
33- let line = search ( magic , ' n' )
34-
35- if line
36- let profile = substitute ( getline (line ), magic , ' ' , ' ' )
37- return profile
38- endif
39-
40- if exists (' g:syntastic_glsl_extensions' )
41- let profiles = g: syntastic_glsl_cgc_profiles
42- else
43- let profiles = {
44- \ ' glslf' : ' gpu_fp' ,
45- \ ' glslv' : ' gpu_vp' ,
46- \ ' frag' : ' gpu_fp' ,
47- \ ' vert' : ' gpu_vp' ,
48- \ ' fp' : ' gpu_fp' ,
49- \ ' vp' : ' gpu_vp' }
50- endif
51-
17+ let g: loaded_syntastic_glsl_cgc_checker = 1
5218
53- let ext = expand ( ' %:e ' )
54-
55- if has_key (profiles, ext)
56- return profiles[ext]
57- else
58- return ' gpu_vert '
59- endif
60- endfunction !
19+ let s: glsl_extensions = {
20+ \ ' glslf ' : ' gpu_fp ' ,
21+ \ ' glslv ' : ' gpu_vp ' ,
22+ \ ' frag ' : ' gpu_fp ' ,
23+ \ ' vert ' : ' gpu_vp ' ,
24+ \ ' fp ' : ' gpu_fp ' ,
25+ \ ' vp ' : ' gpu_vp '
26+ \ }
6127
62- function ! SyntaxCheckers_glsl_cgc_GetExtraArgs ()
63- if exists (' g:syntastic_glsl_extra_args' )
64- return g: syntastic_glsl_extra_args
65- else
66- return ' '
67- endif
68- endfunction
28+ let s: save_cpo = &cpo
29+ set cpo &vim
6930
7031function ! SyntaxCheckers_glsl_cgc_GetLocList () dict
71- let profile = SyntaxCheckers_glsl_cgc_checker_GetProfile ()
72-
73- let args = printf (" -oglsl -profile %s %s" , profile ,SyntaxCheckers_glsl_cgc_GetExtraArgs ())
7432 let makeprg = self .makeprgBuild ({
75- \' args ': args })
33+ \ ' args' : ' -oglsl -profile ' . s: GetProfile () .
34+ \ (exists (' g:syntastic_glsl_options' ) ? ' ' . g: syntastic_glsl_options : ' ' ) })
7635
7736 let errorformat =
7837 \ " %E%f(%l) : error %m," .
@@ -83,6 +42,27 @@ function! SyntaxCheckers_glsl_cgc_GetLocList() dict
8342 \ ' errorformat' : errorformat })
8443endfunction
8544
45+ function ! s: GetProfile ()
46+ let save_cursor = getpos (' .' )
47+ let magic = ' \m\C^// profile:\s*'
48+ let line = search (magic , ' c' )
49+ call setpos (' .' , save_cursor)
50+
51+ if line
52+ let profile = matchstr (getline (line ), magic . ' \zs.*' )
53+ else
54+ let extensions = exists (' g:syntastic_glsl_extensions' ) ? g: syntastic_glsl_extensions : s: glsl_extensions
55+ let profile = get (extensions, tolower (expand (' %:e' )), ' gpu_vert' )
56+ endif
57+
58+ return profile
59+ endfunction !
60+
8661call g: SyntasticRegistry .CreateAndRegisterChecker ({
8762 \' filetype ' : ' glsl',
8863 \' name' : ' cgc'})
64+
65+ let &cpo = s: save_cpo
66+ unlet s: save_cpo
67+
68+ " vim: set et sts = 4 sw = 4 :
0 commit comments