[TxMt] Insert Color Revised (help needed)
Charilaos Skiadas
skiadas at hanover.edu
Sat Oct 21 13:47:40 UTC 2006
On Oct 21, 2006, at 8:21 AM, Brett Terpstra wrote:
> string = $1 * 2 + $2 * 2 + $3 * 2 if string =~ /^(.)(.)(.)$/
>
> You do hate intermediate variables, don't you ;-)?
Hehe yes I do, I try to minimize the variables I use. Mostly because
I am not very good at coming up with names for them ;)
Also, influenced from functional programming, I try minimize the
number of assignments I use.
> I think this needed a minor revision to make it work if there was
> no text selected (no previous color) and you just wanted to insert
> a color. Once again, probably not the most elegant way to handle
> it (but it works). Let me know what you think.
Why not instead simply give it a default, if string is empty?
string = STDIN.read
string = "#999" if string.empty?
prefix, string = string.match(/(#?)(.*)/)[1,2]
string = $1 * 2 + $2 * 2 + $3 * 2 if string =~ /^(.)(.)(.)$/
def_col = ' default color {' + string.scan(/../).map { |i| i.hex *
257 }.join(",") + '}'
......
Haris
More information about the textmate
mailing list