i just borrowed this macro from wowwiki (the link from the macro thread thx Xzin), works great. i'm real new to these detailed macros so I don't know if this is 100% what you are looking for.

/cast [help] [target=targettarget, help] [target=player] Healing Wave (or whatever spell)

1st [help] checks if you can cast on your target, if so it does. and acts like a normal heal button.
2nd [target=targettarget, help] if you are targeting an enemy, will heal the enemys target, if friendly.
3rd heals you if those others arent the case. am i close?