As a non-guitarist, writing idiomatically is a difficult task. I have been more successful lately, but it remains a struggle. I have a few practical rules I will list below that I try to follow (the key word here being “try”):
1. Before composing, I try to “hear” the instrument in my head.
2. Simplify. Keep counterpoint to the minimum. Remember that a guitarist uses but 3 fingers and thumb on the right hand. Write what you want, then remove notes.
3. Work closely with a guitarist and be prepared to edit again. The guitarist knows the instrument and its limitations better than you.
When you succeed, you have real guitar music, and not just a piano piece arranged for the guitar.