X-Git-Url: https://git.distorted.org.uk/~mdw/profile/blobdiff_plain/60abf0c5588242a83f7f9c87940996727fef5f2c..48caedd7338644f7b8d1019da441939435b5b439:/dot/ipython-config.py?ds=sidebyside diff --git a/dot/ipython-config.py b/dot/ipython-config.py index 3377a2b..f48e057 100644 --- a/dot/ipython-config.py +++ b/dot/ipython-config.py @@ -1,6 +1,10 @@ ### -*-python -*- -import pygments as PYG +try: import pygments as PYG +except: PYG = None +try: import prompt_toolkit as PTK +except: PTK = None + c = get_config() ## Simple stuff. @@ -14,32 +18,88 @@ c.InteractiveShell.colors = 'Linux' c.TerminalIPythonApp.display_banner = False c.TerminalInteractiveShell.confirm_exit = False c.TerminalInteractiveShell.display_completions = 'readlinelike' +c.TerminalInteractiveShell.extra_open_editor_shortcuts = True +c.TerminalInteractiveShell.term_title = False ## Syntax colouring. -T = PYG.token -c.TerminalInteractiveShell.highlighting_style = 'emacs' -c.TerminalInteractiveShell.highlighting_style_overrides = { - T.Keyword: 'bold #fff', - T.Comment: 'italic #54ff9f', - T.Literal.Number: '#adff2f', - T.Literal.String: '#87ceff', - T.Literal.String.Escape: '#87ceff', - T.Literal.String.Interpol: '#87ceff', - T.Name: '#fff', - T.Name.Builtin: '#fff', - T.Name.Class: '#fff', - T.Name.Constant: 'italic #fff', - T.Name.Decorator: '#fff', - T.Name.Function: '#fff', - T.Name.Function.Magic: '#fff', - T.Name.Label: '#fff', - T.Name.Namespace: '#fff', - T.Name.Variable: '#fff', - T.Name.Variable.Class: '#fff', - T.Name.Variable.Global: '#fff', - T.Name.Variable.Instance: '#fff', - T.Name.Variable.Magic: '#fff', - T.Operator: '#eec591', - T.Operator.Word: 'bold #fff', - T.Punctuation: '#eec591' -} +if PYG and getattr(PYG, 'token', None): + T = PYG.token + c.TerminalInteractiveShell.highlighting_style = 'emacs' + c.TerminalInteractiveShell.highlighting_style_overrides = { + T.Keyword: 'bold #fff', + T.Comment: 'italic #54ff9f', + T.Literal.Number: '#ffff00', + T.Literal.String: '#87ceff', + T.Literal.String.Escape: '#87ceff', + T.Literal.String.Interpol: '#87ceff', + T.Name: '#fff', + T.Name.Builtin: '#fff', + T.Name.Class: '#fff', + T.Name.Constant: 'italic #fff', + T.Name.Decorator: '#fff', + T.Name.Exception: '#fff', + T.Name.Function: '#fff', + T.Name.Function.Magic: '#fff', + T.Name.Label: '#fff', + T.Name.Namespace: '#fff', + T.Name.Variable: '#fff', + T.Name.Variable.Class: '#fff', + T.Name.Variable.Global: '#fff', + T.Name.Variable.Instance: '#fff', + T.Name.Variable.Magic: '#fff', + T.Operator: '#eec591', + T.Operator.Word: 'bold #fff', + T.Punctuation: '#eec591', + } + +if PYG and PTK: + d = { + PTK.token.Token.MatchingBracket: '', + PTK.token.Token.MatchingBracket.Cursor: '', + PTK.token.Token.MatchingBracket.Other: 'bg:#006400' + } + c.TerminalInteractiveShell.highlighting_style_overrides.update(d) + +## Set the indent level. `Look what you made me do.' +import IPython.core.inputsplitter as _IPCIP +def my_find_indent(self, line): + """Compute the new indentation level for a single line. + + Parameters + ---------- + line : str + A single new line of non-whitespace, non-comment Python input. + + Returns + ------- + indent_spaces : int + New value for the indent level (it may be equal to self.indent_spaces + if indentation doesn't change. + + full_dedent : boolean + Whether the new line causes a full flush-left dedent. + """ + indent_spaces = self.indent_spaces + full_dedent = self._full_dedent + + inisp = _IPCIP.num_ini_spaces(line) + if inisp < indent_spaces: + indent_spaces = inisp + if indent_spaces <= 0: + #print 'Full dedent in text',self.source # dbg + full_dedent = True + + if line.rstrip()[-1] == ':': + indent_spaces += 2 + elif _IPCIP.dedent_re.match(line): + indent_spaces -= 2 + if indent_spaces <= 0: + full_dedent = True + + # Safety + if indent_spaces < 0: + indent_spaces = 0 + #print 'safety' # dbg + + return indent_spaces, full_dedent +_IPCIP.InputSplitter._find_indent = my_find_indent