1

I have some complicated code with variables that use CamelCase. Would it be possible to display such variables with a hyphen (-) or underscore (_), but without modifying the actual text in the buffer. Change would be just for display.

Drew
  • 77,472
  • 10
  • 114
  • 243
Dilna
  • 1
  • 3
  • 11

1 Answers1

2

That's exactly what Glasses mode (M-x glasses-mode) does. See MixedCase words and the glasses package documentation (C-h p glasses RET).

Use M-x customize-group RET glasses RET to see the available customizations. Glasses mode uses _ as the sub-word separator by default, but you can use - or another character instead, or use no character but display the mid-word capital letter in a different color. Glasses mode can also convert from snake_case to camelCase on input, if what you're editing never uses snake case.

  • It works well for me. I would like to change the separator mark from my init file using elisp code. How should the change be? – Dilna Oct 03 '22 at 19:52
  • A problem I have with it is this. It is difficult to distinguish which words get changed. For instance, if one has a mixture of CamelCase, Under_scores one would not know which is modified and which is original. Particularly problematic when one is modifying the code. – Dilna Oct 03 '22 at 20:21
  • @konmi Use the customize interface to change the settings. Change the “Glasses Face” to make the capital letter in a different color of font. – Gilles 'SO- stop being evil' Oct 03 '22 at 21:14
  • How can I do with elisp for my init file? – Dilna Oct 04 '22 at 03:33
  • Another way I want to try is changing the background colour. – Dilna Oct 04 '22 at 03:48