The way to attain compunction is an attentive life. ‘The beginning of repentance comes from the fear of God and attention,’ as the holy martyr Boniface says.
Compunction comes when you consider how much you have grieved God Who is so good, so sweet, so merciful, so kind, and entirely full of love; Who was crucified and suffered everything for us. When you meditate on these things and other things the Lord has suffered, they bring compunction.
Not he is chaste in whom shameful thoughts stop in time of struggle, work and endeavor, but he who by the trueness of his heart makes chaste the vision of his mind not letting it stretch out towards unseemly thoughts.