summaryrefslogtreecommitdiffstats
path: root/Lib/idlelib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/idlelib')
-rw-r--r--Lib/idlelib/AutoComplete.py8
-rw-r--r--Lib/idlelib/AutoCompleteWindow.py19
-rw-r--r--Lib/idlelib/EditorWindow.py45
-rw-r--r--Lib/idlelib/PyShell.py11
-rw-r--r--Lib/idlelib/configHandler.py20
5 files changed, 79 insertions, 24 deletions
diff --git a/Lib/idlelib/AutoComplete.py b/Lib/idlelib/AutoComplete.py
index ac0827c..9d9a81e 100644
--- a/Lib/idlelib/AutoComplete.py
+++ b/Lib/idlelib/AutoComplete.py
@@ -23,6 +23,10 @@ from idlelib.HyperParser import HyperParser
import __main__
+SEPS = os.sep
+if os.altsep: # e.g. '/' on Windows...
+ SEPS += os.altsep
+
class AutoComplete:
menudefs = [
@@ -70,7 +74,7 @@ class AutoComplete:
if lastchar == ".":
self._open_completions_later(False, False, False,
COMPLETE_ATTRIBUTES)
- elif lastchar == os.sep:
+ elif lastchar in SEPS:
self._open_completions_later(False, False, False,
COMPLETE_FILES)
@@ -126,7 +130,7 @@ class AutoComplete:
i -= 1
comp_start = curline[i:j]
j = i
- while i and curline[i-1] in FILENAME_CHARS+os.sep:
+ while i and curline[i-1] in FILENAME_CHARS + SEPS:
i -= 1
comp_what = curline[i:j]
elif hp.is_in_code() and (not mode or mode==COMPLETE_ATTRIBUTES):
diff --git a/Lib/idlelib/AutoCompleteWindow.py b/Lib/idlelib/AutoCompleteWindow.py
index ca9109b..298177f 100644
--- a/Lib/idlelib/AutoCompleteWindow.py
+++ b/Lib/idlelib/AutoCompleteWindow.py
@@ -54,9 +54,9 @@ class AutoCompleteWindow:
self.lastkey_was_tab = False
def _change_start(self, newstart):
+ min_len = min(len(self.start), len(newstart))
i = 0
- while i < len(self.start) and i < len(newstart) and \
- self.start[i] == newstart[i]:
+ while i < min_len and self.start[i] == newstart[i]:
i += 1
if i < len(self.start):
self.widget.delete("%s+%dc" % (self.startindex, i),
@@ -98,13 +98,17 @@ class AutoCompleteWindow:
i = m + 1
last = i-1
+ if first == last: # only one possible completion
+ return self.completions[first]
+
# We should return the maximum prefix of first and last
+ first_comp = self.completions[first]
+ last_comp = self.completions[last]
+ min_len = min(len(first_comp), len(last_comp))
i = len(s)
- while len(self.completions[first]) > i and \
- len(self.completions[last]) > i and \
- self.completions[first][i] == self.completions[last][i]:
+ while i < min_len and first_comp[i] == last_comp[i]:
i += 1
- return self.completions[first][:i]
+ return first_comp[:i]
def _selection_changed(self):
"""Should be called when the selection of the Listbox has changed.
@@ -118,8 +122,9 @@ class AutoCompleteWindow:
if self._binary_search(lts) == cursel:
newstart = lts
else:
+ min_len = min(len(lts), len(selstart))
i = 0
- while i < len(lts) and i < len(selstart) and lts[i] == selstart[i]:
+ while i < min_len and lts[i] == selstart[i]:
i += 1
newstart = selstart[:i]
self._change_start(newstart)
diff --git a/Lib/idlelib/EditorWindow.py b/Lib/idlelib/EditorWindow.py
index 2b5c527..e049b66 100644
--- a/Lib/idlelib/EditorWindow.py
+++ b/Lib/idlelib/EditorWindow.py
@@ -155,6 +155,7 @@ class EditorWindow(object):
text.bind("<Right>", self.move_at_edge_if_selection(1))
text.bind("<<del-word-left>>", self.del_word_left)
text.bind("<<del-word-right>>", self.del_word_right)
+ text.bind("<<beginning-of-line>>", self.home_callback)
if flist:
flist.inversedict[self] = key
@@ -277,6 +278,50 @@ class EditorWindow(object):
self.flist.new(dirname)
return "break"
+ def home_callback(self, event):
+ if (event.state & 12) != 0 and event.keysym == "Home":
+ # state&1==shift, state&4==control, state&8==alt
+ return # <Modifier-Home>; fall back to class binding
+
+ if self.text.index("iomark") and \
+ self.text.compare("iomark", "<=", "insert lineend") and \
+ self.text.compare("insert linestart", "<=", "iomark"):
+ insertpt = int(self.text.index("iomark").split(".")[1])
+ else:
+ line = self.text.get("insert linestart", "insert lineend")
+ for insertpt in xrange(len(line)):
+ if line[insertpt] not in (' ','\t'):
+ break
+ else:
+ insertpt=len(line)
+
+ lineat = int(self.text.index("insert").split('.')[1])
+
+ if insertpt == lineat:
+ insertpt = 0
+
+ dest = "insert linestart+"+str(insertpt)+"c"
+
+ if (event.state&1) == 0:
+ # shift not pressed
+ self.text.tag_remove("sel", "1.0", "end")
+ else:
+ if not self.text.index("sel.first"):
+ self.text.mark_set("anchor","insert")
+
+ first = self.text.index(dest)
+ last = self.text.index("anchor")
+
+ if self.text.compare(first,">",last):
+ first,last = last,first
+
+ self.text.tag_remove("sel", "1.0", "end")
+ self.text.tag_add("sel", first, last)
+
+ self.text.mark_set("insert", dest)
+ self.text.see("insert")
+ return "break"
+
def set_status_bar(self):
self.status_bar = self.MultiStatusBar(self.top)
if macosxSupport.runningAsOSXApp():
diff --git a/Lib/idlelib/PyShell.py b/Lib/idlelib/PyShell.py
index 7c66088..7799232 100644
--- a/Lib/idlelib/PyShell.py
+++ b/Lib/idlelib/PyShell.py
@@ -806,7 +806,6 @@ class PyShell(OutputWindow):
text.bind("<<newline-and-indent>>", self.enter_callback)
text.bind("<<plain-newline-and-indent>>", self.linefeed_callback)
text.bind("<<interrupt-execution>>", self.cancel_callback)
- text.bind("<<beginning-of-line>>", self.home_callback)
text.bind("<<end-of-file>>", self.eof_callback)
text.bind("<<open-stack-viewer>>", self.open_stack_viewer)
text.bind("<<toggle-debugger>>", self.toggle_debugger)
@@ -1048,16 +1047,6 @@ class PyShell(OutputWindow):
self.top.quit()
return "break"
- def home_callback(self, event):
- if event.state != 0 and event.keysym == "Home":
- return # <Modifier-Home>; fall back to class binding
- if self.text.compare("iomark", "<=", "insert") and \
- self.text.compare("insert linestart", "<=", "iomark"):
- self.text.mark_set("insert", "iomark")
- self.text.tag_remove("sel", "1.0", "end")
- self.text.see("insert")
- return "break"
-
def linefeed_callback(self, event):
# Insert a linefeed without entering anything (still autoindented)
if self.reading:
diff --git a/Lib/idlelib/configHandler.py b/Lib/idlelib/configHandler.py
index 4906578..9b995cf 100644
--- a/Lib/idlelib/configHandler.py
+++ b/Lib/idlelib/configHandler.py
@@ -204,7 +204,10 @@ class IdleConf:
if not os.path.exists(userDir):
warn = ('\n Warning: os.path.expanduser("~") points to\n '+
userDir+',\n but the path does not exist.\n')
- sys.stderr.write(warn)
+ try:
+ sys.stderr.write(warn)
+ except IOError:
+ pass
userDir = '~'
if userDir == "~": # still no path to home!
# traditionally IDLE has defaulted to os.getcwd(), is this adequate?
@@ -247,7 +250,10 @@ class IdleConf:
' from section %r.\n'
' returning default value: %r\n' %
(option, section, default))
- sys.stderr.write(warning)
+ try:
+ sys.stderr.write(warning)
+ except IOError:
+ pass
return default
def SetOption(self, configType, section, option, value):
@@ -356,7 +362,10 @@ class IdleConf:
'\n from theme %r.\n'
' returning default value: %r\n' %
(element, themeName, theme[element]))
- sys.stderr.write(warning)
+ try:
+ sys.stderr.write(warning)
+ except IOError:
+ pass
colour=cfgParser.Get(themeName,element,default=theme[element])
theme[element]=colour
return theme
@@ -610,7 +619,10 @@ class IdleConf:
'\n from key set %r.\n'
' returning default value: %r\n' %
(event, keySetName, keyBindings[event]))
- sys.stderr.write(warning)
+ try:
+ sys.stderr.write(warning)
+ except IOError:
+ pass
return keyBindings
def GetExtraHelpSourceList(self,configSet):