We present a novel language-agnostic approach for integrating and preserving hand-written code in files generated via model-to-text transformation. Unlike existing approaches that only support modification of generated files in predefined locations (e.g., protected regions), the proposed approach allows users to make edits anywhere within generated files. Our hand-written code preservation technique has been implemented on top of an existing model-to-text transformation language (Epsilon’s EGL). The approach is illustrated in a case study involving a code generator of Sirius Web editors and is contrasted with existing approaches such as protected regions and separation of generated and non-generated code using inheritance and delegation.