##// END OF EJS Templates
Update docs about emacs configuration to use pylab.
Fernando Perez -
Show More
@@ -9,7 +9,7 b''
9 9 (defconst ipython-version "$Revision: 2927 $"
10 10 "VC version number.")
11 11
12 ;;; Commentary
12 ;;; Commentary
13 13 ;; This library makes all the functionality python-mode has when running with
14 14 ;; the normal python-interpreter available for ipython, too. It also enables a
15 15 ;; persistent py-shell command history across sessions (if you exit python
@@ -33,7 +33,9 b''
33 33 ;;
34 34 ;; You can customize the arguments passed to the IPython instance at startup by
35 35 ;; setting the ``py-python-command-args`` variable. For example, to start
36 ;; always in ``pylab`` mode with hardcoded light-background colors, you can use:
36 ;; always in ``pylab`` mode with hardcoded light-background colors, you can
37 ;; use::
38 ;;
37 39 ;; (setq py-python-command-args '("-pylab" "-colors" "LightBG"))
38 40 ;;
39 41 ;;
@@ -42,8 +44,7 b''
42 44 ;; autocompletion and a decent scheme to switch between python interpreters)
43 45 ;; properly will also require changes to ipython that will likely have to wait
44 46 ;; for a larger rewrite scheduled some time in the future.
45 ;;
46 ;; Also note that you currently NEED THE CVS VERSION OF PYTHON.EL.
47 ;;
47 48 ;;
48 49 ;; Further note that I don't know whether this runs under windows or not and
49 50 ;; that if it doesn't I can't really help much, not being afflicted myself.
@@ -72,9 +73,9 b''
72 73 ;; ipython, you can change ``meta p`` etc. for ``control p``)::
73 74 ;;
74 75 ;; (require 'comint)
75 ;; (define-key comint-mode-map [(meta p)]
76 ;; (define-key comint-mode-map [(meta p)]
76 77 ;; 'comint-previous-matching-input-from-input)
77 ;; (define-key comint-mode-map [(meta n)]
78 ;; (define-key comint-mode-map [(meta n)]
78 79 ;; 'comint-next-matching-input-from-input)
79 80 ;; (define-key comint-mode-map [(control meta n)]
80 81 ;; 'comint-next-input)
@@ -87,7 +88,7 b''
87 88 ;;
88 89 ;; Please send comments and feedback to the ipython-list
89 90 ;; (<ipython-user@scipy.org>) where I (a.s.) or someone else will try to
90 ;; answer them (it helps if you specify your emacs version, OS etc;
91 ;; answer them (it helps if you specify your emacs version, OS etc;
91 92 ;; familiarity with <http://www.catb.org/~esr/faqs/smart-questions.html> might
92 93 ;; speed up things further).
93 94 ;;
@@ -113,10 +114,10 b''
113 114 ;; - neither::
114 115 ;;
115 116 ;; (py-shell "-c print 'FOOBAR'")
116 ;;
117 ;;
117 118 ;; nor::
118 ;;
119 ;; (let ((py-python-command-args (append py-python-command-args
119 ;;
120 ;; (let ((py-python-command-args (append py-python-command-args
120 121 ;; '("-c" "print 'FOOBAR'"))))
121 122 ;; (py-shell))
122 123 ;;
@@ -134,7 +135,7 b''
134 135
135 136 (defcustom ipython-command "ipython"
136 137 "*Shell command used to start ipython."
137 :type 'string
138 :type 'string
138 139 :group 'python)
139 140
140 141 ;; Users can set this to nil
@@ -145,7 +146,7 b''
145 146 (defvar ipython-backup-of-py-python-command nil
146 147 "HACK")
147 148
148
149
149 150 (defvar ipython-de-input-prompt-regexp "\\(?:
150 151 In \\[[0-9]+\\]: *.*
151 152 ----+> \\(.*
@@ -188,16 +189,16 b' the second for a \'normal\' command, and the third for a multiline command.")'
188 189 ;;XXX this is really just a cheap hack, it only completes symbols in the
189 190 ;;interactive session -- useful nonetheless.
190 191 (define-key py-mode-map [(meta tab)] 'ipython-complete)
191
192
192 193 )
193 194 (add-hook 'py-shell-hook 'ipython-shell-hook)
194 195 ;; Regular expression that describes tracebacks for IPython in context and
195 ;; verbose mode.
196
196 ;; verbose mode.
197
197 198 ;;Adapt python-mode settings for ipython.
198 199 ;; (this works for %xmode 'verbose' or 'context')
199 200
200 ;; XXX putative regexps for syntax errors; unfortunately the
201 ;; XXX putative regexps for syntax errors; unfortunately the
201 202 ;; current python-mode traceback-line-re scheme is too primitive,
202 203 ;; so it's either matching syntax errors, *or* everything else
203 204 ;; (XXX: should ask Fernando for a change)
@@ -207,20 +208,20 b' the second for a \'normal\' command, and the third for a multiline command.")'
207 208 (setq py-traceback-line-re
208 209 "\\(^[^\t >].+?\\.py\\).*\n +[0-9]+[^\00]*?\n-+> \\([0-9]+\\)+")
209 210
210
211
211 212 ;; Recognize the ipython pdb, whose prompt is 'ipdb>' or 'ipydb>'
212 213 ;;instead of '(Pdb)'
213 214 (setq py-pdbtrack-input-prompt "\n[(<]*[Ii]?[Pp]y?db[>)]+ ")
214 215 (setq pydb-pydbtrack-input-prompt "\n[(]*ipydb[>)]+ ")
215
216
216 217 (setq py-shell-input-prompt-1-regexp "^In \\[[0-9]+\\]: *"
217 218 py-shell-input-prompt-2-regexp "^ [.][.][.]+: *" )
218 219 ;; select a suitable color-scheme
219 220 (unless (member "-colors" py-python-command-args)
220 (setq py-python-command-args
221 (nconc py-python-command-args
221 (setq py-python-command-args
222 (nconc py-python-command-args
222 223 (list "-colors"
223 (cond
224 (cond
224 225 ((eq frame-background-mode 'dark)
225 226 "Linux")
226 227 ((eq frame-background-mode 'light)
@@ -260,7 +261,7 b' buffer already exists."'
260 261
261 262 (defadvice py-execute-region (around py-execute-buffer-ensure-process)
262 263 "HACK: if `py-shell' is not active or ASYNC is explicitly desired, fall back
263 to python instead of ipython."
264 to python instead of ipython."
264 265 (let ((py-which-shell (if (and (comint-check-proc "*Python*") (not async))
265 266 py-python-command
266 267 ipython-backup-of-py-python-command)))
@@ -274,14 +275,14 b' be used in doctests. Example:'
274 275
275 276
276 277 In [1]: import sys
277
278
278 279 In [2]: sys.stdout.write 'Hi!\n'
279 280 ------> sys.stdout.write ('Hi!\n')
280 281 Hi!
281
282
282 283 In [3]: 3 + 4
283 284 Out[3]: 7
284
285
285 286 gets converted to:
286 287
287 288 >>> import sys
@@ -295,7 +296,7 b' gets converted to:'
295 296 ;(message (format "###DEBUG s:%de:%d" start end))
296 297 (save-excursion
297 298 (save-match-data
298 ;; replace ``In [3]: bla`` with ``>>> bla`` and
299 ;; replace ``In [3]: bla`` with ``>>> bla`` and
299 300 ;; ``... : bla`` with ``... bla``
300 301 (goto-char start)
301 302 (while (re-search-forward ipython-de-input-prompt-regexp end t)
@@ -309,7 +310,7 b' gets converted to:'
309 310 (while (re-search-forward ipython-de-output-prompt-regexp end t)
310 311 (replace-match "" t nil)))))
311 312
312 (defvar ipython-completion-command-string
313 (defvar ipython-completion-command-string
313 314 "print ';'.join(__IP.Completer.all_completions('%s')) #PYTHON-MODE SILENT\n"
314 315 "The string send to ipython to query for all possible completions")
315 316
@@ -339,19 +340,19 b' in the current *Python* session."'
339 340 (completion-table nil)
340 341 completion
341 342 (comint-output-filter-functions
342 (append comint-output-filter-functions
343 (append comint-output-filter-functions
343 344 '(ansi-color-filter-apply
344 (lambda (string)
345 (lambda (string)
345 346 ;(message (format "DEBUG filtering: %s" string))
346 347 (setq ugly-return (concat ugly-return string))
347 (delete-region comint-last-output-start
348 (delete-region comint-last-output-start
348 349 (process-mark (get-buffer-process (current-buffer)))))))))
349 350 ;(message (format "#DEBUG pattern: '%s'" pattern))
350 (process-send-string python-process
351 (process-send-string python-process
351 352 (format ipython-completion-command-string pattern))
352 353 (accept-process-output python-process)
353 354 ;(message (format "DEBUG return: %s" ugly-return))
354 (setq completions
355 (setq completions
355 356 (split-string (substring ugly-return 0 (position ?\n ugly-return)) sep))
356 357 (setq completion-table (loop for str in completions
357 358 collect (list str nil)))
@@ -383,22 +384,22 b' in the current *Python* session."'
383 384 ;; to let ipython have the complete line, so that context can be used
384 385 ;; to do things like filename completion etc.
385 386 (beg (save-excursion (skip-chars-backward "a-z0-9A-Z_./" (point-at-bol))
386 (point)))
387 (point)))
387 388 (end (point))
388 389 (pattern (buffer-substring-no-properties beg end))
389 390 (completions nil)
390 391 (completion-table nil)
391 392 completion
392 393 (comint-preoutput-filter-functions
393 (append comint-preoutput-filter-functions
394 (append comint-preoutput-filter-functions
394 395 '(ansi-color-filter-apply
395 (lambda (string)
396 (lambda (string)
396 397 (setq ugly-return (concat ugly-return string))
397 398 "")))))
398 (process-send-string python-process
399 (process-send-string python-process
399 400 (format ipython-completion-command-string pattern))
400 401 (accept-process-output python-process)
401 (setq completions
402 (setq completions
402 403 (split-string (substring ugly-return 0 (position ?\n ugly-return)) sep))
403 404 ;(message (format "DEBUG completions: %S" completions))
404 405 (setq completion-table (loop for str in completions
@@ -16,7 +16,7 b' automatically create a user copy of the config directory for you,'
16 16 based on its builtin defaults. You can look at the files it creates to
17 17 learn more about configuring the system. The main file you will modify
18 18 to configure IPython's behavior is called ipythonrc (with a .ini
19 extension under Windows), included for reference in `ipythonrc`_
19 extension under Windows), included for reference in `ipythonrc`_
20 20 section. This file is very commented and has many variables you can
21 21 change to suit your taste, you can find more details in
22 22 Sec. customization_. Here we discuss the basic things you will want to
@@ -39,7 +39,7 b' manuals. Unfortunately it seems that different Linux distributions'
39 39 package these files differently, so you may have to look around a bit.
40 40 Below I show the contents of this directory on my system for reference::
41 41
42 [html]> ls
42 [html]> ls
43 43 about.dat acks.html dist/ ext/ index.html lib/ modindex.html
44 44 stdabout.dat tut/ about.html api/ doc/ icons/ inst/ mac/ ref/ style.css
45 45
@@ -71,11 +71,11 b" EDITOR environment variable to 'emacsclient'. The code below, supplied"
71 71 by Francois Pinard, can then be used in your .emacs file to enable the
72 72 server::
73 73
74 (defvar server-buffer-clients)
75 (when (and (fboundp 'server-start) (string-equal (getenv "TERM") 'xterm))
76 (server-start)
77 (defun fp-kill-server-with-buffer-routine ()
78 (and server-buffer-clients (server-done)))
74 (defvar server-buffer-clients)
75 (when (and (fboundp 'server-start) (string-equal (getenv "TERM") 'xterm))
76 (server-start)
77 (defun fp-kill-server-with-buffer-routine ()
78 (and server-buffer-clients (server-done)))
79 79 (add-hook 'kill-buffer-hook 'fp-kill-server-with-buffer-routine))
80 80
81 81 You can also set the value of this editor via the commmand-line option
@@ -141,11 +141,11 b" system interactively by typing '%colors Linux' at the prompt (use"
141 141 prompt shows garbage like::
142 142
143 143 [0;32mIn [[1;32m1[0;32m]: [0;00m
144
144
145 145 instead of (in color) something like::
146
146
147 147 In [1]:
148
148
149 149 this means that your terminal doesn't properly handle color escape
150 150 sequences. You can go to a 'no color' mode by typing '%colors NoColor'.
151 151
@@ -176,7 +176,7 b' In order to configure less as your default pager, do the following:'
176 176
177 177 For the csh or tcsh shells, add to your ~/.cshrc file the lines::
178 178
179 setenv PAGER less
179 setenv PAGER less
180 180 setenv LESS -r
181 181
182 182 There is similar syntax for other Unix shells, look at your system
@@ -207,16 +207,21 b' formats).'
207 207 Once you put these files in your Emacs path, all you need in your .emacs
208 208 file is::
209 209
210 (require 'ipython)
210 (require 'ipython)
211 211
212 212 This should give you full support for executing code snippets via
213 IPython, opening IPython as your Python shell via C-c !, etc.
213 IPython, opening IPython as your Python shell via ``C-c !``, etc.
214
215 You can customize the arguments passed to the IPython instance at startup by
216 setting the ``py-python-command-args`` variable. For example, to start always
217 in ``pylab`` mode with hardcoded light-background colors, you can use::
218
219 (setq py-python-command-args '("-pylab" "-colors" "LightBG"))
214 220
215 221 If you happen to get garbage instead of colored prompts as described in
216 222 the previous section, you may need to set also in your .emacs file::
217 223
218 (setq ansi-color-for-comint-mode t)
219
224 (setq ansi-color-for-comint-mode t)
220 225
221 226 Notes:
222 227
@@ -235,4 +240,4 b' Notes:'
235 240 around the edges (although in practice, it works quite well).
236 241 * Be aware that if you customize py-python-command previously, this
237 242 value will override what ipython.el does (because loading the
238 customization variables comes later). No newline at end of file
243 customization variables comes later).
General Comments 0
You need to be logged in to leave comments. Login now