[Python-checkins] commit of r41451 - python/trunk/Lib/idlelib

kurt.kaiser@python.org kurt.kaiser at python.org
Tue Nov 15 08:20:07 CET 2005


Author: kurt.kaiser
Date: Tue Nov 15 08:20:06 2005
New Revision: 41451

Modified:
   python/trunk/Lib/idlelib/EditorWindow.py
   python/trunk/Lib/idlelib/NEWS.txt
   python/trunk/Lib/idlelib/PyParse.py
Log:
Better indentation after first line of string continuation.
IDLEfork Patch 681992, Noam Raphael


Modified: python/trunk/Lib/idlelib/EditorWindow.py
==============================================================================
--- python/trunk/Lib/idlelib/EditorWindow.py	(original)
+++ python/trunk/Lib/idlelib/EditorWindow.py	Tue Nov 15 08:20:06 2005
@@ -1078,8 +1078,12 @@
             c = y.get_continuation_type()
             if c != PyParse.C_NONE:
                 # The current stmt hasn't ended yet.
-                if c == PyParse.C_STRING:
-                    # inside a string; just mimic the current indent
+                if c == PyParse.C_STRING_FIRST_LINE:
+                    # after the first line of a string; do not indent at all
+                    pass
+                elif c == PyParse.C_STRING_NEXT_LINES:
+                    # inside a string which started before this line;
+                    # just mimic the current indent
                     text.insert("insert", indent)
                 elif c == PyParse.C_BRACKET:
                     # line up with the first (if any) element of the

Modified: python/trunk/Lib/idlelib/NEWS.txt
==============================================================================
--- python/trunk/Lib/idlelib/NEWS.txt	(original)
+++ python/trunk/Lib/idlelib/NEWS.txt	Tue Nov 15 08:20:06 2005
@@ -3,6 +3,9 @@
 
 *Release date: XX-XXX-2005*
 
+- Better indentation after first line of string continuation.
+  IDLEfork Patch 681992, Noam Raphael
+
 - Fixed CodeContext alignment problem, following suggestion from Tal Einat.
 
 - Increased performance in CodeContext extension  Patch 936169 Noam Raphael

Modified: python/trunk/Lib/idlelib/PyParse.py
==============================================================================
--- python/trunk/Lib/idlelib/PyParse.py	(original)
+++ python/trunk/Lib/idlelib/PyParse.py	Tue Nov 15 08:20:06 2005
@@ -2,7 +2,8 @@
 import sys
 
 # Reason last stmt is continued (or C_NONE if it's not).
-C_NONE, C_BACKSLASH, C_STRING, C_BRACKET = range(4)
+(C_NONE, C_BACKSLASH, C_STRING_FIRST_LINE,
+ C_STRING_NEXT_LINES, C_BRACKET) = range(5)
 
 if 0:   # for throwaway debugging output
     def dump(*stuff):
@@ -281,6 +282,7 @@
                 quote = ch
                 if str[i-1:i+2] == quote * 3:
                     quote = quote * 3
+                firstlno = lno
                 w = len(quote) - 1
                 i = i+w
                 while i < n:
@@ -315,7 +317,12 @@
                 else:
                     # didn't break out of the loop, so we're still
                     # inside a string
-                    continuation = C_STRING
+                    if (lno - 1) == firstlno:
+                        # before the previous \n in str, we were in the first
+                        # line of the string
+                        continuation = C_STRING_FIRST_LINE
+                    else:
+                        continuation = C_STRING_NEXT_LINES
                 continue    # with outer loop
 
             if ch == '#':
@@ -335,7 +342,8 @@
         # The last stmt may be continued for all 3 reasons.
         # String continuation takes precedence over bracket
         # continuation, which beats backslash continuation.
-        if continuation != C_STRING and level > 0:
+        if (continuation != C_STRING_FIRST_LINE
+            and continuation != C_STRING_NEXT_LINES and level > 0):
             continuation = C_BRACKET
         self.continuation = continuation
 


More information about the Python-checkins mailing list