# 2023-10-11 ## Adventures in writing a text editor I was thinking on the drive into work about a few things: 1. Now that I have a frame, what comes next? The next logical step is have an Editor to hold the frames, I think. Actually, a Window - which leads to my next point. 2. kepp could really the text mode for kge, so I can reuse a lot of the editor components. Time to switch the repo over. 3. Thinking about #2 makes me think: you basically have a few subsystems here. The ones that I can think of are + The Frame/File subsystem: basically, the editor's subject. + The Window as a container holds a map of names -> frames, as well as the currently active frame. + The current KeyboardMode defines how input is processed. + In the case of kepp, you need a TerminalMode. I think the GUI version will have something similar. + You need an Editor to tie it all together. 4. I can start with using a std::vector> to store data in the Frame to start with. This is where terminology starts to trip me up a little. In emacs, a frame is a window, and a buffer is what I call a Frame. However, I think of the buffer as a member of Frame. Maybe I can call it contents, rename Frame->Buffer, rename Window->Frame. Then the terminology will be more consistent with what I know. ### On files After working with the Dictionary in klib, I briefly thought about memory mapping, but that brings a whole host of issues and it honestly doesn't make sense because you don't need to _immediately_ reflect changes from the editor to the file. I think you could have an autosave timer going, but I think you can just keep changes in memory until you're ready. This leads to a what I think is the next sequence of events: 1. Import kepp into kge. 2. Remove the dependency on klib. It's a complication I don't need right now. 3. Update Frame to have a backing buffer^wcontents. 4. Rename Frame->Buffer. 5. Add Frame to store Buffers. 6. Add an Editor that stores a Frame. 7. Start working on KeyboardMode. Next challenge: getting kge to build on my work Ubuntu machine, which uses NVIDIA drivers. I'm taking the time to make the backends configurable; the code is sdl2/opengl3 specific right now, but that's easy enough to abstract out. Another note: I'm using CLion a lot for development and it's pretty annoying that it flushes to disk every few seconds. This reinforces my thoughts about how to back files in the editor.