Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
7e14db6
First full decoupling of magics into a standalone object.
fperez May 8, 2012
f26fdb6
Simplify logic of passing local scope to magics that need it.
fperez May 8, 2012
09ab697
Fix automagic detection.
fperez May 9, 2012
c0117b5
Fix access from magics to shell storage database.
fperez May 9, 2012
8c87551
Fix pylab support and simplify approach to reduce global state in mai…
fperez May 9, 2012
1244bdc
Fix history (was accessing directly shell methods)
fperez May 9, 2012
7233d8b
Fix more failures due to direct shell access in magics.
fperez May 9, 2012
2b8793f
Simplify line info code.
fperez May 9, 2012
e223878
Move extract_input_lines to main shell object, where it belongs.
fperez May 9, 2012
c92f639
Fix failing test that did direct magic access.
fperez May 9, 2012
0989779
Fix remaining test failures.
fperez May 9, 2012
6c6e057
Major restructuring of magics, breaking them up into separate classes.
fperez May 13, 2012
b0d78b6
Create class for user-defined magics.
fperez May 13, 2012
da012c2
Separate magic code into base file and implementation of magics.
fperez May 13, 2012
ebb8b70
Update decorator module in externals to version 3.3.3 (upstream).
fperez May 13, 2012
2cba502
Implement magic registration and listing in magics manager.
fperez May 14, 2012
0570766
Add all decorators to tag magics.
fperez May 14, 2012
f7dab01
Add proper initialization of magics to main shell instance.
fperez May 14, 2012
07b7cbf
Fix magic decorator logic so we correctly fetch bound instance methods.
fperez May 14, 2012
3f85cbc
Fix %lsmagic
fperez May 14, 2012
e3752a8
Fix %magic
fperez May 14, 2012
580a081
Remove unnecessary metaclass and allow registration of magic classes.
fperez May 14, 2012
9966c19
Fix tab completion for magics, though cell magics are ignored for now.
fperez May 14, 2012
cfd2d6a
Fix %run
fperez May 14, 2012
55dfb45
Cleaner magics constructor
fperez May 14, 2012
8e278df
Fix a few references to old-style names
fperez May 14, 2012
f94a762
Update history magics to new API.
fperez May 19, 2012
e8c0cba
Clean up magic registration api and make it public.
fperez May 20, 2012
65eda9a
Fix simple comment.
fperez May 21, 2012
30e7535
Update storemagic extension to new API
fperez May 22, 2012
9c7626b
Settle on cleaner API for magic registration.
fperez May 22, 2012
145a4ac
Update autoreload: new magics api, various format fixes.
fperez May 22, 2012
a72dc83
Update terminal-only magics to new API.
fperez May 22, 2012
1b3fc25
Update parallelmagics to new magic API.
fperez May 22, 2012
b905841
Update mglob to new magic API.
fperez May 22, 2012
5df304c
Update embedded shell to new magics API.
fperez May 22, 2012
cc0d5b3
Fix various test failures from then new magics API.
fperez May 22, 2012
ed048d4
Fix a few more test failures from magic API changes.
fperez May 22, 2012
4927abd
Fix invalid attribute accesses in magics code.
fperez May 22, 2012
b1c2e30
Fix bugs in completer.py with incompletely-implemented property.
fperez May 22, 2012
ed77ecc
Fix invalid attribute access in parallelmagic
fperez May 22, 2012
6c9a575
Several fixes to autoreload extension for new API.
fperez May 22, 2012
f179c85
Fix import for zmqshell
fperez May 22, 2012
dd9ca73
Fix %pylab magic.
fperez May 22, 2012
f44bd72
Fix parallel tests to work with new magic API.
fperez May 22, 2012
bd70445
Fix tests in autoreload extension for new API.
fperez May 22, 2012
20badbe
Fix call to set_next_input to happen on shell object
fperez May 22, 2012
894a639
First working version of cell magic support.
fperez May 22, 2012
5d763af
Update api names as per review discussion.
fperez May 22, 2012
781e85b
Simplify parallelmagics by removing unnecessary plugin.
fperez May 22, 2012
fe287d7
Create new core.magics package and start populating with history.
fperez May 22, 2012
daebec6
Move UserMagics to core.magics
fperez May 22, 2012
302f198
Cleanup of storemagic with pyflakes.
fperez May 23, 2012
64de6d7
Create core.magics.basic according to new API.
fperez May 23, 2012
21bd601
Create core.magics.code according to new API.
fperez May 23, 2012
bb38a61
Create core.magics.config according to new API.
fperez May 23, 2012
020e4ff
Create core.magics.namespace according to new API.
fperez May 23, 2012
2d703c4
Create core.magics.execution according to new API.
fperez May 23, 2012
d53e149
Create core.magics.auto according to new API.
fperez May 23, 2012
e5bbe65
Create core.magics.osm according to new API.
fperez May 23, 2012
47dea02
Create core.magics.logging according to new API.
fperez May 23, 2012
16abc36
Create core.magics.extension according to new API.
fperez May 23, 2012
7fd6a54
Create core.magics.pylab according to new API.
fperez May 23, 2012
b36afb8
Create core.magics.deprecated according to new API.
fperez May 23, 2012
659282d
Fix failing tests in core and zmq
fperez May 23, 2012
6854bb5
Fix parallel tests
fperez May 23, 2012
b7491ba
Create decorators for standalone magic functions, as per review.x
fperez May 24, 2012
1f1d8fa
Renamed @register_magics to @magics_class to avoid confusion.
fperez May 24, 2012
3f192dc
Remove next_input nonsense in magic calls (but keep functionality).
fperez May 24, 2012
df87cbe
Add first set of cell magic tests.
fperez May 24, 2012
1a856e1
First implementation of cell magics that goes via inputsplitter.
fperez May 24, 2012
089a601
Remove stray code and update to use 'in' instead of 'has_key'.
fperez May 24, 2012
720ddcc
First working version of cell magics in inputsplitter in line mode.
fperez May 25, 2012
b89562b
Working implementation of cell mode with regular expressions - cleaner.
fperez May 25, 2012
a7d2e27
Refine regexp checks for end of blocks logic.
fperez May 25, 2012
03d77d1
Add a few more fixes to cell/line input code, switch approaches.
fperez May 25, 2012
b49896d
Fixes for the text console.
fperez May 25, 2012
cb344b6
Improve error messages for line/cell magics.
fperez May 25, 2012
7b8fa8a
Make cell magic input only allow one blank line for consistency.
fperez May 25, 2012
7d068b4
Clean up implementation of cell magics in inputsplitter.
fperez May 26, 2012
9bb583c
Small fixes as per @certik's review.
fperez May 26, 2012
cf15c8f
Fix contextlib imports for python3 as per @takluyver's review.
fperez May 26, 2012
b537de1
Minor fixes as per @Carreau's review
fperez May 26, 2012
b3a081f
Support PYTHONPATH in zmq tests.
fperez May 26, 2012
681e926
Ensure pythonpath is applied to test env only if present.
fperez May 26, 2012
b29fa5a
Add completion support for cell magics and handling of line/cell magics.
fperez May 26, 2012
954dc34
Ensure that all public magic decorators have descriptive docstrings.
fperez May 26, 2012
5472873
Improve decorator docstrings and clarify execution context for functi…
fperez May 26, 2012
6f16ed9
Add tests for object inspector with magics of all types.
fperez May 27, 2012
9961b83
Clarify that automagic is only for line magics.
fperez May 27, 2012
446d504
Add support for finding cell magics with ?/??.
fperez May 27, 2012
d2a11a7
Fix split_user_input to correctly handle %% escape for cell magics.
fperez May 27, 2012
520fed4
Fix handling of lines like '%%foo?' in cell magic logic.
fperez May 27, 2012
904b6c7
Fix '%%cellm?' case, make tests more stringent to catch error.
fperez May 27, 2012
3e1b62f
Add docstrings as per review.
fperez May 27, 2012
fef3928
Complete documenting magic module, as per review.
fperez May 27, 2012
84ad7d2
Rename a few methods as per review, also complete some docstrings.
fperez May 27, 2012
c28b7cf
Fix test failures under Python 3.
fperez May 27, 2012
f50a0ab
Document cell magics in %magic.
fperez May 27, 2012
16171ea
Update interactive usage message (used by %quickref and others).
fperez May 27, 2012
787e286
Implement %%timeit as a cell level magic.
fperez May 27, 2012
8045334
Implement %%prun as a cell magic too.
fperez May 27, 2012
0876e92
Update the main documentation with new magics API.
fperez May 27, 2012
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
56 changes: 36 additions & 20 deletions IPython/core/completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,14 @@
# proper procedure is to maintain its copyright as belonging to the Python
# Software Foundation (in addition to my own, for all new code).
#
# Copyright (C) 2008-2011 IPython Development Team
# Copyright (C) 2001-2007 Fernando Perez. <fperez@colorado.edu>
# Copyright (C) 2008 IPython Development Team
# Copyright (C) 2001 Fernando Perez. <fperez@colorado.edu>
# Copyright (C) 2001 Python Software Foundation, www.python.org
#
# Distributed under the terms of the BSD License. The full license is in
# the file COPYING, distributed as part of this software.
#
#*****************************************************************************
from __future__ import print_function

