Author cheryl.sabella
Recipients cheryl.sabella, grantjenks, rhettinger, terry.reedy
Date 2018-12-25.21:25:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1545773116.12.0.712150888896.issue34055@roundup.psfhosted.org>
In-reply-to
Content
This code in editor.py controls the text that is parsed for smart indenting:
            if not self.context_use_ps1:
                for context in self.num_context_lines:
                    startat = max(lno - context, 1)
                    startatindex = repr(startat) + ".0"
                    rawtext = text.get(startatindex, "insert")
                    y.set_code(rawtext)
                    bod = y.find_good_parse_start(
                              self.context_use_ps1, self._build_char_in_string_func(startatindex))
                    if bod is not None or startat == 1:
                        break
                y.set_lo(bod or 0)
            else:
                r = text.tag_prevrange("console", "insert")
                if r:
                    startatindex = r[1]
                else:
                    startatindex = "1.0"
                rawtext = text.get(startatindex, "insert")
                y.set_code(rawtext)
                y.set_lo(0)

The `if not self.context_use_ps1` basically says whether the window is an editor or shell.  At a high level, the editor code goes back a certain number of lines from the current cursor and the shell window goes back to just the current statement.  

#31858 improved the use of sys.ps1 (the prompt) and it removed setting `self.context_use_ps1` in pyshell.  This meant that the `else` above was never accessed and that the shell was parsing all the text, not just the current statement.

#31858 introduced `self.prompt_last_line` that is set to '' in the editor and set to the prompt in the shell.  Replacing `self.context_use_ps1` with `self.prompt_last_line` allows the `else` above to be called.

#32989 addresses a bug discovered with adding tests to `pyparse` where the `find_good_parse_start` call above was actually sending incorrect parameters, so removing `context_use_ps1` from that line is not an issue, but rather another bug fix.  It might be preferable to merge #32989 first, therefore I'm listing that as a dependency.
History
Date User Action Args
2018-12-25 21:25:17cheryl.sabellasetrecipients: + cheryl.sabella, rhettinger, terry.reedy, grantjenks
2018-12-25 21:25:16cheryl.sabellasetmessageid: <1545773116.12.0.712150888896.issue34055@roundup.psfhosted.org>
2018-12-25 21:25:16cheryl.sabellalinkissue34055 messages
2018-12-25 21:25:16cheryl.sabellacreate