Tutorial :Customizing emacs to dim or de-highlight one-liners in code



Question:

I program extensively in Python, and instead of using fancy debuggers I just use lots of print statements to figure out what my program is doing. I've set it up so that a typical function looks like this:

def do_something(*args, **kwargs):      verbose = True      verbose and print("Entered do_something with args: {0} and kwargs: {1}".format(args, kwargs))      for a in args:          verbose and print("Looping with {0}".format(a))          ...  

The idea is that since all my "debugging statements" are all on one line, grepping them out is easy enough if/when the time comes. Also, the logic lets me turn certain debugging statements on and off for each function, allowing me to customize what I want to see output into the console.

Anyway, what's annoying me is that they clutter up the place. I want to focus more on the actual code than on my debugger statements when glancing through. Hence, I wonder if emacs is capable of doing some sort of macro that says:

"Change the font color of any line that begins with "verbose" to grey" With the caveat that "begins with" here really means "after ignoring the leading whitespace."

So is it possible to "de-highlight" those verbose statements? Or maybe a macro that fill hide any such one-liners?

I'm a newbie with emacs, so be explicit :) I use Aquamacs on Mac OS X 10.6 if that makes any difference.


Solution:1

I believe hi-lock-mode will do what you need - it will allow you to highlight lines of text with a specific face. Documentation is here:

http://www.gnu.org/software/emacs/manual/html_node/emacs/Highlight-Interactively.html

In principle, once you've enabled hi-lock-mode (e.g. M-x global-hi-lock-mode <RET>), you should be able to use c-x w l verbose <RET> <facename> <RET> to get it highlighted, where facename is the face (font/color/etc.) that you want to use to highlight this. You would have to create a face to do this. It could be that hi-lock has a default face that might work (M-n to go through them after the first <RET>).

However, I'm not sure how (or if) hi-lock-mode and font-lock mode work together - it might be that this won't work for a highlighted source file, and I don't have a copy of emacs on this machine in order to determine the whether this works, and I don't use Aquamacs at all, but this should at least give you something to try.


Solution:2

Read about highlight-lines-matching-regexp in help. If you choose the right face this will do what you want.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »