#425 Delimiter select

Next_major_release
closed
nobody
None
7
2014-08-28
2012-09-13
Andreas Jonsson
No

This was the second most popular idea on the IdeaTorrent:

https://sourceforge.net/apps/ideatorrent/notepad-plus/ideatorrent/idea/169/

This patch allows you to define two custom delimiters, one "left" and one "right", so that Ctrl+Doubleclick selects all text between the delimiters. By default I've set the left delimiter to '(' and the right to ')', but obviously there are many useful choices (curly braces for C programmers, brackets for HTML, etc).

The delimiters can be set by selecting a character and using Settings -> Delimiter selection -> Set left/right.

The flag "entire document" (in the same menu) controls whether or not the program makes the selection on the current line or if it looks for the delimiters in the entire document.

Discussion

  • Realized today I uploaded the wrong patch. delimiterselection2.patch is the complete one.

     
  • Don HO
    Don HO
    2013-06-08

    • status: open --> accepted
    • Group: --> Next_major_release
    • Priority: 5 --> 7
     
  • Don HO
    Don HO
    2013-06-08

    Hi Andreas,

    Sorry for not seeing your patch and thank you for the patch.
    It could be a very handy feature. However, I'm wondering why you choose the "command mode" to set delimiters instead of conventional (preference) way?

    Don

     
  • Don HO
    Don HO
    2013-06-08

    I just found a bug:
    The imbrication case is not handled. ie. Ctrl+ double click into
    (size_t i = 0; i < _buffers.size(); i++)
    only "size_t i = 0; i < _buffers.size(" are selected.

    Don

     
  • To be honest, Visual Studio Express doesn't support resource editing (and I didn't want to work out the positions manually), so I went for a menu option instead. The attached patch should fix the problems with nested delimiters.

     
    Last edit: Andreas Jonsson 2013-06-09
  • Don HO
    Don HO
    2013-06-09

    Andreas,

    I'll make them available in preferences if you don't see more advantage as command items.

    Thank you for the fix, it works but partially.
    if you ctrl + double click on "i++" in (size_t i = 0; i < _buffers.size(); i++), it won't work.

    I don't have the solution (yet), have you any one already?

    BTW, there may be another bug if right delimiter and left delimiter are the same (for example, " or ' for string delimiter). In this case, it should disable the imbrication. What do you think?

    Don

     
  • The problem is that the algorithm always scans left first, looking for the first occurrence of the leftmost delimiter. (As an aside, I assume I chose this way because all the languages I speak are written left-to-right). To deal with the case of "i++" here we need to scan to the right first. But of course, if we just change this we will break case where the user doubleclicks on "size_t" etc.

    So we need an extra step where the algorithm decides if it should scan right of left. I think this will work:

    Start by scanning left. If a rightmost (sic) delimiter is encountered before a leftmost delimiter, set mode = RIGHTSCAN. Otherwise mode = LEFTSCAN.

    If mode == LEFTSCAN, then use the current algorithm. If mode == RIGHTSCAN, use the current algorithm with the change that we scan right first (that is, we attempt to find the rightmost delimiter before we bother with the matching leftmost delimiter).

    I'll implement this (should have the time for it in a few days) and send the patch.

    I agree that if both delimiters are the same, then the original method (in
    delimiterselection2.patch) should be used.

     
  • Scratch that, won't work if you click on "_buffers" in this example:

    (size_t i = function(); i < _buffers.size(); i++)

    I think, however, that the "smallest pair of parentheses which include the clicked position" should work.

    I.e. start at clicked position. Go left until you find a left delimiter. Then go right (from the left delimiter's position) until you find a matching right delimiter (it must be matching). If the clicked position lies between these two delimiters, done. Otherwise continue looking for a new left delimiter and repeat until one is found or the buffer is exhausted.

    Will try to implement this. Should be possible with a single pass through the buffer.

     
    Last edit: Andreas Jonsson 2013-06-10
  • Don HO
    Don HO
    2013-06-11

    If double click on l in
    (olo(eye))
    the algo doesn't work.
    But I'm not sure by "it must be matching" you means.

    Don

     
  • This patch handles all known problematic cases.

     
    Last edit: Andreas Jonsson 2013-06-11
  • Don HO
    Don HO
    2013-06-14

    The patch seems works better.
    Commited.
    Thank you Andreas for your patch.

    Don

     
  • Don HO
    Don HO
    2013-07-10

    • status: accepted --> closed