Author Topic: #if 0 commenting  (Read 4822 times)

mikesart

  • Community Member
  • Posts: 59
  • Hero Points: 11
#if 0 commenting
« on: March 06, 2008, 04:41:26 am »
I've really missed the ability to color blocks of disabled code due to preprocessor directives for a while now. There was a thread on this quite a while back here:

http://community.slickedit.com/index.php?topic=158.msg4394#msg4394

So I posted a feature request in the SE 2008 beta forum and Clark was kind enough to point out this was already possible and double kind for not calling me an idiot.

In any case, I ripped a ton of code out of SE v12 seldisp.e, replicated it in the attached defs_color.e file, and replaced some of the hide code with _StreamMarkerAdd color code. To run, load it up and execute defs_color() to color the code blocks. (Arguments should be eerily similar to the existing SE preprocess command. :)) defs_uncolor() should remove the highlighting. It currently uses the no-save color for the highlighting (CFG_NOSAVE_LINE) way down at the bottom of the file. This works well for me but should be fairly trivial to change if others don't like it.

I'm not experienced with Slick-C, so I very likely have done bad things(tm). But it appears to work on a bunch of the C++ files we've got, so perhaps this will be useful to some other folks after everyone points out the bugs and it gets fixed.

StephenW

  • Senior Community Member
  • Posts: 186
  • Hero Points: 21
Re: #if 0 commenting
« Reply #1 on: March 06, 2008, 08:25:53 pm »
This looks really useful, thank you.

mikesart

  • Community Member
  • Posts: 59
  • Hero Points: 11
Re: #if 0 commenting
« Reply #2 on: March 10, 2008, 05:58:37 pm »
I stuck defs_color() in a _buffer_add_* routine to color all files on load, and it was unusably slow for some large files. After a bit of profiling, it turned out most of the time was spent in defcolor_isdefined(). Hashing the defines dropped that about 4.5x (winuser.h went from 2122ms down to 440ms). Even with that change, winuser.h was still taking a bit too long to load and at this point I believe it's due to processing after defs_color() returns. So I added the ability to early out (and leave the file uncolored) when a threshold has been hit based on the number of _StreamMarkerAdd() calls. This limit is configurable via the _DEFS_HIDE_LINE_COUNT_MAX define in the file. There also appears to be a length limit of ~8100 for the _StreamMarkerAdd() function which I fixed by passing in max 4096 length chunks.

I've now got the following and it appears to be working fairly well at the moment.

    void _buffer_add_defs_color()
    {
       defs_color("-L __cplusplus BLAH=5");
    }

Another option would be to just ignore all standard header files. Something like this possibly:

    if(!pos('\vc\platformsdk\include\', p_buf_name, 1, 'I'))
    {
       defs_color("-L __cplusplus FOOBAR=15");
    }

I'm going to try the first option for a while and see how usable it is.