From 87e4a2e8c91e928db017573db09d085e97938fd3 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Mon, 10 Apr 2023 10:00:48 +0100 Subject: [PATCH] dot/ipython-config.py: Set the indent level to two spaces like God intended. There's an option for every other thing, but not for this. --- dot/ipython-config.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/dot/ipython-config.py b/dot/ipython-config.py index 1a8c25b..f48e057 100644 --- a/dot/ipython-config.py +++ b/dot/ipython-config.py @@ -18,6 +18,7 @@ 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. @@ -58,3 +59,47 @@ if PYG and PTK: 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 -- 2.11.0