[Python-checkins] python/dist/src/Lib/idlelib EditorWindow.py, 1.64, 1.65 NEWS.txt, 1.52, 1.53 PyShell.py, 1.94, 1.95 ScriptBinding.py, 1.28, 1.29

kbk at users.sourceforge.net kbk at users.sourceforge.net
Wed Jan 19 01:23:19 CET 2005


Update of /cvsroot/python/python/dist/src/Lib/idlelib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15261

Modified Files:
	EditorWindow.py NEWS.txt PyShell.py ScriptBinding.py 
Log Message:
1. Polish tabbing code.
2. Restore use of set_indentation_params(), was dead code since
   Autoindent.py was merged into EditorWindow.py.
3. Make usetabs, indentwidth, tabwidth, context_use_ps1 instance vars
   and set in EditorWindow.__init__()
4. In PyShell.__init__() set usetabs, indentwidth and context_use_ps1
   explicitly (config() is eliminated).
5. Add Tabnanny check when Module is Run/F5, not just when Checked.
6. Discourage using an indent width other than 8 when using tabs to
   indent Python code.

M EditorWindow.py
M NEWS.txt
M PyShell.py
M ScriptBinding.py


Index: EditorWindow.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/idlelib/EditorWindow.py,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -d -r1.64 -r1.65
--- EditorWindow.py	18 Jan 2005 00:54:57 -0000	1.64
+++ EditorWindow.py	19 Jan 2005 00:22:54 -0000	1.65
@@ -165,6 +165,38 @@
         text.pack(side=TOP, fill=BOTH, expand=1)
         text.focus_set()
 
+        # usetabs true  -> literal tab characters are used by indent and
+        #                  dedent cmds, possibly mixed with spaces if
+        #                  indentwidth is not a multiple of tabwidth,
+        #                  which will cause Tabnanny to nag!
+        #         false -> tab characters are converted to spaces by indent
+        #                  and dedent cmds, and ditto TAB keystrokes
+        self.usetabs = False
+
+        # indentwidth is the number of characters per logical indent level.
+        # Recommended Python default indent is four spaces.
+        self.indentwidth = 4
+
+        # tabwidth is the display width of a literal tab character.
+        # CAUTION:  telling Tk to use anything other than its default
+        # tab setting causes it to use an entirely different tabbing algorithm,
+        # treating tab stops as fixed distances from the left margin.
+        # Nobody expects this, so for now tabwidth should never be changed.
+        self.tabwidth = 8    # for IDLE use, must remain 8 until Tk is fixed.
+                             # indentwidth should be 8 when usetabs is True.
+
+        # If context_use_ps1 is true, parsing searches back for a ps1 line;
+        # else searches for a popular (if, def, ...) Python stmt.
+        self.context_use_ps1 = False
+
+        # When searching backwards for a reliable place to begin parsing,
+        # first start num_context_lines[0] lines back, then
+        # num_context_lines[1] lines back if that didn't work, and so on.
+        # The last value should be huge (larger than the # of lines in a
+        # conceivable file).
+        # Making the initial values larger slows things down more often.
+        self.num_context_lines = 50, 500, 5000000
+
         self.per = per = self.Percolator(text)
         if self.ispythonsource(filename):
             self.color = color = self.ColorDelegator()
@@ -196,6 +228,8 @@
                 io.set_filename(filename)
         self.saved_change_hook()
 
+        self.set_indentation_params(self.ispythonsource(filename))
+
         self.load_extensions()
 
         menu = self.menudict.get('windows')
@@ -214,10 +248,6 @@
         self.askinteger = tkSimpleDialog.askinteger
         self.showerror = tkMessageBox.showerror
 
-        if self.extensions.has_key('AutoIndent'):
-            self.extensions['AutoIndent'].set_indentation_params(
-                self.ispythonsource(filename))
-
     def new_callback(self, event):
         dirname, basename = self.io.defaultfilename()
         self.flist.new(dirname)
@@ -881,62 +911,19 @@
                                   "n" * newtabwidth)
             text.configure(tabs=pixels)
 
-### begin autoindent code ###
-
-    # usetabs true  -> literal tab characters are used by indent and
-    #                  dedent cmds, possibly mixed with spaces if
-    #                  indentwidth is not a multiple of tabwidth
-    #         false -> tab characters are converted to spaces by indent
-    #                  and dedent cmds, and ditto TAB keystrokes
-    # indentwidth is the number of characters per logical indent level.
-    # tabwidth is the display width of a literal tab character.
-    # CAUTION:  telling Tk to use anything other than its default
-    # tab setting causes it to use an entirely different tabbing algorithm,
-    # treating tab stops as fixed distances from the left margin.
-    # Nobody expects this, so for now tabwidth should never be changed.
-    usetabs = 0
-    indentwidth = 4
-    tabwidth = 8    # for IDLE use, must remain 8 until Tk is fixed
-
-    # If context_use_ps1 is true, parsing searches back for a ps1 line;
-    # else searches for a popular (if, def, ...) Python stmt.
-    context_use_ps1 = 0
-
-    # When searching backwards for a reliable place to begin parsing,
-    # first start num_context_lines[0] lines back, then
-    # num_context_lines[1] lines back if that didn't work, and so on.
-    # The last value should be huge (larger than the # of lines in a
-    # conceivable file).
-    # Making the initial values larger slows things down more often.
-    num_context_lines = 50, 500, 5000000
-
-    def config(self, **options):
-        for key, value in options.items():
-            if key == 'usetabs':
-                self.usetabs = value
-            elif key == 'indentwidth':
-                self.indentwidth = value
-            elif key == 'tabwidth':
-                self.tabwidth = value
-            elif key == 'context_use_ps1':
-                self.context_use_ps1 = value
-            else:
-                raise KeyError, "bad option name: %r" % (key,)
-
     # If ispythonsource and guess are true, guess a good value for
     # indentwidth based on file content (if possible), and if
     # indentwidth != tabwidth set usetabs false.
     # In any case, adjust the Text widget's view of what a tab
     # character means.
 
