A representation-theoretic approach to nearly holomorphic modular forms