Commit 356a577b authored by Kurt B. Kaiser's avatar Kurt B. Kaiser

Merge Py Idle's changes to AutoIndent.py into EditorWindow.py since

EditorWindow has incorporated AutoIndent

Rev 1.17
classifyws():  Fix a "/" to work under -Qnew (as well as without it).
Bugfix candidate!

Rev 1.18
(Already merged)

Rev 1.19
smart_backspace_event():  remove now-pointless int() call.
Bugfix candidate:  the current state of AutoIdent.py should be in 2.2.1.

Rev 1.20
Apply diff2.txt from SF patch http://www.python.org/sf/572113
(with one small bugfix in bgen/bgen/scantools.py)
This replaces string module functions with string methods
for the stuff in the Tools directory. Several uses of
string.letters etc. are still remaining.
parent 456513c5
import sys import sys
import os import os
import string
import re import re
import imp import imp
from Tkinter import * from Tkinter import *
...@@ -913,15 +912,15 @@ class EditorWindow: ...@@ -913,15 +912,15 @@ class EditorWindow:
return "break" return "break"
# Ick. It may require *inserting* spaces if we back up over a # Ick. It may require *inserting* spaces if we back up over a
# tab character! This is written to be clear, not fast. # tab character! This is written to be clear, not fast.
expand, tabwidth = string.expandtabs, self.tabwidth tabwidth = self.tabwidth
have = len(expand(chars, tabwidth)) have = len(chars.expandtabs(tabwidth))
assert have > 0 assert have > 0
want = ((have - 1) // self.indentwidth) * self.indentwidth want = ((have - 1) // self.indentwidth) * self.indentwidth
ncharsdeleted = 0 ncharsdeleted = 0
while 1: while 1:
chars = chars[:-1] chars = chars[:-1]
ncharsdeleted = ncharsdeleted + 1 ncharsdeleted = ncharsdeleted + 1
have = len(expand(chars, tabwidth)) have = len(chars.expandtabs(tabwidth))
if have <= want or chars[-1] not in " \t": if have <= want or chars[-1] not in " \t":
break break
text.undo_block_start() text.undo_block_start()
...@@ -955,8 +954,7 @@ class EditorWindow: ...@@ -955,8 +954,7 @@ class EditorWindow:
if self.usetabs: if self.usetabs:
pad = '\t' pad = '\t'
else: else:
effective = len(string.expandtabs(prefix, effective = len(prefix.expandtabs(self.tabwidth))
self.tabwidth))
n = self.indentwidth n = self.indentwidth
pad = ' ' * (n - effective % n) pad = ' ' * (n - effective % n)
text.insert("insert", pad) text.insert("insert", pad)
...@@ -1121,7 +1119,7 @@ class EditorWindow: ...@@ -1121,7 +1119,7 @@ class EditorWindow:
head, tail, chars, lines = self.get_region() head, tail, chars, lines = self.get_region()
tabwidth = self._asktabwidth() tabwidth = self._asktabwidth()
for pos in range(len(lines)): for pos in range(len(lines)):
lines[pos] = string.expandtabs(lines[pos], tabwidth) lines[pos] = lines[pos].expandtabs(tabwidth)
self.set_region(head, tail, chars, lines) self.set_region(head, tail, chars, lines)
def toggle_tabs_event(self, event): def toggle_tabs_event(self, event):
...@@ -1162,12 +1160,12 @@ class EditorWindow: ...@@ -1162,12 +1160,12 @@ class EditorWindow:
head = text.index("insert linestart") head = text.index("insert linestart")
tail = text.index("insert lineend +1c") tail = text.index("insert lineend +1c")
chars = text.get(head, tail) chars = text.get(head, tail)
lines = string.split(chars, "\n") lines = chars.split("\n")
return head, tail, chars, lines return head, tail, chars, lines
def set_region(self, head, tail, chars, lines): def set_region(self, head, tail, chars, lines):
text = self.text text = self.text
newchars = string.join(lines, "\n") newchars = "\n".join(lines)
if newchars == chars: if newchars == chars:
text.bell() text.bell()
return return
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment