tags:

views:

101

answers:

2

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.

+1  A: 

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

atlpeg
+2  A: 

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.

Peter Hart
These directions have helped a lot. As suggested, the faces provided don't get me exactly what I want however; I need the text color to be darker in order for it to blend into the black background. I don't know how to define a new face from scratch (yikes?) nor do I know how to modify an existing one. Lisp isn't among my active languages.What's even more confusing is that when I try out the various faces provided in emacs in a vain attempt to find the exact right one, it seems to ignore the background color defined in that face. I guess it's the major mode overrides the highlight face??
Adam Morris
Update: I just discovered the customize-face command, which I found at http://stackoverflow.com/questions/1076503/change-emacs-syntax-highlighting-colorsIt was easy enough setting the font face color to very dark grey, and now it works exactly as I wanted.While I was at it, I also set it so that any def or class lines get a bigger font. So nice!
Adam Morris