Subword Mode

This should probably be a Red Meat Friday post but I really hate camel case. It’s hard to read, hard to type, and looks ugly. Among it’s many other sins, it has made abominations such as subword mode necessary.

Over at Emacs Elements there is a (very) short video on using subword mode. There’s not much to say. It’s a way of having forward-word skip to each capitalized segment of a camel case word. The video recommends enabling it via a hook function for whatever programming modes you use. You can, of course, toggle it manually by invoking Meta+x subword-mode.

Some people love this mode but—the awfulness of camel case notation aside—I’ve never seen the point of it. Yes, occasionally it’s convenient to have forward-word stop at each subword of a camel case identifier, but most often you want to treat the camel case word for what it is: a single symbol. In those rare cases (heh) where you want to put the cursor on one of the subwords, it’s easy enough to skip to the head of the composite symbol and move the point to the correct spot. Or you could use something easier like jump-char-forward. Regardless, it’s hard to see the utility of subword-mode.

Still, people differ in their needs and if this is something that’s useful for your workflow, Emacs, as usual, has you covered. The video is only two minutes, 25 seconds so you should be able to slip it in easily.

UPDATE [2023-09-01 Fri 12:39]: Mickey writes to tell me that I may have been too harsh on subword mode. What really happens when you invoke it is that the definition of a “word” is changed to encompass the subwords of SomethingLikeThis. That means that not just forward-word but any word-based command can stop and act on the subwords.

That makes it more useful than my original post suggested but I still think that usually you want to treat “SomethingLikeThis” as the single symbol that it is and subword mode is almost always overkill. As a real world, real time example, I misspelled SomethingLikeThis as SomethingLikrThis but rather than toggling on subword-mode and moving back to the error, I simply called jump-char-backward and went right to the error.

This entry was posted in General and tagged . Bookmark the permalink.