Author Topic: Paren matching in strings (v9)  (Read 761 times)

Margaret

  • Community Member
  • Posts: 70
  • Hero Points: 0
Paren matching in strings (v9)
« on: September 04, 2016, 07:23:57 pm »
I'm sitting here debugging regexen, and thinking how lovely it would be if there were a switch to toggle whether parens-matching happens even within strings.

Graeme

  • Senior Community Member
  • Posts: 2389
  • Hero Points: 314
Re: Paren matching in strings (v9)
« Reply #1 on: September 05, 2016, 11:51:01 am »
I'm sitting here debugging regexen, and thinking how lovely it would be if there were a switch to toggle whether parens-matching happens even within strings.
I don't understand.  Could you please give an example?

Margaret

  • Community Member
  • Posts: 70
  • Hero Points: 0
Re: Paren matching in strings (v9)
« Reply #2 on: September 05, 2016, 01:22:04 pm »
I don't understand.  Could you please give an example?
Right now in C or PHP or some other language you might (I do) have the editor flag the matching open paren so that when you've a complicated expression with lots of nesting you don't discover the hard way that you've put in the wrong number of closes or closed the wrong subexpression.  I find, for example, that in expressions with more than 3 levels of nesting, I'll either leave off one or put in one too many.  The little blip of light (or its absence) helps avoid that problem.

But the feature doesn't work inside strings, and one passes regexen to (e.g.) preg_replace() as strings, which is how I came to think about it yesterday, squinting at the screen trying to make sure "by hand" that I'd got all the nesting correct.

Tim Kemp

  • Senior Community Member
  • Posts: 536
  • Hero Points: 90
Re: Paren matching in strings (v9)
« Reply #3 on: September 05, 2016, 01:49:19 pm »
Interesting. I'd probably temporarily remove the quotes or copy the contents of the string to a temporary buffer. Even though the code will be garbage at that point, the paren matching should work.

Graeme

  • Senior Community Member
  • Posts: 2389
  • Hero Points: 314
Re: Paren matching in strings (v9)
« Reply #4 on: September 06, 2016, 12:25:19 pm »
Have you seen this macro
https://community.slickedit.com/index.php/topic,3236.0.html
It highlights matching parentheses in different colours.  I don't think it matches [] <> or {}.

It wouldn't be hard to write a macro to copy the current string to a temporary edit buffer in a new window, remove the quotes and call HighlightParens() on it.

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2834
  • Hero Points: 429
Re: Paren matching in strings (v9)
« Reply #5 on: September 06, 2016, 02:28:16 pm »
Paren matching does work in strings.  However, there may be a scenario where the parenthesis highlighting is not very visible on account of the string color it is overlaying being very similar to the paren matching color.  Try it in a default config with the default color scheme, you'll see that it does in fact work.

Margaret

  • Community Member
  • Posts: 70
  • Hero Points: 0
Re: Paren matching in strings (v9)
« Reply #6 on: September 07, 2016, 09:01:53 pm »
Paren matching does work in strings.  However, there may be a scenario where the parenthesis highlighting is not very visible on account of the string color it is overlaying being very similar to the paren matching color.  Try it in a default config with the default color scheme, you'll see that it does in fact work.

It doesn't in v9.  Or at least not my copy of v9.  I just did the experiment you suggested and stuck in a couple of parens -- it just sat there.

But if it works in later versions, that'll be nifty -- if it's in v13, so I can get it for XP.