Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b61602c

Browse files
committed
Better indentation after first line of string continuation.
IDLEfork Patch 681992, Noam Raphael
1 parent 6b34789 commit b61602c

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

Lib/idlelib/EditorWindow.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,8 +1078,12 @@ def newline_and_indent_event(self, event):
10781078
c = y.get_continuation_type()
10791079
if c != PyParse.C_NONE:
10801080
# The current stmt hasn't ended yet.
1081-
if c == PyParse.C_STRING:
1082-
# inside a string; just mimic the current indent
1081+
if c == PyParse.C_STRING_FIRST_LINE:
1082+
# after the first line of a string; do not indent at all
1083+
pass
1084+
elif c == PyParse.C_STRING_NEXT_LINES:
1085+
# inside a string which started before this line;
1086+
# just mimic the current indent
10831087
text.insert("insert", indent)
10841088
elif c == PyParse.C_BRACKET:
10851089
# line up with the first (if any) element of the

Lib/idlelib/NEWS.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ What's New in IDLE 1.2a0?
33

44
*Release date: XX-XXX-2005*
55

6+
- Better indentation after first line of string continuation.
7+
IDLEfork Patch 681992, Noam Raphael
8+
69
- Fixed CodeContext alignment problem, following suggestion from Tal Einat.
710

811
- Increased performance in CodeContext extension Patch 936169 Noam Raphael

Lib/idlelib/PyParse.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import sys
33

44
# Reason last stmt is continued (or C_NONE if it's not).
5-
C_NONE, C_BACKSLASH, C_STRING, C_BRACKET = range(4)
5+
(C_NONE, C_BACKSLASH, C_STRING_FIRST_LINE,
6+
C_STRING_NEXT_LINES, C_BRACKET) = range(5)
67

78
if 0: # for throwaway debugging output
89
def dump(*stuff):
@@ -281,6 +282,7 @@ def _study1(self):
281282
quote = ch
282283
if str[i-1:i+2] == quote * 3:
283284
quote = quote * 3
285+
firstlno = lno
284286
w = len(quote) - 1
285287
i = i+w
286288
while i < n:
@@ -315,7 +317,12 @@ def _study1(self):
315317
else:
316318
# didn't break out of the loop, so we're still
317319
# inside a string
318-
continuation = C_STRING
320+
if (lno - 1) == firstlno:
321+
# before the previous \n in str, we were in the first
322+
# line of the string
323+
continuation = C_STRING_FIRST_LINE
324+
else:
325+
continuation = C_STRING_NEXT_LINES
319326
continue # with outer loop
320327

321328
if ch == '#':
@@ -335,7 +342,8 @@ def _study1(self):
335342
# The last stmt may be continued for all 3 reasons.
336343
# String continuation takes precedence over bracket
337344
# continuation, which beats backslash continuation.
338-
if continuation != C_STRING and level > 0:
345+
if (continuation != C_STRING_FIRST_LINE
346+
and continuation != C_STRING_NEXT_LINES and level > 0):
339347
continuation = C_BRACKET
340348
self.continuation = continuation
341349

0 commit comments

Comments
 (0)