| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | " Vim syntax file | 
					
						
							|  |  |  | " Language:	X Pixmap v2 | 
					
						
							|  |  |  | " Maintainer:	Steve Wall (hitched97@velnet.com) | 
					
						
							| 
									
										
										
										
											2017-02-17 22:47:16 +01:00
										 |  |  | " Last Change:	2017 Feb 01 | 
					
						
							| 
									
										
										
										
											2012-06-01 22:38:45 +02:00
										 |  |  | " 		(Dominique Pelle added @Spell) | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | " Version:	5.8 | 
					
						
							| 
									
										
										
										
											2017-02-17 22:47:16 +01:00
										 |  |  | "               Jemma Nelson added termguicolors support | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | " | 
					
						
							|  |  |  | " Made from xpm.vim by Ronald Schild <rs@scutum.de> | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-30 23:26:57 +02:00
										 |  |  | " quit when a syntax file was already loaded | 
					
						
							|  |  |  | if exists("b:current_syntax") | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |   finish | 
					
						
							|  |  |  | endif | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-04 21:59:01 +01:00
										 |  |  | let s:cpo_save = &cpo | 
					
						
							|  |  |  | set cpo&vim | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | syn region  xpm2PixelString	start="^"  end="$"  contains=@xpm2Colors | 
					
						
							|  |  |  | syn keyword xpm2Todo		TODO FIXME XXX  contained | 
					
						
							| 
									
										
										
										
											2012-06-01 22:38:45 +02:00
										 |  |  | syn match   xpm2Comment		"\!.*$"  contains=@Spell,xpm2Todo | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-30 23:26:57 +02:00
										 |  |  | command -nargs=+ Hi hi def <args> | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-17 22:47:16 +01:00
										 |  |  | if has("gui_running") || has("termguicolors") && &termguicolors | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   let color  = "" | 
					
						
							|  |  |  |   let chars  = "" | 
					
						
							|  |  |  |   let colors = 0 | 
					
						
							|  |  |  |   let cpp    = 0 | 
					
						
							|  |  |  |   let n      = 0 | 
					
						
							|  |  |  |   let i      = 1 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   while i <= line("$")		" scanning all lines | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let s = getline(i) | 
					
						
							|  |  |  |     if match(s,"\!.*$") != -1 | 
					
						
							|  |  |  |       let s = matchstr(s, "^[^\!]*") | 
					
						
							|  |  |  |     endif | 
					
						
							|  |  |  |     if s != ""			" does line contain a string? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if n == 0			" first string is the Values string | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	" get the 3rd value: colors = number of colors | 
					
						
							|  |  |  | 	let colors = substitute(s, '\s*\d\+\s\+\d\+\s\+\(\d\+\).*', '\1', '') | 
					
						
							|  |  |  | 	" get the 4th value: cpp = number of character per pixel | 
					
						
							|  |  |  | 	let cpp = substitute(s, '\s*\d\+\s\+\d\+\s\+\d\+\s\+\(\d\+\).*', '\1', '') | 
					
						
							| 
									
										
										
										
											2008-06-24 21:16:56 +00:00
										 |  |  | 	if cpp =~ '[^0-9]' | 
					
						
							|  |  |  | 	  break  " if cpp is not made of digits there must be something wrong | 
					
						
							|  |  |  | 	endif | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-06-24 21:16:56 +00:00
										 |  |  | 	" Highlight the Values string as normal string (no pixel string). | 
					
						
							|  |  |  | 	" Only when there is no slash, it would terminate the pattern. | 
					
						
							|  |  |  | 	if s !~ '/' | 
					
						
							|  |  |  | 	  exe 'syn match xpm2Values /' . s . '/' | 
					
						
							|  |  |  | 	endif | 
					
						
							| 
									
										
										
										
											2016-08-31 22:22:10 +02:00
										 |  |  | 	hi def link xpm2Values Statement | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	let n = 1			" n = color index | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       elseif n <= colors		" string is a color specification | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	" get chars = <cpp> length string representing the pixels | 
					
						
							|  |  |  | 	" (first incl. the following whitespace) | 
					
						
							|  |  |  | 	let chars = substitute(s, '\(.\{'.cpp.'}\s\+\).*', '\1', '') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	" now get color, first try 'c' key if any (color visual) | 
					
						
							|  |  |  | 	let color = substitute(s, '.*\sc\s\+\(.\{-}\)\s*\(\(g4\=\|[ms]\)\s.*\)*\s*', '\1', '') | 
					
						
							|  |  |  | 	if color == s | 
					
						
							|  |  |  | 	  " no 'c' key, try 'g' key (grayscale with more than 4 levels) | 
					
						
							|  |  |  | 	  let color = substitute(s, '.*\sg\s\+\(.\{-}\)\s*\(\(g4\|[ms]\)\s.*\)*\s*', '\1', '') | 
					
						
							|  |  |  | 	  if color == s | 
					
						
							|  |  |  | 	    " next try: 'g4' key (4-level grayscale) | 
					
						
							|  |  |  | 	    let color = substitute(s, '.*\sg4\s\+\(.\{-}\)\s*\([ms]\s.*\)*\s*', '\1', '') | 
					
						
							|  |  |  | 	    if color == s | 
					
						
							|  |  |  | 	      " finally try 'm' key (mono visual) | 
					
						
							|  |  |  | 	      let color = substitute(s, '.*\sm\s\+\(.\{-}\)\s*\(s\s.*\)*\s*', '\1', '') | 
					
						
							|  |  |  | 	      if color == s | 
					
						
							|  |  |  | 		let color = "" | 
					
						
							|  |  |  | 	      endif | 
					
						
							|  |  |  | 	    endif | 
					
						
							|  |  |  | 	  endif | 
					
						
							|  |  |  | 	endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	" Vim cannot handle RGB codes with more than 6 hex digits | 
					
						
							|  |  |  | 	if color =~ '#\x\{10,}$' | 
					
						
							|  |  |  | 	  let color = substitute(color, '\(\x\x\)\x\x', '\1', 'g') | 
					
						
							|  |  |  | 	elseif color =~ '#\x\{7,}$' | 
					
						
							|  |  |  | 	  let color = substitute(color, '\(\x\x\)\x', '\1', 'g') | 
					
						
							|  |  |  | 	" nor with 3 digits | 
					
						
							|  |  |  | 	elseif color =~ '#\x\{3}$' | 
					
						
							|  |  |  | 	  let color = substitute(color, '\(\x\)\(\x\)\(\x\)', '0\10\20\3', '') | 
					
						
							|  |  |  | 	endif | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	" escape meta characters in patterns | 
					
						
							|  |  |  | 	let s = escape(s, '/\*^$.~[]') | 
					
						
							|  |  |  | 	let chars = escape(chars, '/\*^$.~[]') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	" change whitespace to "\s\+" | 
					
						
							|  |  |  | 	let s = substitute(s, "[ \t][ \t]*", "\\\\s\\\\+", "g") | 
					
						
							|  |  |  | 	let chars = substitute(chars, "[ \t][ \t]*", "\\\\s\\\\+", "g") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	" now create syntax items | 
					
						
							|  |  |  | 	" highlight the color string as normal string (no pixel string) | 
					
						
							|  |  |  | 	exe 'syn match xpm2Col'.n.'Def /'.s.'/ contains=xpm2Col'.n.'inDef' | 
					
						
							| 
									
										
										
										
											2016-08-31 22:22:10 +02:00
										 |  |  | 	exe 'hi def link xpm2Col'.n.'Def Constant' | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	" but highlight the first whitespace after chars in its color | 
					
						
							|  |  |  | 	exe 'syn match xpm2Col'.n.'inDef /^'.chars.'/hs=s+'.(cpp).' contained' | 
					
						
							| 
									
										
										
										
											2016-08-31 22:22:10 +02:00
										 |  |  | 	exe 'hi def link xpm2Col'.n.'inDef xpm2Color'.n | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	" remove the following whitespace from chars | 
					
						
							|  |  |  | 	let chars = substitute(chars, '\\s\\+$', '', '') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	" and create the syntax item contained in the pixel strings | 
					
						
							|  |  |  | 	exe 'syn match xpm2Color'.n.' /'.chars.'/ contained' | 
					
						
							|  |  |  | 	exe 'syn cluster xpm2Colors add=xpm2Color'.n | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	" if no color or color = "None" show background | 
					
						
							|  |  |  | 	if color == ""  ||  substitute(color, '.*', '\L&', '') == 'none' | 
					
						
							|  |  |  | 	  exe 'Hi xpm2Color'.n.' guifg=bg guibg=NONE' | 
					
						
							| 
									
										
										
										
											2008-06-24 21:16:56 +00:00
										 |  |  | 	elseif color !~ "'" | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 	  exe 'Hi xpm2Color'.n." guifg='".color."' guibg='".color."'" | 
					
						
							|  |  |  | 	endif | 
					
						
							|  |  |  | 	let n = n + 1 | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  | 	break			" no more color string | 
					
						
							|  |  |  |       endif | 
					
						
							|  |  |  |     endif | 
					
						
							|  |  |  |     let i = i + 1 | 
					
						
							|  |  |  |   endwhile | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   unlet color chars colors cpp n i s | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-17 22:47:16 +01:00
										 |  |  | endif          " has("gui_running") || has("termguicolors") && &termguicolors | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | " Define the default highlighting. | 
					
						
							| 
									
										
										
										
											2016-08-30 23:26:57 +02:00
										 |  |  | " Only when an item doesn't have highlighting yet | 
					
						
							|  |  |  | " The default highlighting. | 
					
						
							| 
									
										
										
										
											2016-08-31 22:22:10 +02:00
										 |  |  | hi def link xpm2Type		Type | 
					
						
							|  |  |  | hi def link xpm2StorageClass	StorageClass | 
					
						
							|  |  |  | hi def link xpm2Todo		Todo | 
					
						
							|  |  |  | hi def link xpm2Comment		Comment | 
					
						
							|  |  |  | hi def link xpm2PixelString	String | 
					
						
							| 
									
										
										
										
											2016-08-30 23:26:57 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | delcommand Hi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | let b:current_syntax = "xpm2" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-04 21:59:01 +01:00
										 |  |  | let &cpo = s:cpo_save | 
					
						
							|  |  |  | unlet s:cpo_save | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  | " vim: ts=8:sw=2:noet: |