RGedit sends an extra 'return' after c...

Help
jon
2012-11-20
2013-04-05
  • jon
    jon
    2012-11-20

    I have a bunch of interactive functions that are immediately canceled by RGedit's extra 'return' after sending a line.  Where/how can I delete the  extra return? 

     
  • Dan Dediu
    Dan Dediu
    2012-11-20

    Hi,

    there was a discussion early on about this behaviour and the majority vote at that time favoured an enter after the line to get it executed. Now, you could change the python code doing that or send the *selection* to the console (actually, what exactly is the scenario that does not work?)

    Best,
    Dan

     
  • jon
    jon
    2012-11-20

    You are correct, running the selection works well, but running the current line adds the extra 'enter' and advances the initial 'ask=TRUE' component. 

    I think it would be great if I could modify the python code to make this work…but I have never done anything in python.  If its as simple as finding the line in RCtrl.py and deleting a couple of characters I can do that. 

    It would be a lot easier if I had some hints on what line number I should look at! 

    Thanks for your help so far-
    Jon

     
  • jon
    jon
    2012-11-20

    Looks like I may need to recompile when I'm done?  That's ok, I could do that too I guess.  Still can't find the right line though…

    jon

     
  • Dan Dediu
    Dan Dediu
    2012-11-21

    Hi Jon,

    what version of rgedit do you use (GTK2 or GTK3)?

    Dan

     
  • jon
    jon
    2012-11-21

    Hi Dan,

    it's GTK3 (0.7.1.2).  I just downloaded it the other day, and I've been using it every day.  It's a great plugin!

    thanks,
    Jon

     
  • Dan Dediu
    Dan Dediu
    2012-11-21

    commenting lines 1848 and 1849 to get:

                    #if len(sel_text) == 0 or sel_text[-1] != '\n' and sel_text[-1] != '\r':
                        #sel_text = sel_text + '\n'
    

    should be enough (these lines add a trailing '\n' if one is missing). In fact, it might be necessary to actively remove any trailing '\n' or '\r' but please let me know if it works like this for you…

    Dan

     
  • jon
    jon
    2012-11-22

    Hi Dan,

    This was a huge help, I really appreciate it!  Commenting out those two lines actually didn't solve it immediately (even though I removed the RCtrl.pyc file and restarted gedit); what really helped was your note that I might need to remove any trailing '\r'.  I didn't mention it, but the file I am working from was started in Windows and many of the lines must end with '\r\n', which gedit understands as equivalent to '\n' but which was translated into two line breaks when it was sent to R.  Reading your note, then removing them and replacing with '\n' is what solved it.

    I only use gedit in linux, so instead of commenting out the two lines you suggested (which seem very useful and not my problem after all) I added these two lines immediately before the lines you printed above:

    {                if sel_text[-2] == '\r' and sel_text[-1] == '\n':
                        sel_text = sel_text.replace('\r','')}
    

    and all seems to work as it should.

    Again, I really appreciate your help, I couldn't have done this without your input.
    Thank you,
    jon

     
  • jon
    jon
    2012-11-22

    that was the first line of code I inserted into a post, so of course I did it wrong.  Ignore the brackets.  it should be:

                    if sel_text[-2] == '\r' and sel_text[-1] == '\n':
                        sel_text = sel_text.replace('\r','')
    
     
  • jon
    jon
    2012-11-22

    Reading more about different line breaks I learned that '\n', '\r', and '\r\n' are all in use and it may vary not only by OS but by editor as well. My Windows editor is Tinn-R, in case you are curious.

    Jon

     
  • Dan Dediu
    Dan Dediu
    2012-11-22

    Hi Jon,

    I'm glad ti worked! I'm even thinking about adding an option to remove these trailing new lines when sending the current line to R in case somebody else might need it.

    Best,
    Dan