how to use colors to visually accentuate the function the cursor is in?

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-register because you need to control the order of fontification.

    HTH!


    Which-function mode is used to highlight the current function. Try it to see if it helps you, and see if this post helps you:

    Emacs Setting which-function-mode

    链接地址: http://www.djcxy.com/p/10956.html

    上一篇: 我怎样才能追捕这些在我的场景中扭曲对象的OpenGL调用?

    下一篇: 如何使用颜色来直观地强调光标所在的功能?