MCPcopy Index your code
hub / github.com/python/cpython / History

Class History

Lib/idlelib/history.py:6–101  ·  view source on GitHub ↗

Implement Idle Shell history mechanism. store - Store source statement (called from pyshell.resetoutput). fetch - Fetch stored statement matching prefix already entered. history_next - Bound to < > event (default Alt-N). history_prev - Bound to < > event (

Source from the content-addressed store, hash-verified

4
5
6class History:
7 ''&#x27; Implement Idle Shell history mechanism.
8
9 store - Store source statement (called from pyshell.resetoutput).
10 fetch - Fetch stored statement matching prefix already entered.
11 history_next - Bound to <<history-next>> event (default Alt-N).
12 history_prev - Bound to <<history-prev>> event (default Alt-P).
13 ''&#x27;
14 def __init__(self, text):
15 ''&#x27;Initialize data attributes and bind event methods.
16
17 .text - Idle wrapper of tk Text widget, with .bell().
18 .history - source statements, possibly with multiple lines.
19 .prefix - source already entered at prompt; filters history list.
20 .pointer - index into history.
21 .cyclic - wrap around history list (or not).
22 ''&#x27;
23 self.text = text
24 self.history = []
25 self.prefix = None
26 self.pointer = None
27 self.cyclic = idleConf.GetOption("main", "History", "cyclic", 1, "bool")
28 text.bind("<<history-previous>>", self.history_prev)
29 text.bind("<<history-next>>", self.history_next)
30
31 def history_next(self, event):
32 "Fetch later statement; start with earliest if cyclic."
33 self.fetch(reverse=False)
34 return "break"
35
36 def history_prev(self, event):
37 "Fetch earlier statement; start with most recent."
38 self.fetch(reverse=True)
39 return "break"
40
41 def fetch(self, reverse):
42 ''&#x27;Fetch statement and replace current line in text widget.
43
44 Set prefix and pointer as needed for successive fetches.
45 Reset them to None, None when returning to the start line.
46 Sound bell when return to start line or cannot leave a line
47 because cyclic is False.
48 ''&#x27;
49 nhist = len(self.history)
50 pointer = self.pointer
51 prefix = self.prefix
52 if pointer is not None and prefix is not None:
53 if self.text.compare("insert", "!=", "end-1c") or \
54 self.text.get("iomark", "end-1c") != self.history[pointer]:
55 pointer = prefix = None
56 self.text.mark_set("insert", "end-1c") # != after cursor move
57 if pointer is None or prefix is None:
58 prefix = self.text.get("iomark", "end-1c")
59 if reverse:
60 pointer = nhist # will be decremented
61 else:
62 if self.cyclic:
63 pointer = -1 # will be incremented

Callers 2

setUpClassMethod · 0.90
setUpMethod · 0.90

Calls

no outgoing calls

Tested by 2

setUpClassMethod · 0.72
setUpMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…