Making CamelCase Readable with Glasses-Mode
If you’re working on a codebase that makes use of CamelCase identifiers LikeThis or evenWorseLikeThisAbstractFactoryFactory you can make them readable by splitting up the words with M-x glasses-mode. glasses-mode will insert a virtual underscore separator between the conjoined words, so fooBarBaz will look like foo_Bar_Baz.
The changes are not permanent and Emacs will keep track of the virtual separators and ensure they are never accidentally saved to disk.
When glasses-mode is enabled, you should continue following the CamelCase style as Emacs will automagically insert the virtual separator, as needed, when you type a capitalized character.
There’s a handful of configurable options you can tweak to personalize glasses-mode. To access them, type M-x customize-group RET glasses.
Mastering Emacs
> The changes are not permanent and Emacs will keep track
> of the virtual separators and ensure they are never
> accidentally saved to disk.
In case that still sounds scary to anyone (it certainly does to me
I thought I’d point out that the separators do not actually exist in the buffer text at all, so it’s not possible to save them accidentally or otherwise.
This is achieved with overlays, which modifies the visual appearance of the buffer without actually changing the text.
Indeed. Overlays in Emacs are the bee’s knees. I’d never use glasses-mode myself but at least the option is there for people who want to use it.
Looks like this works as visual-line-mode, the new virtual line breaker for emacs 23. Have you tried it? Much better than fill-paragraph or autofill-mode: it generates virtual new lines that are not saved to the buffer.
I don’t program using CamelCase (well, I do, but with very short function names), so I don’t have any use for this… For now. Most emacs utilities that seem like not useful at first end up being pretty useful once you get the “aha!” moment
Cheers,
Ruben
In my blog: The Emacs 30 Day Challenge: Use just emacs for (almost) everything for 30 days
glasses-mode is one of those crazy inventions you’d only ever see in Emacs. It may not be the world’s most useful feature, but it highlights the power and flexibility of Emacs as a text editor.