You might want to look into Forth, which from its beginning, normally did its own editing, file operations, assembling, compiling, etc., in a very small memory footprint. I use it regularly, although I have not been using an
editor written in it. The standard book to get started in it is "Starting Forth" by Leo Brodie who's kind of a comedian. It's entertaining, and was very easy for me to understand. I picked it up and just flew with it. You can read it free at
https://www.forth.com/starting-forth/ which has a few updates but still has the original cartoons. Forth originally used 1KB blocks for source code but I think normal text files (which I use) are much more common today for Forth source code. I wrote my own assembler in Forth, and in its original, simple form took me one evening to write. I later realized that macro capabilities were innate, since the Forth system was already there and you could take advantage of its capabilities to make decisions, write its own code per your direction, etc..
Regardless of language though, I think 4K will be too limiting for some tasks. You could split a program into multiple tasks, but it would just add complexity. Perhaps you could leave the option for a task to take multiple 4K sections without splitting it up.