Commit | Line | Data |
---|---|---|
27be52b3 MW |
1 | ### -*-python -*- |
2 | ||
449d37ba MW |
3 | try: import pygments as PYG |
4 | except: PYG = None | |
5 | try: import prompt_toolkit as PTK | |
6 | except: PTK = None | |
9ddf986b | 7 | |
27be52b3 MW |
8 | c = get_config() |
9 | ||
60abf0c5 | 10 | ## Simple stuff. |
27be52b3 MW |
11 | c.InteractiveShell.autocall = 0 |
12 | c.InteractiveShell.autoindent = True | |
13 | c.InteractiveShell.automagic = False | |
14 | ||
15 | c.InteractiveShell.color_info = True | |
16 | c.InteractiveShell.colors = 'Linux' | |
17 | ||
27be52b3 | 18 | c.TerminalIPythonApp.display_banner = False |
27be52b3 | 19 | c.TerminalInteractiveShell.confirm_exit = False |
d4d07085 | 20 | c.TerminalInteractiveShell.display_completions = 'readlinelike' |
87e4a2e8 | 21 | c.TerminalInteractiveShell.extra_open_editor_shortcuts = True |
29b9501f | 22 | c.TerminalInteractiveShell.term_title = False |
60abf0c5 MW |
23 | |
24 | ## Syntax colouring. | |
449d37ba MW |
25 | if PYG and getattr(PYG, 'token', None): |
26 | T = PYG.token | |
27 | c.TerminalInteractiveShell.highlighting_style = 'emacs' | |
28 | c.TerminalInteractiveShell.highlighting_style_overrides = { | |
29 | T.Keyword: 'bold #fff', | |
30 | T.Comment: 'italic #54ff9f', | |
31 | T.Literal.Number: '#ffff00', | |
32 | T.Literal.String: '#87ceff', | |
33 | T.Literal.String.Escape: '#87ceff', | |
34 | T.Literal.String.Interpol: '#87ceff', | |
35 | T.Name: '#fff', | |
36 | T.Name.Builtin: '#fff', | |
37 | T.Name.Class: '#fff', | |
38 | T.Name.Constant: 'italic #fff', | |
39 | T.Name.Decorator: '#fff', | |
40 | T.Name.Exception: '#fff', | |
41 | T.Name.Function: '#fff', | |
42 | T.Name.Function.Magic: '#fff', | |
43 | T.Name.Label: '#fff', | |
44 | T.Name.Namespace: '#fff', | |
45 | T.Name.Variable: '#fff', | |
46 | T.Name.Variable.Class: '#fff', | |
47 | T.Name.Variable.Global: '#fff', | |
48 | T.Name.Variable.Instance: '#fff', | |
49 | T.Name.Variable.Magic: '#fff', | |
50 | T.Operator: '#eec591', | |
51 | T.Operator.Word: 'bold #fff', | |
52 | T.Punctuation: '#eec591', | |
53 | } | |
54 | ||
55 | if PYG and PTK: | |
56 | d = { | |
57 | PTK.token.Token.MatchingBracket: '', | |
58 | PTK.token.Token.MatchingBracket.Cursor: '', | |
59 | PTK.token.Token.MatchingBracket.Other: 'bg:#006400' | |
60 | } | |
61 | c.TerminalInteractiveShell.highlighting_style_overrides.update(d) | |
87e4a2e8 MW |
62 | |
63 | ## Set the indent level. `Look what you made me do.' | |
64 | import IPython.core.inputsplitter as _IPCIP | |
65 | def my_find_indent(self, line): | |
66 | """Compute the new indentation level for a single line. | |
67 | ||
68 | Parameters | |
69 | ---------- | |
70 | line : str | |
71 | A single new line of non-whitespace, non-comment Python input. | |
72 | ||
73 | Returns | |
74 | ------- | |
75 | indent_spaces : int | |
76 | New value for the indent level (it may be equal to self.indent_spaces | |
77 | if indentation doesn't change. | |
78 | ||
79 | full_dedent : boolean | |
80 | Whether the new line causes a full flush-left dedent. | |
81 | """ | |
82 | indent_spaces = self.indent_spaces | |
83 | full_dedent = self._full_dedent | |
84 | ||
85 | inisp = _IPCIP.num_ini_spaces(line) | |
86 | if inisp < indent_spaces: | |
87 | indent_spaces = inisp | |
88 | if indent_spaces <= 0: | |
89 | #print 'Full dedent in text',self.source # dbg | |
90 | full_dedent = True | |
91 | ||
92 | if line.rstrip()[-1] == ':': | |
93 | indent_spaces += 2 | |
94 | elif _IPCIP.dedent_re.match(line): | |
95 | indent_spaces -= 2 | |
96 | if indent_spaces <= 0: | |
97 | full_dedent = True | |
98 | ||
99 | # Safety | |
100 | if indent_spaces < 0: | |
101 | indent_spaces = 0 | |
102 | #print 'safety' # dbg | |
103 | ||
104 | return indent_spaces, full_dedent | |
105 | _IPCIP.InputSplitter._find_indent = my_find_indent |