Skip to content

Commit

Permalink
Gets ipython working with python-mode with little config.
Browse files Browse the repository at this point in the history
* sets the default value for py-shell-name to the ipython-command
* fixes color scheme setting to set a default value
  • Loading branch information
paykroyd committed Nov 22, 2011
1 parent 65ce75f commit cbf9083
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions docs/emacs/ipython.el
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
;; can be used to convert bits of a ipython session into something that can be ;; can be used to convert bits of a ipython session into something that can be
;; used for doctests. To install, put this file somewhere in your emacs ;; used for doctests. To install, put this file somewhere in your emacs
;; `load-path' [1] and add the following line to your ~/.emacs file (the first ;; `load-path' [1] and add the following line to your ~/.emacs file (the first
;; line only needed if the default (``"ipython"``) is wrong):: ;; line only needed if the default (``"ipython"``) is wrong or ipython is not
;; in your `exec-path')::
;; ;;
;; (setq ipython-command "/SOME-PATH/ipython") ;; (setq ipython-command "/SOME-PATH/ipython")
;; (require 'ipython) ;; (require 'ipython)
Expand All @@ -36,7 +37,7 @@
;; always in ``pylab`` mode with hardcoded light-background colors, you can ;; always in ``pylab`` mode with hardcoded light-background colors, you can
;; use:: ;; use::
;; ;;
;; (setq py-python-command-args '("--pylab" "--colors=LightBG")) ;; (setq-default py-python-command-args '("--pylab" "--colors=LightBG"))
;; ;;
;; ;;
;; NOTE: This mode is currently somewhat alpha and although I hope that it ;; NOTE: This mode is currently somewhat alpha and although I hope that it
Expand Down Expand Up @@ -132,6 +133,12 @@
(require 'shell) (require 'shell)
(require 'executable) (require 'executable)
(require 'ansi-color) (require 'ansi-color)
;; XXX load python-mode, so that we can screw around with its variables
;; this has the disadvantage that python-mode is loaded even if no
;; python-file is ever edited etc. but it means that `py-shell' works
;; without loading a python-file first. Obviously screwing around with
;; python-mode's variables like this is a mess, but well.
(require 'python-mode)


(defcustom ipython-command "ipython" (defcustom ipython-command "ipython"
"*Shell command used to start ipython." "*Shell command used to start ipython."
Expand Down Expand Up @@ -164,12 +171,8 @@ the second for a 'normal' command, and the third for a multiline command.")
(if (not (executable-find ipython-command)) (if (not (executable-find ipython-command))
(message (format "Can't find executable %s - ipython.el *NOT* activated!!!" (message (format "Can't find executable %s - ipython.el *NOT* activated!!!"
ipython-command)) ipython-command))
;; XXX load python-mode, so that we can screw around with its variables ;; change the default value of py-shell-name to ipython
;; this has the disadvantage that python-mode is loaded even if no (setq-default py-shell-name ipython-command)
;; python-file is ever edited etc. but it means that `py-shell' works
;; without loading a python-file first. Obviously screwing around with
;; python-mode's variables like this is a mess, but well.
(require 'python-mode)
;; turn on ansi colors for ipython and activate completion ;; turn on ansi colors for ipython and activate completion
(defun ipython-shell-hook () (defun ipython-shell-hook ()
;; the following is to synchronize dir-changes ;; the following is to synchronize dir-changes
Expand Down Expand Up @@ -220,15 +223,16 @@ the second for a 'normal' command, and the third for a multiline command.")
(unless (delq nil (unless (delq nil
(mapcar (lambda (x) (eq (string-match "^--colors=*" x) 0)) (mapcar (lambda (x) (eq (string-match "^--colors=*" x) 0))
py-python-command-args)) py-python-command-args))
(push (format "--colors=%s" (setq-default py-python-command-args
(cond (cons (format "--colors=%s"
((eq frame-background-mode 'dark) (cond
"Linux") ((eq frame-background-mode 'dark)
((eq frame-background-mode 'light) "Linux")
"LightBG") ((eq frame-background-mode 'light)
(t ; default (backg-mode isn't always set by XEmacs) "LightBG")
"LightBG"))) (t ; default (backg-mode isn't always set by XEmacs)
py-python-command-args)) "LightBG")))
py-python-command-args)))
(when (boundp 'py-python-command) (when (boundp 'py-python-command)
(unless (equal ipython-backup-of-py-python-command py-python-command) (unless (equal ipython-backup-of-py-python-command py-python-command)
(setq ipython-backup-of-py-python-command py-python-command))) (setq ipython-backup-of-py-python-command py-python-command)))
Expand Down

0 comments on commit cbf9083

Please sign in to comment.