Inspired by ia Writer’s focus mode, I’m interested in using font + background colors in emacs to accentuate the function the cursor is in and visually cue the rest of the code as the background (I use C++, but it would be nice if this worked regardless of the programming language).
Ideally the font color of code outside the function would be dimmed (this is how focus mode works). A simpler solution probably be to change the background color slightly for the function that the cursor is currently in. How can this be done?
Nothing like this exists AFAIK. If you want it to write it yourself, here is a sketch:
Write a routine that determines the boundaries of the current function. The easiest way to do this is with
(bounds-of-thing-at-point 'defun).Write a routine that, when given the bounds of a region, gets the background face property of the region of the region, darkens it, and applies the new face to the region.
Override
font-lock-fontify-region-function(see here) with a routine that calls the original value of this variable, differences the region given with the region of the current defun (using #1), and then applies routine #2 to the remaining region.I would prefer overriding font lock to, say, using
jit-lock-registerbecause you need to control the order of fontification.HTH!