Adventures in writing a text editor, part 2
Adventures in writing a text editor
I was thinking on the drive into work about a few things:
- 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.
- kepp could really the text mode for kge, so I can reuse a lot of the editor components. Time to switch the repo over.
-
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.
-
I can start with using a std::vector<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:
- Import kepp into kge.
- Remove the dependency on klib. It's a complication I don't need right now.
- Update Frame to have a backing buffer^wcontents.
- Rename Frame->Buffer.
- Add Frame to store Buffers.
- Add an Editor that stores a Frame.
- 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.