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