From: Noam Postavsky <npostavs@users.sourceforge.net>
To: "Андрей Парамонов" <cmr.pent@gmail.com>
Cc: 28580@debbugs.gnu.org
Subject: bug#28580: python.el: native completion setup failed
Date: Sun, 24 Sep 2017 13:51:19 -0400 [thread overview]
Message-ID: <87a81km1d4.fsf@users.sourceforge.net> (raw)
In-Reply-To: <CAC4Co6OeA--HnpAeeAZVx8k7MNquFn9+_CE7a3MwhjAuzHzp=g@mail.gmail.com> ("Андрей Парамонов"'s message of "Sun, 24 Sep 2017 19:56:39 +0300")
Андрей Парамонов <cmr.pent@gmail.com> writes:
> It didn't help, unfortunately: I was indeed missing pyreadline, but
> installing it from conda repo made no difference :-(
> Neither did using "-i -u" as interactive Python arg.
>
> I vaguely remember this working with older Pythons -- what could
> probably change?
Hmm, can you try running the python code from
python-shell-completion-native-setup manually from a prompt and see what
comes out? (or where it goes wrong)
def __PYTHON_EL_native_completion_setup():
try:
import readline
try:
import __builtin__
except ImportError:
# Python 3
import builtins as __builtin__
builtins = dir(__builtin__)
is_ipython = ('__IPYTHON__' in builtins or
'__IPYTHON__active' in builtins)
class __PYTHON_EL_Completer:
'''Completer wrapper that prints candidates to stdout.
It wraps an existing completer function and changes its behavior so
that the user input is unchanged and real candidates are printed to
stdout.
Returned candidates are '0__dummy_completion__' and
'1__dummy_completion__' in that order ('0__dummy_completion__' is
returned repeatedly until all possible candidates are consumed).
The real candidates are printed to stdout so that they can be
easily retrieved through comint output redirect trickery.
'''
PYTHON_EL_WRAPPED = True
def __init__(self, completer):
self.completer = completer
self.last_completion = None
self.print_mode = True
def __call__(self, text, state):
if state == 0:
# Set the first dummy completion.
self.last_completion = None
completion = '0__dummy_completion__'
else:
completion = self.completer(text, state - 1)
if not completion:
if self.last_completion != '1__dummy_completion__':
# When no more completions are available, returning a
# dummy with non-sharing prefix allow ensuring output
# while preventing changes to current input.
# Coincidentally it's also the end of output.
completion = '1__dummy_completion__'
elif completion.endswith('('):
# Remove parens on callables as it breaks completion on
# arguments (e.g. str(Ari<tab>)).
completion = completion[:-1]
self.last_completion = completion
if completion in (
'0__dummy_completion__', '1__dummy_completion__'):
return completion
elif completion:
# For every non-dummy completion, return a repeated dummy
# one and print the real candidate so it can be retrieved
# by comint output filters.
if self.print_mode:
print (completion)
return '0__dummy_completion__'
else:
return completion
else:
return completion
completer = readline.get_completer()
if not completer:
# Used as last resort to avoid breaking customizations.
import rlcompleter
completer = readline.get_completer()
if completer and not getattr(completer, 'PYTHON_EL_WRAPPED', False):
# Wrap the existing completer function only once.
new_completer = __PYTHON_EL_Completer(completer)
if not is_ipython:
readline.set_completer(new_completer)
else:
# Try both initializations to cope with all IPython versions.
# This works fine for IPython 3.x but not for earlier:
readline.set_completer(new_completer)
# IPython<3 hacks readline such that `readline.set_completer`
# won't work. This workaround injects the new completer
# function into the existing instance directly:
instance = getattr(completer, 'im_self', completer.__self__)
instance.rlcomplete = new_completer
if readline.__doc__ and 'libedit' in readline.__doc__:
readline.parse_and_bind('bind ^I rl_complete')
else:
readline.parse_and_bind('tab: complete')
# Require just one tab to send output.
readline.parse_and_bind('set show-all-if-ambiguous on')
print ('python.el: native completion setup loaded')
except:
print ('python.el: native completion setup failed')
__PYTHON_EL_native_completion_setup()
next prev parent reply other threads:[~2017-09-24 17:51 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-24 15:56 bug#28580: python.el: native completion setup failed Андрей Парамонов
2017-09-24 16:14 ` Noam Postavsky
2017-09-24 16:56 ` Андрей Парамонов
2017-09-24 17:51 ` Noam Postavsky [this message]
2017-09-24 18:02 ` Андрей Парамонов
2017-09-24 18:09 ` Noam Postavsky
2017-09-24 18:16 ` Андрей Парамонов
2017-09-24 19:39 ` Noam Postavsky
2017-09-24 19:57 ` Андрей Парамонов
2017-09-24 20:06 ` Noam Postavsky
2017-09-24 20:19 ` Андрей Парамонов
2017-09-24 20:30 ` Noam Postavsky
2017-09-24 20:34 ` Андрей Парамонов
2017-09-24 21:00 ` Noam Postavsky
2017-09-24 21:08 ` Андрей Парамонов
2017-09-24 21:31 ` Noam Postavsky
2017-09-24 21:37 ` Андрей Парамонов
2017-10-03 4:01 ` Noam Postavsky
2017-10-12 19:40 ` Noam Postavsky
2017-10-13 3:28 ` Noam Postavsky
2017-10-15 18:23 ` Noam Postavsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87a81km1d4.fsf@users.sourceforge.net \
--to=npostavs@users.sourceforge.net \
--cc=28580@debbugs.gnu.org \
--cc=cmr.pent@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.