diff --git a/docs/emacs/ipython.el b/docs/emacs/ipython.el index b1ed525..273d7d0 100644 --- a/docs/emacs/ipython.el +++ b/docs/emacs/ipython.el @@ -9,7 +9,7 @@ (defconst ipython-version "$Revision: 2927 $" "VC version number.") -;;; Commentary +;;; Commentary ;; This library makes all the functionality python-mode has when running with ;; the normal python-interpreter available for ipython, too. It also enables a ;; persistent py-shell command history across sessions (if you exit python @@ -33,7 +33,9 @@ ;; ;; You can customize the arguments passed to the IPython instance at startup by ;; setting the ``py-python-command-args`` variable. For example, to start -;; always in ``pylab`` mode with hardcoded light-background colors, you can use: +;; always in ``pylab`` mode with hardcoded light-background colors, you can +;; use:: +;; ;; (setq py-python-command-args '("-pylab" "-colors" "LightBG")) ;; ;; @@ -42,8 +44,7 @@ ;; autocompletion and a decent scheme to switch between python interpreters) ;; properly will also require changes to ipython that will likely have to wait ;; for a larger rewrite scheduled some time in the future. -;; -;; Also note that you currently NEED THE CVS VERSION OF PYTHON.EL. +;; ;; ;; Further note that I don't know whether this runs under windows or not and ;; that if it doesn't I can't really help much, not being afflicted myself. @@ -72,9 +73,9 @@ ;; ipython, you can change ``meta p`` etc. for ``control p``):: ;; ;; (require 'comint) -;; (define-key comint-mode-map [(meta p)] +;; (define-key comint-mode-map [(meta p)] ;; 'comint-previous-matching-input-from-input) -;; (define-key comint-mode-map [(meta n)] +;; (define-key comint-mode-map [(meta n)] ;; 'comint-next-matching-input-from-input) ;; (define-key comint-mode-map [(control meta n)] ;; 'comint-next-input) @@ -87,7 +88,7 @@ ;; ;; Please send comments and feedback to the ipython-list ;; () where I (a.s.) or someone else will try to -;; answer them (it helps if you specify your emacs version, OS etc; +;; answer them (it helps if you specify your emacs version, OS etc; ;; familiarity with might ;; speed up things further). ;; @@ -113,10 +114,10 @@ ;; - neither:: ;; ;; (py-shell "-c print 'FOOBAR'") -;; +;; ;; nor:: -;; -;; (let ((py-python-command-args (append py-python-command-args +;; +;; (let ((py-python-command-args (append py-python-command-args ;; '("-c" "print 'FOOBAR'")))) ;; (py-shell)) ;; @@ -134,7 +135,7 @@ (defcustom ipython-command "ipython" "*Shell command used to start ipython." - :type 'string + :type 'string :group 'python) ;; Users can set this to nil @@ -145,7 +146,7 @@ (defvar ipython-backup-of-py-python-command nil "HACK") - + (defvar ipython-de-input-prompt-regexp "\\(?: In \\[[0-9]+\\]: *.* ----+> \\(.* @@ -188,16 +189,16 @@ the second for a 'normal' command, and the third for a multiline command.") ;;XXX this is really just a cheap hack, it only completes symbols in the ;;interactive session -- useful nonetheless. (define-key py-mode-map [(meta tab)] 'ipython-complete) - + ) (add-hook 'py-shell-hook 'ipython-shell-hook) ;; Regular expression that describes tracebacks for IPython in context and - ;; verbose mode. - + ;; verbose mode. + ;;Adapt python-mode settings for ipython. ;; (this works for %xmode 'verbose' or 'context') - ;; XXX putative regexps for syntax errors; unfortunately the + ;; XXX putative regexps for syntax errors; unfortunately the ;; current python-mode traceback-line-re scheme is too primitive, ;; so it's either matching syntax errors, *or* everything else ;; (XXX: should ask Fernando for a change) @@ -207,20 +208,20 @@ the second for a 'normal' command, and the third for a multiline command.") (setq py-traceback-line-re "\\(^[^\t >].+?\\.py\\).*\n +[0-9]+[^\00]*?\n-+> \\([0-9]+\\)+") - + ;; Recognize the ipython pdb, whose prompt is 'ipdb>' or 'ipydb>' ;;instead of '(Pdb)' (setq py-pdbtrack-input-prompt "\n[(<]*[Ii]?[Pp]y?db[>)]+ ") (setq pydb-pydbtrack-input-prompt "\n[(]*ipydb[>)]+ ") - + (setq py-shell-input-prompt-1-regexp "^In \\[[0-9]+\\]: *" py-shell-input-prompt-2-regexp "^ [.][.][.]+: *" ) ;; select a suitable color-scheme (unless (member "-colors" py-python-command-args) - (setq py-python-command-args - (nconc py-python-command-args + (setq py-python-command-args + (nconc py-python-command-args (list "-colors" - (cond + (cond ((eq frame-background-mode 'dark) "Linux") ((eq frame-background-mode 'light) @@ -260,7 +261,7 @@ buffer already exists." (defadvice py-execute-region (around py-execute-buffer-ensure-process) "HACK: if `py-shell' is not active or ASYNC is explicitly desired, fall back - to python instead of ipython." + to python instead of ipython." (let ((py-which-shell (if (and (comint-check-proc "*Python*") (not async)) py-python-command ipython-backup-of-py-python-command))) @@ -274,14 +275,14 @@ be used in doctests. Example: In [1]: import sys - + In [2]: sys.stdout.write 'Hi!\n' ------> sys.stdout.write ('Hi!\n') Hi! - + In [3]: 3 + 4 Out[3]: 7 - + gets converted to: >>> import sys @@ -295,7 +296,7 @@ gets converted to: ;(message (format "###DEBUG s:%de:%d" start end)) (save-excursion (save-match-data - ;; replace ``In [3]: bla`` with ``>>> bla`` and + ;; replace ``In [3]: bla`` with ``>>> bla`` and ;; ``... : bla`` with ``... bla`` (goto-char start) (while (re-search-forward ipython-de-input-prompt-regexp end t) @@ -309,7 +310,7 @@ gets converted to: (while (re-search-forward ipython-de-output-prompt-regexp end t) (replace-match "" t nil))))) -(defvar ipython-completion-command-string +(defvar ipython-completion-command-string "print ';'.join(__IP.Completer.all_completions('%s')) #PYTHON-MODE SILENT\n" "The string send to ipython to query for all possible completions") @@ -339,19 +340,19 @@ in the current *Python* session." (completion-table nil) completion (comint-output-filter-functions - (append comint-output-filter-functions + (append comint-output-filter-functions '(ansi-color-filter-apply - (lambda (string) + (lambda (string) ;(message (format "DEBUG filtering: %s" string)) (setq ugly-return (concat ugly-return string)) - (delete-region comint-last-output-start + (delete-region comint-last-output-start (process-mark (get-buffer-process (current-buffer))))))))) ;(message (format "#DEBUG pattern: '%s'" pattern)) - (process-send-string python-process + (process-send-string python-process (format ipython-completion-command-string pattern)) (accept-process-output python-process) ;(message (format "DEBUG return: %s" ugly-return)) - (setq completions + (setq completions (split-string (substring ugly-return 0 (position ?\n ugly-return)) sep)) (setq completion-table (loop for str in completions collect (list str nil))) @@ -383,22 +384,22 @@ in the current *Python* session." ;; to let ipython have the complete line, so that context can be used ;; to do things like filename completion etc. (beg (save-excursion (skip-chars-backward "a-z0-9A-Z_./" (point-at-bol)) - (point))) + (point))) (end (point)) (pattern (buffer-substring-no-properties beg end)) (completions nil) (completion-table nil) completion (comint-preoutput-filter-functions - (append comint-preoutput-filter-functions + (append comint-preoutput-filter-functions '(ansi-color-filter-apply - (lambda (string) + (lambda (string) (setq ugly-return (concat ugly-return string)) ""))))) - (process-send-string python-process + (process-send-string python-process (format ipython-completion-command-string pattern)) (accept-process-output python-process) - (setq completions + (setq completions (split-string (substring ugly-return 0 (position ?\n ugly-return)) sep)) ;(message (format "DEBUG completions: %S" completions)) (setq completion-table (loop for str in completions diff --git a/docs/source/config/initial_config.txt b/docs/source/config/initial_config.txt index bf13599..0620f83 100644 --- a/docs/source/config/initial_config.txt +++ b/docs/source/config/initial_config.txt @@ -16,7 +16,7 @@ automatically create a user copy of the config directory for you, based on its builtin defaults. You can look at the files it creates to learn more about configuring the system. The main file you will modify to configure IPython's behavior is called ipythonrc (with a .ini -extension under Windows), included for reference in `ipythonrc`_ +extension under Windows), included for reference in `ipythonrc`_ section. This file is very commented and has many variables you can change to suit your taste, you can find more details in Sec. customization_. Here we discuss the basic things you will want to @@ -39,7 +39,7 @@ manuals. Unfortunately it seems that different Linux distributions package these files differently, so you may have to look around a bit. Below I show the contents of this directory on my system for reference:: - [html]> ls + [html]> ls about.dat acks.html dist/ ext/ index.html lib/ modindex.html stdabout.dat tut/ about.html api/ doc/ icons/ inst/ mac/ ref/ style.css @@ -71,11 +71,11 @@ EDITOR environment variable to 'emacsclient'. The code below, supplied by Francois Pinard, can then be used in your .emacs file to enable the server:: - (defvar server-buffer-clients) - (when (and (fboundp 'server-start) (string-equal (getenv "TERM") 'xterm)) - (server-start) - (defun fp-kill-server-with-buffer-routine () - (and server-buffer-clients (server-done))) + (defvar server-buffer-clients) + (when (and (fboundp 'server-start) (string-equal (getenv "TERM") 'xterm)) + (server-start) + (defun fp-kill-server-with-buffer-routine () + (and server-buffer-clients (server-done))) (add-hook 'kill-buffer-hook 'fp-kill-server-with-buffer-routine)) You can also set the value of this editor via the commmand-line option @@ -141,11 +141,11 @@ system interactively by typing '%colors Linux' at the prompt (use prompt shows garbage like:: [0;32mIn [[1;32m1[0;32m]: [0;00m - + instead of (in color) something like:: - + In [1]: - + this means that your terminal doesn't properly handle color escape sequences. You can go to a 'no color' mode by typing '%colors NoColor'. @@ -176,7 +176,7 @@ In order to configure less as your default pager, do the following: For the csh or tcsh shells, add to your ~/.cshrc file the lines:: - setenv PAGER less + setenv PAGER less setenv LESS -r There is similar syntax for other Unix shells, look at your system @@ -207,16 +207,21 @@ formats). Once you put these files in your Emacs path, all you need in your .emacs file is:: - (require 'ipython) + (require 'ipython) This should give you full support for executing code snippets via -IPython, opening IPython as your Python shell via C-c !, etc. +IPython, opening IPython as your Python shell via ``C-c !``, etc. + +You can customize the arguments passed to the IPython instance at startup by +setting the ``py-python-command-args`` variable. For example, to start always +in ``pylab`` mode with hardcoded light-background colors, you can use:: + + (setq py-python-command-args '("-pylab" "-colors" "LightBG")) If you happen to get garbage instead of colored prompts as described in the previous section, you may need to set also in your .emacs file:: - (setq ansi-color-for-comint-mode t) - + (setq ansi-color-for-comint-mode t) Notes: @@ -235,4 +240,4 @@ Notes: around the edges (although in practice, it works quite well). * Be aware that if you customize py-python-command previously, this value will override what ipython.el does (because loading the - customization variables comes later). \ No newline at end of file + customization variables comes later).