ioam / topographica

A general-purpose neural simulator focusing on topographic maps.
topographica.org
BSD 3-Clause "New" or "Revised" License
53 stars 32 forks source link

IPython: emacs integration #320

Closed sf-issues closed 12 years ago

sf-issues commented 12 years ago

Converted from SourceForge issue 1838016, submitted by ceball Submit Date: 2007-11-25 10:30 GMT

Provide instructions (using ipython.el) to allow Emacs users to be able to see the line of the source code where the error or breakpoint occurred.

sf-issues commented 12 years ago

Submitted by ceball Date: 2009-07-22 12:59 GMT

Does any of "http://ipython.scipy.org/moin/Cookbook/IPythonEmacs23" help?

sf-issues commented 12 years ago

Submitted by jbednar Date: 2009-11-19 13:52 GMT

Jeff P. and I discussed Emacs integration a couple of years back, and he even supplied some patches, but I have yet to do anything about it. I've attached his updated version, plus our discussion (below).

Jim

From: Jefferson P. Date: Sep 25 10:37:32 2007 -0400
On Sep 25, 2007, at 10:21 AM, James A. Bednar wrote:
> From: Jefferson P.
> Date: Sep 18 12:54:25 2007 -0400
>
>
> On Sep 12, 2007, at 4:20 PM, James A. Bednar wrote:
>
> > From: Jefferson P.
> > Date: Sep 12 15:35:53 2007 -0400
> >
> > Um... I just noticed that I seem to be using some ancient
> > python- mode.el, and that it's currently being maintained
> > on sourceforge. I guess it shouldn't be too hard to port
> > my changes into the latest version.
> >
> > D'oh! There's a topographica-mode in etc/ in the
> > topographica distribution, but it doesn't do anything
> > useful. Usually we would distribute such a thing only as a
> > patch, especially if it's currently maintained, so that we
> > can keep abreast of new versions. So once you have updated
> > it, please send me both the edited and the original so that
> > I can make a patch for distribution. Or, you can let emacs
> > do the patching, by only overriding functions and variables
> > using elisp, rather than by editing the file. Either way,
> > it would be great to have better integration with Emacs...
>
> I looked at topographica.el, but I don't really understand how
> to make derived modes. I ported my changes into the latest
> python- mode.el (from SVN at python-mode.sf.net). The
> original file and the patch are attached.
>
> Hmm. I've tried integrating that into Topographica, but haven't
> had much luck. Your original instructions said:
>
> (load "python-topo-mode.el")
> (setq py-python-command "~/bin/python")
> (setq py-topographica-command "~/bin/topographica")
> (setq py-default-interpreter 'topographica)
>
> I don't want to make everyone have to (load
> "python-topo-mode.el"), because that's not really sustainable --
> I don't want every emacs session I (or other Topo users) ever run
> to have to execute that file. So I've tried getting it to
> autoload like my old topographica.el did, but that doesn't really
> work properly so far, apparently because there are strange
> interactions between the system's python mode and your customized
> one.
>
> Have you looked at autoloading and found that it didn't work, and
> therefore did this? Just wondering, so that I don't end up redoing
> what you've already done...
I don't know. It's still vague and mysterious to me. My .emacs file
has been loading a file called 'python-mode.el' for years anyway, so
it didn't bother me much to change that line to load my own file
instead. The default python mode that comes with GNU emacs is pretty
crappy by comparison, IMO -- I don't think that the version at python-
mode.sf.net is the same. Do you get an "IM-Python" navigation menu
in your Python buffers with the system's python mode?

Yes, I do get that by default. At least on the system I'm using right now, /usr/share/emacs/site-lisp/python-mode.el is the 2001 version of the same file you've edited:

;;; python-mode.el --- Major mode for editing Python programs

;; Copyright (C) 1992,1993,1994 Tim Peters

