[TxMt] Re: showing preview of css colors

Allan Odgaard mailinglist at textmate.org
Mon May 30 21:36:23 UTC 2016

On 30 May 2016, at 23:04, Carpii UK wrote:

>> a) create a script to find everywhere a color is specified in a CSS 
>> file
> How would this look? Would it require a bundle-style reg-exp which 
> pulls
> them all out?
> My preference would be to write it as a proper script […]

Yes, write a regular script that reads a CSS file (preferably from 
stdin) and then parses this and for each color it finds, it needs to 
execute this:

     "$TM_MATE" --line «line»[:«column»] --set-mark 

So it should track the line number and could also track the column 
number, but for now, the result will be the same (since we add to the 
gutter rather than inlined).

>> b) generate an image from a CSS color specification.
> I'll look into this too, maybe I can do something with EPS.
> Would each image need to be written to disk, or simply be another 
> script
> which streams it to stdout, and somehow TM calls it and reads the 
> image
> from there?

It needs to be written to disk, I suggest using a location like 
`~/Library/Caches/com.macromates.textmate.colors/` and then you can also 
skip generating an image if the file already exist.

I realize a minor nuisance: currently when you set a mark you must 
manually clear that mark yourself by specifying the same image, e.g. to 
clear the mark from the above example we need to run:

     "$TM_MATE" --line «line»[:«column»] --clear-mark 

We can remove the `--line` argument to remove all the marks using this 
image, but we still need to specify the image, so for a script that 
generates arbitrary images, this requires some bookkeeping.

I think one solution could be that if the path supplied to 
`--clear-mark` ends with a slash, it will clear all marks which are 
descendents of that path, so that the script only need to make one call 
to `--clear-mark` rather than one per image it has previously 

More information about the textmate mailing list