-    def set_indentation_params(self, ispythonsource, guess=1):
+    def set_indentation_params(self, ispythonsource, guess=True):
         if guess and ispythonsource:
             i = self.guess_indent()
             if 2 <= i <= 8:
                 self.indentwidth = i
             if self.indentwidth != self.tabwidth:
-                self.usetabs = 0
-
+                self.usetabs = False
         self.set_tabwidth(self.tabwidth)
 
     def smart_backspace_event(self, event):
@@ -988,8 +975,9 @@
         # if intraline selection:
         #     delete it
         # elif multiline selection:
-        #     do indent-region & return
-        # indent one level
+        #     do indent-region
+        # else:
+        #     indent one level
         text = self.text
         first, last = self.get_selection_indices()
         text.undo_block_start()
@@ -1005,6 +993,7 @@
                 # only whitespace to the left
                 self.reindent_to(effective + self.indentwidth)
             else:
+                # tab to the next 'stop' within or to right of line's text:
                 if self.usetabs:
                     pad = '\t'
                 else:
@@ -1178,28 +1167,34 @@
     def toggle_tabs_event(self, event):
         if self.askyesno(
               "Toggle tabs",
-              "Turn tabs " + ("on", "off")[self.usetabs] + "?",
+              "Turn tabs " + ("on", "off")[self.usetabs] +
+              "?\nIndent width " +
+              ("will be", "remains at")[self.usetabs] + " 8.",
               parent=self.text):
             self.usetabs = not self.usetabs
+        # Try to prevent mixed tabs/spaces.
+        # User must reset indent width manually after using tabs
+        #      if he insists on getting into trouble.
+        self.indentwidth = 8
         return "break"
 
-    # XXX this isn't bound to anything -- see class tabwidth comments
-    def change_tabwidth_event(self, event):
-        new = self._asktabwidth()
-        if new != self.tabwidth:
-            self.tabwidth = new
-            self.set_indentation_params(0, guess=0)
-        return "break"
+    # XXX this isn't bound to anything -- see tabwidth comments
+##     def change_tabwidth_event(self, event):
+##         new = self._asktabwidth()
+##         if new != self.tabwidth:
+##             self.tabwidth = new
+##             self.set_indentation_params(0, guess=0)
+##         return "break"
 
     def change_indentwidth_event(self, event):
         new = self.askinteger(
                   "Indent width",
-                  "New indent width (2-16)",
+                  "New indent width (2-16)\n(Always use 8 when using tabs)",
                   parent=self.text,
                   initialvalue=self.indentwidth,
                   minvalue=2,
                   maxvalue=16)
-        if new and new != self.indentwidth:
+        if new and new != self.indentwidth and not self.usetabs:
             self.indentwidth = new
         return "break"
 

Index: NEWS.txt
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/idlelib/NEWS.txt,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -d -r1.52 -r1.53
--- NEWS.txt	18 Jan 2005 00:54:58 -0000	1.52
+++ NEWS.txt	19 Jan 2005 00:22:57 -0000	1.53
@@ -3,6 +3,14 @@
 
 *Release date: XX-XXX-2005*
 
+- Discourage using an indent width other than 8 when using tabs to indent
+  Python code.
+
+- Restore use of EditorWindow.set_indentation_params(), was dead code since
+  Autoindent was merged into EditorWindow.
+
+- Add Tabnanny check before Run/F5, not just when Checking module.
+
 - If an extension can't be loaded, print warning and skip it instead of
   erroring out.
 

Index: PyShell.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/idlelib/PyShell.py,v
retrieving revision 1.94
retrieving revision 1.95
diff -u -d -r1.94 -r1.95
--- PyShell.py	23 Dec 2004 04:20:59 -0000	1.94
+++ PyShell.py	19 Jan 2005 00:22:58 -0000	1.95
@@ -795,7 +795,11 @@
         import __builtin__
         __builtin__.quit = __builtin__.exit = "To exit, type Ctrl-D."
         #
-        self.config(usetabs=1, indentwidth=8, context_use_ps1=1)
+##        self.config(usetabs=1, indentwidth=8, context_use_ps1=1)
+        self.usetabs = True
+        # indentwidth must be 8 when using tabs.  See note in EditorWindow:
+        self.indentwidth = 8
+        self.context_use_ps1 = True
         #
         text = self.text
         text.configure(wrap="char")

Index: ScriptBinding.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/idlelib/ScriptBinding.py,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- ScriptBinding.py	4 Jul 2004 01:25:56 -0000	1.28
+++ ScriptBinding.py	19 Jan 2005 00:22:59 -0000	1.29
@@ -138,6 +138,8 @@
         filename = self.getfilename()
         if not filename:
             return
+        if not self.tabnanny(filename):
+            return
         code = self.checksyntax(filename)
         if not code:
             return



More information about the Python-checkins mailing list