ipython keybinding

Fernando Pérez fperez528 at yahoo.com
Tue Oct 22 19:54:35 CEST 2002


John Hunter wrote:

> 
> I just installed ipython http://www-hep.colorado.edu/~fperez/ipython/.
> Wow, what a fantastic python shell.

Thanks. Glad you like it.

> So far I have just two items on my wishlist:
> 
> 1) Is it possible to bind the 'up/down' arrow keys to the same
>    function that C-n/C-p are.  The latter only bring up previous
>    commands that match what has been typed before, while the former
>    bring up the previous/next command regardless of the text entered
>    so far on the prompt.

I couldn't do it. Tried a lot, never got it to work. But if someone can figure 
it out, I'll be glad to fix it for a future release. That's how I use my 
normal shell and would love to set the same thing in ipython, but I wasn't 
able to fix this.

> 2) Is it possible to run ipython in an emacs shell, or is this in the
>    works (ala matlab-shell)?  I fear the answer is no, since the
>    default editor for the @edit command is vi, which leads me to guess
>    that Fernando is a vi user.  This is not a big requirement, since I
>    can just pop open a quick emacs session from within ipython with
>    @edit, but we emacs junkies like to do everything within one emacs
>    session, for cutting and pasting text across buffers that are
>    already open, etc...

Actually, @edit is bound to call $EDITOR. I am an XEmacs user myself, the only 
thing I know how to do with vi is 'C-Z; killall vi' when I accidentally open 
it :) You can set your editor environment variable to anything you want. I 
personally use jed for quick edits, so I set $EDITOR to that, and I use 
Xemacs for heavy-duty work. Now, with Alex Schmolck's help who patched the 
Xemacs python mode, it _is_ possible to use ipython inside emacs as your 
python shell. I just uploaded the new python-mode.el file to the download 
directory for ipython, so you can grab it from there. I also put the 
following in my emacs config file, as per Alex's instructions:

  (defun my-activate-ansi-colors ()
    (require 'ansi-color)
    (ansi-color-for-comint-mode-on))
  (add-hook 'py-shell-hook 'my-activate-ansi-colors)
  ;; Regular expression that describes tracebacks for IPython in context and
  ;; verbose mode.
  (add-hook 'python-mode-hook
            '(lambda ()
               ;; this works for @xmode verbose or context
               (setq py-traceback-line-re
                     "^\\(.+?\\) in [^\00]+?\n--> \\([0-9]+\\) +")))
  (setq py-shell-input-prompt-1-regexp "^In \\[[0-9]+\\]: "
        py-shell-input-prompt-2-regexp "^   [.][.][.]+: " )

  ;; Set IPython to be the python command and give it arguments
  (setq py-python-command "ipython")
  (setq py-python-command-args
        (cond
         ((eq frame-background-mode 'dark)
          '("-colors" "Linux"))
         ((eq frame-background-mode 'light)
          '("-colors" "LightBG"))
         (t                ; default (backg-mode isn't always set by XEmacs)
          '("-colors" "LightBG"))
         ))

Let me know if this works ok for you.

Cheers,

f.



More information about the Python-list mailing list