[Idle-dev] CVS: idle EditorWindow.py,1.39,1.40 PyShell.py,1.49,1.50

Kurt B. Kaiser kbk@users.sourceforge.net
Sun, 29 Dec 2002 14:03:40 -0800


Update of /cvsroot/idlefork/idle
In directory sc8-pr-cvs1:/tmp/cvs-serv16359

Modified Files:
	EditorWindow.py PyShell.py 
Log Message:
M EditorWindow.py
M PyShell.py

1. PyShell Rev 1.39, EditorWindow Rev 1.37 fix was not handling a
   multiline prompt.
2. The same fix introduced a bug where hitting <enter> at a previous
   prompt-only line would copy the prompt to the iomark.
3. Move the setting of sys.ps1 earlier, into PyShell.main(), to allow
   this code to work before a shell is started up.
4. If cursor is on the input line in the prompt, and you hit <enter>,
   process the line instead of complaining.
5. If line has no stdin range (this includes the last line before shell
   restart) strip any prompt before recalling.


Index: EditorWindow.py
===================================================================
RCS file: /cvsroot/idlefork/idle/EditorWindow.py,v
retrieving revision 1.39
retrieving revision 1.40
diff -C2 -r1.39 -r1.40
*** EditorWindow.py	20 Dec 2002 19:37:09 -0000	1.39
--- EditorWindow.py	29 Dec 2002 22:03:38 -0000	1.40
***************
*** 953,959 ****
          assert have > 0
          want = ((have - 1) // self.indentwidth) * self.indentwidth
          ncharsdeleted = 0
          while 1:
!             if chars == sys.ps1:
                  break
              chars = chars[:-1]
--- 953,961 ----
          assert have > 0
          want = ((have - 1) // self.indentwidth) * self.indentwidth
+         # Debug prompt is multilined....
+         last_line_of_prompt = sys.ps1.split('\n')[-1]
          ncharsdeleted = 0
          while 1:
!             if chars == last_line_of_prompt:
                  break
              chars = chars[:-1]
***************
*** 1012,1028 ****
              line = text.get("insert linestart", "insert")
              i, n = 0, len(line)
-             if line == sys.ps1:
-                 return "break"
              while i < n and line[i] in " \t":
                  i = i+1
              if i == n:
!                 # the cursor is in or at leading indentation; just inject
!                 # an empty line at the start
                  text.insert("insert linestart", '\n')
                  return "break"
              indent = line[:i]
!             # strip whitespace before insert point
              i = 0
!             while line and line[-1] in " \t":
                  line = line[:-1]
                  i = i+1
--- 1014,1029 ----
              line = text.get("insert linestart", "insert")
              i, n = 0, len(line)
              while i < n and line[i] in " \t":
                  i = i+1
              if i == n:
!                 # the cursor is in or at leading indentation in a continuation
!                 # line; just inject an empty line at the start
                  text.insert("insert linestart", '\n')
                  return "break"
              indent = line[:i]
!             # strip whitespace before insert point unless it's in the prompt
              i = 0
!             last_line_of_prompt = sys.ps1.split('\n')[-1]
!             while line and line[-1] in " \t" and line != last_line_of_prompt:
                  line = line[:-1]
                  i = i+1

Index: PyShell.py
===================================================================
RCS file: /cvsroot/idlefork/idle/PyShell.py,v
retrieving revision 1.49
retrieving revision 1.50
diff -C2 -r1.49 -r1.50
*** PyShell.py	24 Dec 2002 17:21:43 -0000	1.49
--- PyShell.py	29 Dec 2002 22:03:38 -0000	1.50
***************
*** 826,833 ****
                     (sys.version, sys.platform, self.COPYRIGHT,
                      idlever.IDLE_VERSION))
-         try:
-             sys.ps1
-         except AttributeError:
-             sys.ps1 = ">>> "
          self.showprompt()
          import Tkinter
--- 826,829 ----
***************
*** 944,955 ****
                  self.recall(self.text.get(next[0], next[1]))
                  return "break"
!             # No stdin mark -- just get the current line
!             self.recall(self.text.get("insert linestart", "insert lineend"))
              return "break"
          # If we're between the beginning of the line and the iomark, i.e.
!         # in the prompt area, complain.
          if self.text.compare("insert", "<", "iomark"):
!             self.text.bell()
!             return "break"
          # If we're in the current input and there's only whitespace
          # beyond the cursor, erase that whitespace first
--- 940,954 ----
                  self.recall(self.text.get(next[0], next[1]))
                  return "break"
!             # No stdin mark -- just get the current line, less any prompt
!             line = self.text.get("insert linestart", "insert lineend")
!             last_line_of_prompt = sys.ps1.split('\n')[-1]
!             if line.startswith(last_line_of_prompt):
!                 line = line[len(last_line_of_prompt):]
!             self.recall(line)
              return "break"
          # If we're between the beginning of the line and the iomark, i.e.
!         # in the prompt area, move to the end of the prompt
          if self.text.compare("insert", "<", "iomark"):
!             self.text.mark_set("insert", "iomark")
          # If we're in the current input and there's only whitespace
          # beyond the cursor, erase that whitespace first
***************
*** 1136,1139 ****
--- 1135,1142 ----
      script = None
      startup = False
+     try:
+         sys.ps1
+     except AttributeError:
+         sys.ps1 = '>>> '
      try:
          opts, args = getopt.getopt(sys.argv[1:], "c:deihr:st:")