The Mastering Emacs ebook cover art

Emacs 28 Edition is out now!

Read a Free Sample

Learn More

Making CamelCase Readable with Glasses-Mode

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.

Further Reading

Have you read my Reading Guide yet? It's a curated guide to most of my articles and I guarantee you'll learn something whether you're a beginner or an expert. And why not check out my book?

Subscribe to the Mastering Emacs newsletter

I write infrequently, so go on — sign up and receive an e-mail when I write new articles