SlickEdit Community
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
September 02, 2010, 11:46:18 AM  


Login with username, password and session length

Pages: [1]
  Print  
Author Topic: Highlight matching parens macro  (Read 4880 times)
chrisant
Community Member


Hero Points: 92
Posts: 784


« on: April 08, 2008, 09:40:06 PM »

Here is a macro that uses different colors to highlights pairs of matching parentheses on/near the current line, and extending outwards trying to find all related pairs of parentheses that appear to be part of the same expression.  I find this macro handy on long/complex expressions, maybe you will too.

Bind a key to the HighlightParens command (I happen to use the Ctrl-0 key).

Invoking the command repeatedly extends the color coding to cover the text between the parens, starting from the innermost level of nested parens and with each subsequent invocation progressively working its way to the outermost level of parens.  Mismatched parens are highlighted in red.

The timeout for the highlights, the max distance to scan for matching parens, and the colors can all be modified near the top of the macro file.
Logged
Graeme
Community Member


Hero Points: 116
Posts: 959


« Reply #1 on: April 09, 2008, 09:22:09 AM »

Nice work.

What's the idea of stream markers?  I notice if I turn on the parentheses coloring, then insert some lines before the highlighted line, the coloring gets removed correctly.  Is that the main benefit of stream markers compared with remembering line/column positions and using set-text-color?

How did you find out that stream markers could be used for this?  I guess line markers are for putting a bitmap in the margin.

Graeme
Logged
chrisant
Community Member


Hero Points: 92
Posts: 784


« Reply #2 on: April 09, 2008, 02:48:44 PM »

Stream markers is how all of the built in macro code I've been reading colors text (search, isearch, regex evaluator, dynamic surround, the built in as-you-type paren matching highlights).  I don't remember for sure how I first found stream markers, I think it was from examining the search/isearch highlights.  I don't know yet whether syntax color coding uses them.

Stream markers move as the text they are attached to move, and they overlay the underlying color rather than replacing it.  Both make it much easier to remove the coloring properly afterwards, but they also mean you can overlay your color only once and let the rendering engine take it from there - e.g. no need to reapply it yourself if text moves or if the window gets repainted etc.

I don't yet know if you can apply only a foreground or only a background color.  The cursor line coloring seems to only affect the background color, and it alpha blends with the selection color, so I suspect there may be a way to set foreground-only, background-only, or perhaps alpha blended colors.
Logged
Graeme
Community Member


Hero Points: 116
Posts: 959


« Reply #3 on: April 09, 2008, 05:41:50 PM »

Thanks chrisant.  Lisa should add this information to a "stream/line markers overview" topic in the macro user guide.

Graeme
Logged
Lisa
SlickEdit Team Member
Community Member
*

Hero Points: 19
Posts: 239


« Reply #4 on: April 09, 2008, 05:51:36 PM »

Thanks chrisant.  Lisa should add this information to a "stream/line markers overview" topic in the macro user guide.

Graeme


Thanks Graeme. I've added this to the todo list for the Slick-C docs.
Logged

Lisa
-------------
Please send comments about our documentation to docs@slickedit.com. All feedback is appreciated and receives a response!
asandler
Community Member


Hero Points: 16
Posts: 123


« Reply #5 on: May 27, 2008, 12:17:22 PM »

@chrisant Excellent macro! Very useful. With your permission, I'd like to post it on my macros for SE web-page.
Logged

Alexander Sandler
Alex on Linux
chrisant
Community Member


Hero Points: 92
Posts: 784


« Reply #6 on: May 27, 2008, 08:26:00 PM »

Sure, that's a good idea.
Logged
rdsuel
Community Member


Hero Points: 0
Posts: 10


« Reply #7 on: June 12, 2008, 10:25:37 AM »

I'd like to try this macro, but when I try to load it, Slick complains about the "loop" statements.  I'm using v11.0.2, is "loop" a new Slick-C command in SlickEdit 2008 or something?

-rdsuel
Logged
Lisa
SlickEdit Team Member
Community Member
*

Hero Points: 19
Posts: 239


« Reply #8 on: June 12, 2008, 10:39:47 AM »

I'd like to try this macro, but when I try to load it, Slick complains about the "loop" statements.  I'm using v11.0.2, is "loop" a new Slick-C command in SlickEdit 2008 or something?

-rdsuel

This was another statement added in SlickEdit 2008 (v13). Here is the documentation that will be in the upcoming release:

The generic loop statement is similar to that found in the Ada and D languages. The following statements are equivalent:

Code:
for(;;) { ... }

loop { ... }

Example:
Code:
status := search(":","@"); 
loop {
   if ( status ) break;
   get_line(line);
   messageNwait("found match line="line);
   status = repeat_search();
}

Another example:
Code:
defmain()
{
   i:=0;
   j:=0;
   loop {
      say("test, i="i);
      i++;
      if (i>1000) {
         break;
      }
      inner: loop {
         say("defmain: j="j);
         if (j++ > 750) break inner;
      }
      say("defmain: H1");
      if (i < 500) {
         continue;
      }
      say("defmain: H2");
   }
}
Logged

Lisa
-------------
Please send comments about our documentation to docs@slickedit.com. All feedback is appreciated and receives a response!
chrisant
Community Member


Hero Points: 92
Posts: 784


« Reply #9 on: June 12, 2008, 01:13:36 PM »

Attached a new version of the macro which uses "while(true)" instead of "loop".
Logged
rdsuel
Community Member


Hero Points: 0
Posts: 10


« Reply #10 on: June 16, 2008, 11:42:33 AM »

Thanks  ... nice macro!
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC

©1988-2008 SlickEdit Inc.   •  1 919.473.0070   •  1.800.934.EDIT
Contact Us   •   Privacy Policy   •   Terms of Use