;; Author: 1995-2001 Barry A. Warsaw ;; 1992-1994 Tim Peters ;; Maintainer: python-mode@python.org ;; Created: Feb 1992 ;; Keywords: python languages oop

(defconst py-version "$Revision: 4.6.18.2 $" "`python-mode' version number.")

So I haven't had any particular complaint about it, though I've never set up C-c C-c and C-c C-!.

| I tried modifying topographica/etc/topographica-mode.el, but I didn't
| really know what I was doing. I eventually just trashed all my
| changes because I think they were worse than useless.

Ok, I'll work under the assumption that it hasn't been done before...

Jim

sf-issues commented 12 years ago

Submitted by ceball Date: 2010-04-02 14:20 GMT

I forgot about this, but I have what seems like great integration between topographica, emacs, and ipython (in particular, debugging is much easier). Maybe I don't know what is possible, and this isn't all that great, but automatically entering the debugger when there's an error, and seeing the corresponding source code files in a split window, etc, seems pretty good..

First, I have python-mode.el (not the default that comes with emacs): https://launchpad.net/python-mode/

Second, I have ipython.el: http://ipython.scipy.org/dist/ipython.el

In my .emacs, I have:

(setq auto-mode-alist (cons '("\.py$" . python-mode) auto-mode-alist)) (setq interpreter-mode-alist (cons '("python" . python-mode) interpreter-mode-alist)) (autoload 'python-mode "python-mode" "Python editing mode." t)

;; command should just be 'ipython' but for various reasons... (setq ipython-command "/home/s0454615/t/lissomrgb/bin/ipython") (require 'ipython)

I have a modification to commandline.py to turn automatic debugging on:

--- a/topo/misc/commandline.py +++ b/topo/misc/commandline.py @@ -510,7 +510,8 @@ def process_argv(argv): IPShell(['-noconfirm_exit','-nobanner', '-pi1',CommandPrompt.get_format(), '-pi2',CommandPrompt2.get_format(),

sf-issues commented 12 years ago

Submitted by jbednar Date: 2010-04-05 13:36 GMT

Chris, your setup sounds great, but I don't see how it will find the correct Python executable to run. The problem with the standard Python modes has been that they find the standard system Python, which won't work for a Topographica installed with all dependencies in a separate directory. Does your setup only work when using the system Python? Also, does it automatically select the correct mode for .ty files, or do you have to run python-mode explicitly?

sf-issues commented 12 years ago

Submitted by ceball Date: 2010-04-10 20:16 GMT

I don't see how it will find the correct Python executable to run. The problem with the standard Python modes has been that they find the standard system Python, which won't work for a Topographica installed with all dependencies in a separate directory. Does your setup only work when using the system Python?

I'm using a copy of Topographica built from source (i.e. not using the system python).

I don't know how to make emacs find the right ipython automatically (would that even be possible?). In my .emacs file, I specify the IPython I use most often:

(setq ipython-command "/home/s0454615/t/lissomrgb/bin/ipython") (require 'ipython)

That was in the original post, so I guess you are talking about something different?

Also, does it automatically select the correct mode for .ty files, or do you have to run python-mode explicitly?

It automatically selects the correct mode for .ty files in the normal way. I didn't include this in the original post:

(add-to-list 'auto-mode-alist '("\.ty\'" . python-mode))

sf-issues commented 12 years ago

Submitted by jbednar Date: 2010-04-12 19:23 GMT

Ah, I didn't realize that the ipython executable was all it needed, i.e. that it didn't also need a path to a python executable. So that sounds pretty good; the only problem is then that we're taking over the Emacs user's Python setup, such that anything they might want to send to Python will go to Topographica's python. But now that Topographica works with a variety of Python versions, that shouldn't be a big deal. So let's document your setup and put it into our instructions.

sf-issues commented 12 years ago

Submitted by jbednar Date: 2010-07-04 16:07 GMT

Decided not to provide specific Emacs support.