Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions emacs_sage_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
pass

# Disable color.
ip.run_line_magic('colors', 'NoColor')
ip.run_line_magic('colors', 'nocolor')

# Disable the SQLite history.
try:
Expand Down Expand Up @@ -179,8 +179,8 @@ def all_attributes(compl_dct) -> list:


def _completions_attributes(varname) -> list[str]:
completions = ip.complete(f'{varname}.')[1]
ln = len(varname) + 1
text, completions = ip.complete(f'{varname}.')
ln = len(text)
Comment on lines +182 to +183
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to work, but I don't understand it. I tried:

sage: import IPython
sage: ip = IPython.get_ipython()
sage: ip.complete("Bi")
('Bi',
 ['Bialgebras',
  'BialgebrasWithBasis',
  'Bijectionist',
  'Bilder/',
  'Bimodules',
  'BinaryQF',
  'BinaryQF_reduced_representatives',
  'BinaryRecurrenceSequence',
  'BinaryStrings',
  'BinaryTree',
  'BinaryTrees',
  'BipartiteGraph',
  'Bitset'])

so it seems it would strip the first two letters from every result - but it doesn't! Do you know why?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# Old IPython: ip.complete("ZZ.") → ('ZZ.', ['ZZ.CartesianProduct', ...])
# len("ZZ") + 1 = 3, strip 3 from 'ZZ.CartesianProduct' → 'CartesianProduct' 

# IPython 9.x: ip.complete("ZZ.") → ('.', ['.CartesianProduct', ...])
# len("ZZ") + 1 = 3, strip 3 from '.CartesianProduct' → 'rtesianProduct' 

Seems like this

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I was not clear. The example above is with IPython 9.12.0!

sage: import IPython
sage: ip = IPython.get_ipython()
sage: ip.complete("Bij")
('Bij', ['Bijectionist'])
sage: ip.complete("Bi")
('Bi',
 ['Bialgebras',
  'BialgebrasWithBasis',
  'Bijectionist',
  'Bilder/',
  'Bimodules',
  'BinaryQF',
  'BinaryQF_reduced_representatives',
  'BinaryRecurrenceSequence',
  'BinaryStrings',
  'BinaryTree',
  'BinaryTrees',
  'BipartiteGraph',
  'Bitset'])
sage: IPython.__version__
'9.12.0'
sage: ip.complete("Bijectionist.")
('.',
 ['.category',
  '.constant_blocks',
  '.dump',
  '.dumps',
  '.get_custom_name',
  '.minimal_subdistributions_blocks_iterator',
  '.minimal_subdistributions_iterator',
  '.parent',
  '.possible_values',
  '.rename',
  '.reset_name',
  '.save',
  '.set_constant_blocks',
  '.set_distributions',
  '.set_homomesic',
  '.set_intertwining_relations',
  '.set_quadratic_relation',
  '.set_semi_conjugacy',
  '.set_statistics',
  '.set_value_restrictions',
  '.solutions_iterator',
  '.statistics_fibers',
  '.statistics_table'])

return [a[ln:] for a in completions]


Expand Down Expand Up @@ -212,7 +212,7 @@ def is_module(p: Path):
return False

if p.is_file():
if p.suffix == "py":
if p.suffix == ".py":
return p

if p.is_dir():
Expand Down