Is this not supported out of the box?
It is; see (emacs) Useless Whitespace
.
My current settings are:
(global-whitespace-mode)
(setq whitespace-style '(face trailing lines tabs big-indent))
As per the aforementioned manual node, you're only missing an empty
element for your whitespace-style
setting. Quoth C-hvwhitespace-style
RET:
empty empty lines at beginning and/or end of buffer
are visualized via faces.
It has effect only if ‘face’ (see above)
is present in ‘whitespace-style’.
In fact, empty
is present in whitespace-style
by default. So, you just need to modify your setting to include it again:
(setq whitespace-style '(face trailing tabs lines empty big-indent))
I think the general rule would be:
After the last non-whitespace character, accept one newline, then highlight all whitespace after.
Note that the empty
setting for whitespace-style
is slightly more general than this, in that it also applies to lines at the beginning of the buffer.
A relevant setting which only applies to the buffer's end, but only in the fringe of graphical frames, rather than by highlighting buffer contents, is the buffer-local user option indicate-empty-lines
, which is also documented in the aforementioned manual node.
indicate-empty-lines
for a more subtle indication.