Skip to content
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

New IPython Console (Spyder 2.2+): add support for the %edit magic command #1051

Closed
spyder-bot opened this issue Feb 17, 2015 · 24 comments
Closed

Comments

@spyder-bot
Copy link
Collaborator

From pierre.raybaut on 2012-05-26T08:34:32Z

Currently, the %edit magic command will open the target filename in the default editor.

For example, on Windows platforms, typing...
edit foobar.py
...in an IPython client will open the notepad.exe to edit this file.
(grreeat!)

So, we have to hack this feature so that it allows opening files with Spyder directly, for example by using the builtin function 'open_in_spyder' (see spyderlib/widgets/externalshell/sitecustomize.py).

Original issue: http://code.google.com/p/spyderlib/issues/detail?id=1051

@spyder-bot
Copy link
Collaborator Author

From pierre.raybaut on 2012-05-27T04:42:34Z

Labels: Cat-IPythonConsole

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2012-06-08T15:48:30Z

This issue was updated by revision 828df6b70bae .

Status: Fixed

@spyder-bot
Copy link
Collaborator Author

From petrus.h...@gmail.com on 2012-06-08T22:39:42Z

I think this assumes the magic edit is already set, it fails at line 99 in start_ipython.. as .magic_edit does not exists.

I added

For issue #1051 : Use %edit to open files in Spyder

if hasattr(ipythonshell, 'magic_edit'):
ipythonshell.magic_ed = ipythonshell.magic_edit

ipythonshell.magic_edit = open_in_spyder

but ipython still thinks there is no edit set "No default editor available.
Specify a GUI text editor in the IPythonWidget.editor configurable to enable the %edit magic"

@spyder-bot
Copy link
Collaborator Author

From jed.lud...@gmail.com on 2012-06-09T15:41:39Z

I can confirm the same problem as in comment 4. issue #1087 reports the same problem.

Status: Started

@spyder-bot
Copy link
Collaborator Author

From jed.lud...@gmail.com on 2012-06-09T15:42:25Z

issue #1087 has been merged into this issue.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2012-06-09T17:06:16Z

I can't reproduce this on my end (either on Linux or on my Win XP virtual machine) but I'm working on it.

Owner: ccordoba12

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2012-06-09T17:33:57Z

Jed, what Petrus did in comment 4 solves the problem for you? I mean, at least the kernel could be started with that?

We can latter see how to set the editor correctly but at least I would like to solve the failure right now.

Cc: jed.lud...@gmail.com

@spyder-bot
Copy link
Collaborator Author

From jed.lud...@gmail.com on 2012-06-09T17:56:18Z

Actually, I didn't try Petrus's fix since it didn't really seem to result in a solution to the original goal of this issue. I should have stated my response more clearly. I experienced the same failure as issue #1087 , but I solved it by simply commenting out the two lines that were added to start_ipython_kernel.py by revision 828df6b70bae . By referring to comment 4 I was simply trying to confirm that the feature didn't seem to be working as intended.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2012-06-09T18:05:58Z

Thanks for your explanation Jed. The thing is I can't reproduce this behavior (as I said in comment 7). I removed my ipython config dir, restarted Spyder and didn't see any failure.

It seems in some situations IPython initializes magic_edit later down the road (perhaps when the kernel is started). So I'll try to move those two lines to the external console and then post a patch to see if that solves the problem.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2012-06-09T19:08:16Z

Jed, could you try this patch? Please check if %ed gets assigned to %edit, doing in the console:

%ed?

You should get the long help for %edit instead of a short message. And also check that %edit has became in open_in_spyder.

Attachment: first_try.patch

@spyder-bot
Copy link
Collaborator Author

From jed.lud...@gmail.com on 2012-06-09T19:26:10Z

I have applied the patch, and the console now launches correctly. Here are the outputs of the commands suggested in comment 11:

%ed?
Type: Magic function
Base Class: <type 'instancemethod'>
String Form:<bound method CodeMagics.ed of <IPython.core.magics.code.CodeMagics object at 0x05153C10>>
Namespace: IPython internal
File: Dynamically generated function. No source code available.
Definition: %ed(self, parameter_s='')
Docstring: Alias to %edit.

%edit? produces a really long help message. If I run %edit foo.py, I get foo.py open for editing in notepad.exe and not Spyder.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2012-06-09T21:28:27Z

Ok, I think I solved it. The magics organization inside the internal IPython namespace has changed a lot recently and that was generating the error.

Jed this second patch should work on both 0.12 and 0.13. Could you test it? Please revert my previous patch before applying this one.

Attachment: second_try.patch

@spyder-bot
Copy link
Collaborator Author

From jorisvan...@gmail.com on 2012-06-10T00:49:10Z

I can confirm that it works for me (Ubuntu 12.04, IPython 0.13dev), the IPython kernel starts and %edit opens the file in Spyder.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2012-06-10T07:09:14Z

Great, thanks Joris. I'm going to commit it right now.

@spyder-bot
Copy link
Collaborator Author

From petrus.h...@gmail.com on 2012-06-10T07:23:05Z

Sorry for not responding earlier, been offline. The patch seems to work fine (mac osx 10.7.4, IPython 0.13dev). Many thanks for this feature.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2012-06-10T07:29:17Z

This issue was updated by revision 58596d245074 .

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2012-06-10T07:30:32Z

Don't worry petrus and thanks for the confirmation.

@spyder-bot
Copy link
Collaborator Author

From petrus.h...@gmail.com on 2012-06-10T07:37:38Z

Maybe I was quick.. It seems it is only possible to edit in the dir where ipython starts, if cd'ing to another dir nothing is opened. (silently)

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2012-06-10T07:40:02Z

True. I'll take a look at it later.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2012-06-10T17:54:19Z

This issue was updated by revision be5641ea90da .

-. open_in_spyder was not working when trying to open files on directories
different from the initial one (at least on IPython consoles).
-. Print an error message if the file was not found instead of failing silently.
-. Detect if the user is trying to edit a module when the 'source' arg is a
string. This is useful for IPython because it seems all magic arguments are
strings.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2012-06-10T18:21:49Z

Ok, I've fixed the problem reported by Petrus in comment #19 and make open_in_spyder to open modules from the IPython console.

Please try it and let me know if this works for you too.

@spyder-bot
Copy link
Collaborator Author

From jed.lud...@gmail.com on 2012-06-11T07:54:15Z

This looks like it's working correctly now.

Status: Verified

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2012-07-05T20:14:35Z

Blocking: spyderlib:1053

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2015-02-15T16:14:33Z

Labels: -Component-IPython

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant