0

I use whitespace-mode, intend with tabs (colored pale yellow, which is what I want) and I am wondering about the situation where there is an empty line inside an indented block (see image below).

I would like the empty line to also start with some pale yellow highlighting, of the same length of the surrounding indentation, in order to make it easier to understand which parts of the code belong to which block, but I do not want to add an actual tab in the file. Is there an easy way to do that?

enter image description here

5
  • Normaly the background color is a property of text, but if there is no text (or whitespace), how to apply the property? – jue Oct 7 '20 at 20:11
  • @jue Yes, I realize that too, but maybe there is a way to have some tabs that do not get saved to the file, or something like that? I am not very familiar with the internals of emacs. – Guillaume Brunerie Oct 7 '20 at 20:39
  • 1
    Possibly with Overlays, but also possibly it is complicated to implement. – jue Oct 7 '20 at 20:44
  • Thanks! I might give it a try – Guillaume Brunerie Oct 7 '20 at 20:50
  • I should have sayed "perhaps with Overlays". I'm no native english speaker. – jue Oct 7 '20 at 20:55
0

I couldn’t find a built-in way to do it, so I implemented it myself as a minor mode (see here). Feel free to try it out if you have the same issue. I have been using it full time at my day job for a few weeks/months now, and it works perfectly and makes my code look so much better!

Technical details:

The way it works is with text properties, which allow one to change the way certain characters are displayed (without actually changing the contents of the buffer). So basically whenever there are two consecutive new lines, I put a text property on the second one that displays it as a certain number of tabs followed by a new line, the number of tabs being taken from the first non-empty line that follows.

Those text properties are automatically updated after any change, and they are also automatically removed from the region when the mark is active, as for some reason it was still showing through the region face.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.