From a18858802b09d1cd2b24d3b1acb7dc5e078a35b9 2016-06-30 21:55:15 From: Matthias Bussonnier Date: 2016-06-30 21:55:15 Subject: [PATCH] Remove readline related code. Pass 1 --- diff --git a/IPython/core/completer.py b/IPython/core/completer.py index 16c2942..ba8cdcd 100644 --- a/IPython/core/completer.py +++ b/IPython/core/completer.py @@ -1,50 +1,13 @@ # encoding: utf-8 """Word completion for IPython. -This module is a fork of the rlcompleter module in the Python standard +This module stared as fork of the rlcompleter module in the Python standard library. The original enhancements made to rlcompleter have been sent -upstream and were accepted as of Python 2.3, but we need a lot more -functionality specific to IPython, so this module will continue to live as an -IPython-specific utility. +upstream and were accepted as of Python 2.3, -Original rlcompleter documentation: -This requires the latest extension to the readline module (the -completes keywords, built-ins and globals in __main__; when completing -NAME.NAME..., it evaluates (!) the expression up to the last dot and -completes its attributes. - -It's very cool to do "import string" type "string.", hit the -completion key (twice), and see the list of names defined by the -string module! - -Tip: to use the tab key as the completion key, call - - readline.parse_and_bind("tab: complete") - -Notes: - -- Exceptions raised by the completer function are *ignored* (and - generally cause the completion to fail). This is a feature -- since - readline sets the tty device in raw (or cbreak) mode, printing a - traceback wouldn't work well without some complicated hoopla to save, - reset and restore the tty state. - -- The evaluation of the NAME.NAME... form may cause arbitrary - application defined code to be executed if an object with a - ``__getattr__`` hook is found. Since it is the responsibility of the - application (or the user) to enable this feature, I consider this an - acceptable risk. More complicated expressions (e.g. function calls or - indexing operations) are *not* evaluated. - -- GNU readline is also used by the built-in functions input() and - raw_input(), and thus these also benefit/suffer from the completer - features. Clearly an interactive application can benefit by - specifying its own completer function and using raw_input() for all - its input. - -- When the original stdin is not a tty device, GNU readline is never - used, and this module (and the readline module) are silently inactive. +This is now mostly Completer implementation made to function with +prompt_toolkit, but that should still work with readline. """ # Copyright (c) IPython Development Team. @@ -1211,66 +1174,3 @@ class IPCompleter(Completer): self.matches = sorted(set(self.matches), key=completions_sorting_key) return text, self.matches - - def rlcomplete(self, text, state): - """Return the state-th possible completion for 'text'. - - This is called successively with state == 0, 1, 2, ... until it - returns None. The completion should begin with 'text'. - - Parameters - ---------- - text : string - Text to perform the completion on. - - state : int - Counter used by readline. - """ - if state==0: - - self.line_buffer = line_buffer = self.readline.get_line_buffer() - cursor_pos = self.readline.get_endidx() - - #io.rprint("\nRLCOMPLETE: %r %r %r" % - # (text, line_buffer, cursor_pos) ) # dbg - - # if there is only a tab on a line with only whitespace, instead of - # the mostly useless 'do you want to see all million completions' - # message, just do the right thing and give the user his tab! - # Incidentally, this enables pasting of tabbed text from an editor - # (as long as autoindent is off). - - # It should be noted that at least pyreadline still shows file - # completions - is there a way around it? - - # don't apply this on 'dumb' terminals, such as emacs buffers, so - # we don't interfere with their own tab-completion mechanism. - if not (self.dumb_terminal or line_buffer.strip()): - self.readline.insert_text('\t') - sys.stdout.flush() - return None - - # Note: debugging exceptions that may occur in completion is very - # tricky, because readline unconditionally silences them. So if - # during development you suspect a bug in the completion code, turn - # this flag on temporarily by uncommenting the second form (don't - # flip the value in the first line, as the '# dbg' marker can be - # automatically detected and is used elsewhere). - DEBUG = False - #DEBUG = True # dbg - if DEBUG: - try: - self.complete(text, line_buffer, cursor_pos) - except: - import traceback; traceback.print_exc() - else: - # The normal production version is here - - # This method computes the self.matches array - self.complete(text, line_buffer, cursor_pos) - - try: - return self.matches[state] - except IndexError: - return None - diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index c170efc..7b686f9 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -343,9 +343,6 @@ class InteractiveShell(SingletonConfigurable): Automatically call the pdb debugger after every exception. """ ).tag(config=True) - multiline_history = Bool(sys.platform != 'win32', - help="Save multi-line entries as one entry in readline history" - ).tag(config=True) display_page = Bool(False, help="""If True, anything that would be passed to the pager will be displayed as regular output instead.""" @@ -387,40 +384,10 @@ class InteractiveShell(SingletonConfigurable): history_load_length = Integer(1000, help= """ The number of saved history entries to be loaded - into the readline buffer at startup. + into the history buffer at startup. """ ).tag(config=True) - # The readline stuff will eventually be moved to the terminal subclass - # but for now, we can't do that as readline is welded in everywhere. - readline_use = Bool(True).tag(config=True) - readline_remove_delims = Unicode('-/~').tag(config=True) - readline_delims = Unicode() # set by init_readline() - # don't use \M- bindings by default, because they - # conflict with 8-bit encodings. See gh-58,gh-88 - readline_parse_and_bind = List([ - 'tab: complete', - '"\C-l": clear-screen', - 'set show-all-if-ambiguous on', - '"\C-o": tab-insert', - '"\C-r": reverse-search-history', - '"\C-s": forward-search-history', - '"\C-p": history-search-backward', - '"\C-n": history-search-forward', - '"\e[A": history-search-backward', - '"\e[B": history-search-forward', - '"\C-k": kill-line', - '"\C-u": unix-line-discard', - ]).tag(config=True) - - _custom_readline_config = False - - @observe('readline_parse_and_bind') - def _readline_parse_and_bind_changed(self, change): - # notice that readline config is customized - # indicates that it should have higher priority than inputrc - self._custom_readline_config = True - ast_node_interactivity = Enum(['all', 'last', 'last_expr', 'none'], default_value='last_expr', help=""" diff --git a/IPython/core/usage.py b/IPython/core/usage.py index 21de20b..a3d17dd 100644 --- a/IPython/core/usage.py +++ b/IPython/core/usage.py @@ -109,12 +109,9 @@ MAIN FEATURES variable names, and show you a list of the possible completions if there's no unambiguous one. It will also complete filenames in the current directory. - This feature requires the readline and rlcomplete modules, so it won't work - if your Python lacks readline support (such as under Windows). +* Search previous command history in two ways: -* Search previous command history in two ways (also requires readline): - - - Start typing, and then use Ctrl-p (previous,up) and Ctrl-n (next,down) to + - Start typing, and then use Ctrl-p (previous, up) and Ctrl-n (next,down) to search through only the history items that match what you've typed so far. If you use Ctrl-p/Ctrl-n at a blank prompt, they just behave like normal arrow keys. @@ -123,7 +120,7 @@ MAIN FEATURES your history for lines that match what you've typed so far, completing as much as it can. - - %hist: search history by index (this does *not* require readline). + - %hist: search history by index. * Persistent command history across sessions. @@ -255,7 +252,6 @@ MAIN FEATURES interactive_usage_min = """\ An enhanced console for Python. Some of its features are: -- Readline support if the readline library is present. - Tab completion in the local namespace. - Logging of input, see command-line options. - System shell escape via ! , eg !ls. diff --git a/setup.py b/setup.py index 8d78f93..d23d5eb 100755 --- a/setup.py +++ b/setup.py @@ -220,20 +220,8 @@ if not any(arg.startswith('bdist') for arg in sys.argv): if sys.platform == 'darwin': install_requires.extend(['appnope']) - have_readline = False - try: - import readline - except ImportError: - pass - else: - if 'libedit' not in readline.__doc__: - have_readline = True - if not have_readline: - install_requires.extend(['gnureadline']) - - if sys.platform.startswith('win'): - extras_require['terminal'].append('pyreadline>=2.0') - else: + + if not sys.platform.startswith('win'): install_requires.append('pexpect') # workaround pypa/setuptools#147, where setuptools misspells