Today I spent some time implementing a piece tree. It's not really a tree yet. It's more like a linked list. But I think the interface will be the same.
I've been curious about the piece tree for a while after having read a lot about it. And what better way to learn more and solidify that understanding than by implementing it? After getting a simple implementation working, I wanted to use it in the rest of rlworkbench and that work felt very hard. I was disappointed.
But I think I achieved something important that I didn't realize at first. I've never used a piece tree before. I've just read about it. Now I actually have an implementation in C. And I know how it works. I have advanced one step. Previously, my brain was focused on how a piece tree works and the benefits that it can give. Now that I actually have one, my brain can start thinking about how to use it in the context of rlworkbench.
I also got bogged down in details of C. And tried to reach perfection. That never ends well. Perhaps it's time to go back and use the application and work on improving what actually hurts the most. Right now, that might be that the copy & paste buffer has a memory limit. So if you try to copy or paste text that is too large, the application will crash. I have to figure out how to extend my arena implementation to allow arbitrarily much memory and how to represent strings spanning over multiple memory chunks. The piece tree might be one solution. But perhaps there are simpler solution for this particular problem. But now I have one more tool in my toolbox.
in #rlworkbench
I've implemented a function to filter the current selection through an external program in rlworkbench. Here is a demo of it.
Right now, the filter program is hard coded to one that formats C code.
One idea with this external formatting is that you could spend more time inputing text that actually does something instead of being distracted by formatting issues.
in #rlworkbench
I've implemented an special select mode in rlworkbench that simplifies selecting different portions of a document. Here is a demo of it.
The select mode is entered by pressing ctrl+l for se(l)ect. The mode is a quasimode meaning that it is only active while the 'l' key is still pressed. (The ctrl key can be released.)
In the select mode buttons to different things:
Pressing 'r' extends the selection to the current (r)egion leaped over
Pressing 'e' extends the selection to lin(e) boundaries
Pressing 'a' extends the selection to p(a)ragraph boundaries
The editor is also in select mode when clicking and dragging with the mouse. So the same keys can be used there. (That is why all the keys are on the left side of the keyboard, since, for me, I operate the mouse with the right hand.)
Having an explicit select mode frees up more keys for select operations. So far I find it a little uncomfortable sustaining the 'l' key, but I feel like it has potential.
I've implemented selection of text with the mouse in rlworkbench. Here is a demo.
The selection goes into the X11/Wayland "primary selection" clipboard which can be pasted with the middle mouse button.
Sometimes when writing a document, I do that by copy and pasting text from various sources. I do that with the mouse. So it has been very convenient to be able to use the mouse in rlworkbench as well. It's starting to feel more and more like a "native application".
in #rlworkbench
Today I learned that copy and paste only works if the program that you copy from is still running.
The SDL API documentation gave me the clue that i might work like this. Because in some situations, you need to provide a callback to transfer data to the clipboard.
I wonder if this is only on Linux, or other operating systems as well?
in #rlworkbench
Last month I decided to try to make rlworkbench a fully modeless editor.
In theory, I get why modeless editing is good. However, I'm a long time, happy Vim user. Vim is probably the most common example of a modal editor. The opposite of modeless. Despite that I want to try. This is a note about my current thoughts and experiences.
One thing that I like about editing in Vim is that I seldom have to press multiple keys at once. That is comfortable for my hands and fingers. My right arm is quite sensitive to bad ergonomics. For example, I often feel a slight pain after working on a laptop keyboard for an hour or so. I'm afraid that a modeless editing interface can not preserve this ergonomics.
In Vim, you are by default in "normal mode" where key presses don't usually insert characters but instead perform operations such as moving the cursor. With a modeless editor interface, you are by default in "insert mode" where key presses insert characters. Now that rlworkbench has a modeless editing interface, I'm sometimes afraid of accidentally inserting characters. Maybe I just have a bad habit of moving the cursor around and I should stop doing that. However, the feeling is that always insert mode feels a little scary.
In modeless editors the default mode is insert mode, and you issue commands by holding down control for example. Why is that? Can we invert that so that the default mode is "command mode" and you have to press and hold a key to insert characters? My guess is that I spend more time navigating than typing.
The Humane Interface (p. 59) argues that the hope is that most time is spent creating content (aka insert mode) and that should be as easy as possible. But I wonder if that is really true. Issuing commands can create content as well, right? For example, there might be a command to format a piece of source code. The formatting might be important for readability. Making the content more readable. Isn't that then part of "creating content"?
This is a short note about my experience with C.
I've previously written about how I feel that C slow me down. Partly because it is a lower-level language than I'm used to. Partly because I don't know it that well.
But yesterday when I worked on rlworkbench I felt that making a change was not that hard. It might even have felt slightly easier.
This feels like a breakthrough for me in my C journey. Perhaps I've learned C well enough for it to not be in my way? Perhaps I've got enough primitives implemented so that I can do some high level programming without more effort? Perhaps the C programming paradigm is more productive? I don't know. But I'm starting to like C more and more.
in #rlworkbench #c
I've implemented the ability to extend the selection to line boundaries in rlworkbench.
This can be used to more easily select a number of lines and do operations on them.
I plan to extend this mechanism with more text objects. Things that come to mind are word, sentence, paragraph, and function if you are writing code.
in #rlworkbench
I've implemented copy and paste in rlworkbench, and this is a demo of the current state.
You can make a selection as I demonstrated in the previous demo. Then you can copy that selection with ctrl+c and paste it with ctrl+v.
This also works with external programs.
The next step in copy paste is probably to allow selection of text with the mouse which puts the selection in a clipboard that can be pasted with the third mouse button.
Copy and paste felt like a big step towards a usable editor. Especially when writing code. I often copy and paste code and make small modifications. Now that is possible in rlworkbench.
in #rlworkbench
in #rlworkbench
I've just got selection working in rlworkbench and this is a demo of the current state.
The navigation and selection mechanism is taken from the Canon Cat. You navigate with a kind of incremental search called LEAP. The text that you just LEAPed over can be selected and deleted.
in #rlworkbench
in #rlworkbench
in #rlworkbench
in #rlworkbench
in #rlworkbench
in #rlworkbench
in #rlworkbench
in #rlworkbench
in #rlworkbench
in #rlworkbench #c #aoc
What is Rickard working on and thinking about right now?
Every month I write a newsletter about just that. You will get updates about my current projects and thoughts about programming, and also get a chance to hit reply and interact with me. Subscribe to it below.