New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an API for registering magic aliases. #2124
Conversation
@@ -292,10 +285,3 @@ def rerun(self, parameter_s=''): | |||
print(histlines) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line 240 above this one, there is a
if 'rep' in h :
continue
Maybe we should change it for 'rep' in h or 'recall' in h
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, well the point of this line is to prevent matching the current line you are executing (or any previous line), however just blindly looking for 'rep' or 'recall' in the sequence is pretty fragile. Nonetheless I've included your suggestion and pushed the change.
Except from the small comment above, from which I'm not even sure what to think of it, I'm fine with merging this. |
Test results for commit c2266b1 merged into master
Not available for testing: python2.6, python3.1 |
This will need to be updated with |
I've updated this pull request to include the addition of a new method In addition, I've subsumed #2144 into this pull request (since it becomes a trivial addition). If this approach looks reasonable, I'll add some tests. (Although this is already being tested, at least a little, by the tests for |
I think that approach looks sensible. |
Looks find to me. Once this is merge, what do you think of excluding the aliases magics from |
I'd be inclined to exclude them from %lsmagic and the Qt console menus
|
Devil advocate : But for user defined alias, it would make a convenient menu... |
I think the main reason to declare an alias is to save typing for Of course, a short menu of recently used magics might have uses (like
|
Find with me, i'll do that once this one is merged. |
Add an API for registering magic aliases. Add a method `register_alias` to `MagicsManager` which can be used to register new magic aliases. Each magic alias is an instance of `MagicAlias`, a helper class whose `__call__` looks up the target of the alias (at call time) and dispatches the magic call. As a future benefit, this could be easily extended to allow for new aliases which contain some flags to pass to the function. For example, it would be easy to change the behavior to allow the creation of an `%ex` alias for `%edit -x`.
Great, clean code. I do like the idea of future uses with default flags, which matches how |
Add an API for registering magic aliases. Add a method `register_alias` to `MagicsManager` which can be used to register new magic aliases. Each magic alias is an instance of `MagicAlias`, a helper class whose `__call__` looks up the target of the alias (at call time) and dispatches the magic call. As a future benefit, this could be easily extended to allow for new aliases which contain some flags to pass to the function. For example, it would be easy to change the behavior to allow the creation of an `%ex` alias for `%edit -x`.
Original Issue:
Following up on #2086, we can also use
%alias_magic
to register%ed
,%hist
and%recall
.Since the coupling between the original function (
%edit
) and alias (%ed
) is a bit looser now, I've modified the docstring examples for%edit
to useedit
instead ofed
.New idea, as @fperez wrote in #2144:
Current Issue:
Add a method
register_alias
toMagicsManager
which can be used to register new magic aliases. Each magic alias is an instance ofMagicAlias
, a helper class whose__call__
looks up the target of the alias (at call time) and dispatches the magic call.As a future benefit, this could be easily extended to allow for new aliases which contain some flags to pass to the function. For example, it would be easy to change the behavior to allow the creation of an
%ex
alias for%edit -x
.