Migrate from GitHub to SourceForge with this tool. Check out all of SourceForge's recent improvements.
Close

#144 replacing with new lines (\n)

Major
closed-fixed
NetBeans (62)
5
2011-06-11
2011-05-07
slither
No

When doing a replace that increases line count not all occurences are properly replaced.
By example I have:
void JavaObject::setObject(jobject object);
jobject JavaObject::operator()(const std::string& method, ...) const;
jobject JavaObject::operator()(jmethodID method, ...) const;
jobject JavaObject::operator[](const std::string& field) const;

Now issuing jVi command:
%s/;/{\n\n}\n/

The result is:
void JavaObject::setObject(jobject object){

}

jobject JavaObject::operator()(const std::string& method, ...) const;
jobject JavaObject::operator()(jmethodID method, ...) const;
jobject JavaObject::operator[](const std::string& field) const;

Instead of expected:
void JavaObject::setObject(jobject object){

}

jobject JavaObject::operator()(const std::string& method, ...) const{

}

jobject JavaObject::operator()(jmethodID method, ...) const{

}

jobject JavaObject::operator[](const std::string& field) const{

}

I have to repeat the command multiple times to get everything right

Discussion

  • Ernie Rael

    Ernie Rael - 2011-05-08
    • assigned_to: nobody --> err
     
  • Ernie Rael

    Ernie Rael - 2011-05-08

    Interesting. If you have a bunch of empty lines after the initial text, then the command works fine. I'll check it out.

     
  • Ernie Rael

    Ernie Rael - 2011-05-08

    The following works:
    g/;/s/;/ {\n\n}\n

     
  • slither

    slither - 2011-05-10

    Specifying exact line indexes also works but in special way. For the above example I would need to type:
    1,13s/;/{\n\n}\n/
    It means that I have to know, how many lines will be added.

    Anyway - the "s" command definatelly has some issues when number of lines changes. Do I have to mention that works as expected (meaning operation is performed on the content of buffer before execution and doesn't care about modification made by the command)?

     
  • Ernie Rael

    Ernie Rael - 2011-05-10

    The very simple fix is in VCS as of a few days ago. I'll put out a early access release this week.

    > Do I have to mention that works as expected (meaning operation is
    > performed on the content of buffer before execution and doesn't
    > care about modification made by the command)?

    I'm not certain what you mean, does it have something to do with that in the current release, if you do
    %s/;/{\n;\n}\n/
    (note the ';' between the '\n') then things go crazy.

    BTW, using '\n' in the replacement string is a new feature. I had fixed the 'g' command, but forgot about the 's' command by itself.

    This will all have to be revisited if I ever allow '\n' on the match side.

     
  • slither

    slither - 2011-05-10

    >The very simple fix is in VCS as of a few days ago. I'll put out a early
    >access release this week.
    Great! I really appreciate your work.

    >I'm not certain what you mean
    I only meant that original vim acts like it first finds out what modifications to do and then applies it on the buffer. From what I see, I assume that jVi does modifications on the fly what can lead to strange behaviour.

    > %s/;/{\n;\n}\n/
    This is a good example - the pattern we want to replace occurs in replacement string. If you modify buffer on the fly, it leads to infinite loop of replacements.

    I don't know if and how it can be avoided as I have no time to get familiar with either NetBeans API or your code. I'm only thinking 'aloud' ;)

     
  • Ernie Rael

    Ernie Rael - 2011-05-10

    > I don't know if and how it can be avoided

    The fix handles this as well. 'g' and 's' commands are now two pass.

     
  • Ernie Rael

    Ernie Rael - 2011-05-10
    • status: open --> open-fixed
     
  • Ernie Rael

    Ernie Rael - 2011-06-11
    • status: open-fixed --> closed-fixed
     
  • Ernie Rael

    Ernie Rael - 2011-06-11

    Available in early access release

     

Log in to post a comment.