#include color_class c_comment_color = {COLOR(colGREEN, colBLACK), MCNORM}; /*****************************************************************************/ /* Command color_c_comments searches through the whole buffer and adds color to comments. It "colorizes" both new and old style comments. by Morgwn McCarty on 8/12/92 */ command color_c_comments() { int orig_point, old_point; spot pos1, pos2; orig_point = point; /* save our current position */ point = 0; /* go to top of buffer */ while (do_searching(0, "/")) /* search for the '/' char */ { switch(curchar()) /* now check the next char */ { case '/': /* new c++ style comments */ pos1 = alloc_spot(); *pos1 = point - 1; end_of_line(); pos2 = alloc_spot(); *pos2 = point; add_region(pos1, pos2, color_class c_comment_color, REGNORM, 0); break; case '*': /* old c style comments */ old_point = point; if (do_searching(0, "*/")) /* search for end of comment */ { pos1 = alloc_spot(); *pos1 = old_point - 1; pos2 = alloc_spot(); *pos2 = point; add_region(pos1, pos2, color_class c_comment_color, REGNORM, 0); } break; } } point = orig_point; /* restore original point */ } /*****************************************************************************/ /* C_mode_hook has been modified to call color_c_comments. This will make epsilon automatically color your C program when it is read in via "dired", etc.. */ c_mode_hook() { color_c_comments(); } /*****************************************************************************/ /* Indent_for_comment has also been modified to automatically colorize a new comment. */ command indent_for_comment() on reg_tab[ALT(';')] { int pt = point, scom; spot pos1, pos2; /* used for colorizing -mm */ if (has_arg) { if (iter < 0) { to_begin_line(); if (!re_search(RE_REVERSE, comment_start)) { point = pt; error("No previous comment found."); } } if (!re_search(RE_FORWARD, comment_start)) { point = pt; error("No comment found."); } iter = 0; return; } if (to_line_comment()) { /* line has comment */ if (pt > point) { /* if we were in the comment */ scom = point; /* remember where comment was */ point = pt; /* stay there after */ save_spot point = scom; to_comment_column(); /* now reindent it */ } else { to_comment_column(); /* reindent it */ re_search(RE_FORWARD, comment_start); } /* go to start of comment */ } else { to_comment_column(); /* make a new comment on this line */ pos1 = alloc_spot(); /* beginning of color stuff -mm */ *pos1 = point; stuff(comment_begin); pt = point; stuff(comment_end); pos2 = alloc_spot(); /* end of color stuff -mm */ *pos2 = point; add_region(pos1, pos2, color_class c_comment_color, REGNORM, 0); point = pt; /* insert comment text here */ } }