Diary 2019-05-01

By Max Woerner Chase

One thing I ended up working on briefly over the weekend was an attempt to come up with an alternative to Sublime Text's default "reindent" command that is sometimes triggered by pressing tab.

The general problem of "I don't like what Sublime Text does here by default" is something that I've had cause to think about for years. To recap that question, I asked "Hey, how do I make it only indent one tabstop?", got some discussion that I feel was... not helpful, figured out for myself how to get the behavior I wanted, and was happy with it, then blew back in a few days ago, years later, with a link to a Gist that does something completely different than what I was asking for.

Let's break this down:

I'm going to try to systematize the issues I'm having here. Let's suppose, given a blank line in front of a given user at a given moment, that there exists a "user-desired indentation" (UDI), a quantity of whitespace that that user at that moment, desires to be inserted, should they press the tab key. What can we conclude?

This, then, is what motivated my original question: if we assume that "one tab" is always a possible UDI, then "one tab" is the best choice of what to insert. The resulting behavior was good enough for me for over two years. So what changed?

Well, I'm actually sort of A/B testing myself, with the command I wrote active on one machine I use, but not the other. That said, the idea came to me when I was following the roguelike tutorial I love to complain about, and realized that it would be nice—not essential, but nice—if pressing tab on a blank line between two blocks at the same indentation, brought it to that same level. And then I considered the motivating case for the StackOverflow question: "Given a method that ends in a highly indented block, how do I write a new method after it without hitting the delete key a bunch?" and I thought "What if the class is in an indented block, itself? Supposing I'm inserting a method between two methods, I know I don't want to use any less indentation." After years of being fine with the behavior I'd written, I realize that it was possible to get a higher lower bound on the desired indentation: to reduce deficits without risk of excess.

So anyway, that's what I was doing Sunday night instead of sleeping. Whoops!