Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
xpm.vim155 linesDownload Raw Back to syntax
1" Vim syntax file2" Language:	X Pixmap3" Maintainer:	Ronald Schild <rs@scutum.de>4" Last Change:	2023 May 245" Version:	5.4n.26"               Jemma Nelson added termguicolors support7"               Dominique Pellé fixed spelling support8"               Christian J. Robinson fixed use of global variables, moved9"               loop into a compiled function10 11" quit when a syntax file was already loaded12if exists("b:current_syntax")13  finish14endif15 16syn spell notoplevel17 18syn keyword xpmType		char19syn keyword xpmStorageClass	static20syn keyword xpmTodo		TODO FIXME XXX  contained21syn region  xpmComment		start="/\*"  end="\*/"  contains=xpmTodo,@Spell22syn region  xpmPixelString	start=+"+  skip=+\\\\\|\\"+  end=+"+  contains=@xpmColors23 24if has("gui_running") || has("termguicolors") && &termguicolors25 26def s:CreateSyntax(): void27   var color  = ""28   var chars  = ""29   var colors = 030   var cpp    = 031   var n      = 032   var lines  = getline(1, '$')33 34   for line in lines			# scanning all lines35 36      var s = matchstr(line, '".\{-1,}"')37 38      if s != ""			# does line contain a string?39 40	 if n == 0			# first string is the Values string41 42	    var values = split(s[1 : -2])43 44	    # Values string invalid, bail out45 	    if len(values) != 4 && len(values) != 6 && len(values) != 746	       return47	    endif48 49	    # get the 3rd value: colors = number of colors50	    colors = str2nr(values[2])51	    # get the 4th value: cpp = number of character per pixel52	    cpp = str2nr(values[3])53 54	    # these values must be positive, nonzero55	    if colors < 1 || cpp < 156	       return57	    endif58 59	    # Highlight the Values string as normal string (no pixel string).60	    # Only when there is no slash, it would terminate the pattern.61	    if s !~ '/'62	       exe 'syn match xpmValues /' .. s .. '/'63	    endif64	    hi link xpmValues String65 66	    n = 1		# n = color index67 68	 elseif n <= colors	# string is a color specification69 70	    # get chars = <cpp> length string representing the pixels71	    # (first incl. the following whitespace)72	    chars = substitute(s, '"\(.\{' .. cpp .. '}\s\).*"', '\1', '')73 74	    # now get color, first try 'c' key if any (color visual)75	    color = substitute(s, '".*\sc\s\+\(.\{-}\)\s*\(\(g4\=\|[ms]\)\s.*\)*\s*"', '\1', '')76	    if color == s77	       # no 'c' key, try 'g' key (grayscale with more than 4 levels)78	       color = substitute(s, '".*\sg\s\+\(.\{-}\)\s*\(\(g4\|[ms]\)\s.*\)*\s*"', '\1', '')79	       if color == s80		  # next try: 'g4' key (4-level grayscale)81		  color = substitute(s, '".*\sg4\s\+\(.\{-}\)\s*\([ms]\s.*\)*\s*"', '\1', '')82		  if color == s83		     # finally try 'm' key (mono visual)84		     color = substitute(s, '".*\sm\s\+\(.\{-}\)\s*\(s\s.*\)*\s*"', '\1', '')85		     if color == s86			color = ""87		     endif88		  endif89	       endif90	    endif91 92	    # Vim cannot handle RGB codes with more than 6 hex digits93	    if color =~ '#\x\{10,}$'94	       color = substitute(color, '\(\x\x\)\x\x', '\1', 'g')95	    elseif color =~ '#\x\{7,}$'96	       color = substitute(color, '\(\x\x\)\x', '\1', 'g')97	    # nor with 3 digits98	    elseif color =~ '#\x\{3}$'99	       color = substitute(color, '\(\x\)\(\x\)\(\x\)', '0\10\20\3', '')100	    endif101 102	    # escape meta characters in patterns103	    s = escape(s, '/\*^$.~[]')104 	    chars = escape(chars, '/\*^$.~[]')105 106	    # now create syntax items107	    # highlight the color string as normal string (no pixel string)108	    exe 'syn match xpmCol' .. n .. 'Def /' .. s .. '/ contains=xpmCol' .. n .. 'inDef'109	    exe 'hi link xpmCol' .. n .. 'Def String'110 111	    # but highlight the first whitespace after chars in its color112	    exe 'syn match xpmCol' .. n .. 'inDef /"' .. chars .. '/hs=s+' .. (cpp + 1) .. ' contained'113	    exe 'hi link xpmCol' .. n .. 'inDef xpmColor' .. n114 115	    # remove the following whitespace from chars116	    chars = substitute(chars, '.$', '', '')117 118	    # and create the syntax item contained in the pixel strings119	    exe 'syn match xpmColor' .. n .. ' /' .. chars .. '/ contained'120	    exe 'syn cluster xpmColors add=xpmColor' .. n121 122	    # if no color or color = "None" show background123	    if color == ""  ||  substitute(color, '.*', '\L&', '') == 'none'124	       exe 'hi xpmColor' .. n .. ' guifg=bg'125	       exe 'hi xpmColor' .. n .. ' guibg=NONE'126	    elseif color !~ "'"127	       exe 'hi xpmColor' .. n .. " guifg='" .. color .. "'"128	       exe 'hi xpmColor' .. n .. " guibg='" .. color .. "'"129	    endif130	    n += 1131	 else132	    break		# no more color string133	 endif134      endif135   endfor136enddef137 138call s:CreateSyntax()139 140endif          " has("gui_running") || has("termguicolors") && &termguicolors141 142" Define the default highlighting.143" Only when an item doesn't have highlighting yet144 145hi def link xpmType		Type146hi def link xpmStorageClass	StorageClass147hi def link xpmTodo		Todo148hi def link xpmComment		Comment149hi def link xpmPixelString	String150 151 152let b:current_syntax = "xpm"153 154" vim: ts=8:sw=3:noet:155 
codekingpro/portable-devtools · Team Ai