#-----------------------------------------------------------------------------
# Imports
Expand Down Expand Up @@ -178,11 +177,14 @@ def compress_user(path, tilde_expand, tilde_val):
else:
return path


class Bunch(object): pass


DELIMS = ' \t\n`!@#$^&*()=+[{]}\\|;:\'",<>?'
GREEDY_DELIMS = ' \r\n'


class CompletionSplitter(object):
"""An object to split an input line in a manner similar to readline.

Expand All @@ -194,7 +196,7 @@ class CompletionSplitter(object):

What characters are used as splitting delimiters can be controlled by
setting the `delims` attribute (this is a property that internally
automatically builds the necessary """
automatically builds the necessary regular expression)"""

# Private interface

Expand All @@ -212,19 +214,21 @@ class CompletionSplitter(object):

def __init__(self, delims=None):
delims = CompletionSplitter._delims if delims is None else delims
self.set_delims(delims)
self.delims = delims

@property
def delims(self):
"""Return the string of delimiter characters."""
return self._delims

def set_delims(self, delims):
@delims.setter
def delims(self, delims):
"""Set the delimiters for line splitting."""
expr = '[' + ''.join('\\'+ c for c in delims) + ']'
self._delim_re = re.compile(expr)
self._delims = delims
self._delim_expr = expr

def get_delims(self):
"""Return the string of delimiter characters."""
return self._delims

def split_line(self, line, cursor_pos=None):
"""Split a line of text with a cursor at the given position.
"""
Expand Down Expand Up @@ -377,7 +381,7 @@ def attr_matches(self, text):
def get__all__entries(obj):
"""returns the strings in the __all__ attribute"""
try:
words = getattr(obj,'__all__')
words = getattr(obj, '__all__')
except:
return []

Expand All @@ -390,12 +394,12 @@ class IPCompleter(Completer):
def _greedy_changed(self, name, old, new):
"""update the splitter and readline delims when greedy is changed"""
if new:
self.splitter.set_delims(GREEDY_DELIMS)
self.splitter.delims = GREEDY_DELIMS
else:
self.splitter.set_delims(DELIMS)
self.splitter.delims = DELIMS

if self.readline:
self.readline.set_completer_delims(self.splitter.get_delims())
self.readline.set_completer_delims(self.splitter.delims)

merge_completions = CBool(True, config=True,
help="""Whether to merge completion results into a single list
Expand Down Expand Up @@ -472,7 +476,7 @@ def __init__(self, shell=None, namespace=None, global_namespace=None,

# List where completion matches will be stored
self.matches = []
self.shell = shell.shell
self.shell = shell
if alias_table is None:
alias_table = {}
self.alias_table = alias_table
Expand Down Expand Up @@ -601,11 +605,23 @@ def magic_matches(self, text):
"""Match magics"""
#print 'Completer->magic_matches:',text,'lb',self.text_until_cursor # dbg
# Get all shell magics now rather than statically, so magics loaded at
# runtime show up too
magics = self.shell.lsmagic()
# runtime show up too.
lsm = self.shell.magics_manager.lsmagic()
line_magics = lsm['line']
cell_magics = lsm['cell']
pre = self.magic_escape
baretext = text.lstrip(pre)
return [ pre+m for m in magics if m.startswith(baretext)]
pre2 = pre+pre

# Completion logic:
# - user gives %%: only do cell magics
# - user gives %: do both line and cell magics
# - no prefix: do both
# In other words, line magics are skipped if the user gives %% explicitly
bare_text = text.lstrip(pre)
comp = [ pre2+m for m in cell_magics if m.startswith(bare_text)]
if not text.startswith(pre2):
comp += [ pre+m for m in line_magics if m.startswith(bare_text)]
return comp

def alias_matches(self, text):
"""Match internal system aliases"""
Expand Down Expand Up @@ -820,7 +836,7 @@ def complete(self, text=None, line_buffer=None, cursor_pos=None):

self.line_buffer = line_buffer
self.text_until_cursor = self.line_buffer[:cursor_pos]
#io.rprint('\nCOMP2 %r %r %r' % (text, line_buffer, cursor_pos)) # dbg
#io.rprint('COMP2 %r %r %r' % (text, line_buffer, cursor_pos)) # dbg

# Start with a clean slate of completions
self.matches[:] = []
Expand Down
Loading