Size: 2390
Comment:
|
Size: 2331
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 2: | Line 2: |
There is support for using SAGE interactively from within emacs, and editing Python code in emacs: |
There is support for using SAGE interactively from within emacs, and editing Python code in emacs: |
Line 7: | Line 5: |
Line 9: | Line 6: |
(NOTE: Recent versions of Emacs have their own major mode for Python called [[href="http://cvs.savannah.gnu.org/viewvc/emacs/lisp/progmodes/python.el?root=emacs&view=log python.el]]. So those with GNU Emacs 22 or 23 shouldn't need python-mode.el. The modifications to your .emacs file suggested below will be the same, except you can remove or comment out {{{(load "python-mode")}}}.) |
(NOTE: Recent versions of Emacs have their own major mode for Python called http://cvs.savannah.gnu.org/viewvc/emacs/lisp/progmodes/python.el?root=emacs&view=log. So those with GNU Emacs 22 or 23 shouldn't need python-mode.el. The modifications to your .emacs file suggested below will be the same, except you can remove or comment out {{{(load "python-mode")}}}.) |
Line 14: | Line 9: |
Line 16: | Line 10: |
Line 18: | Line 11: |
Line 21: | Line 13: |
Line 25: | Line 16: |
(load "sage") | (load "sage") |
Line 27: | Line 18: |
Line 31: | Line 21: |
(setq auto-mode-alist (cons '("\.pyx\'" . pyrex-mode) auto-mode-alist)) (setq auto-mode-alist (cons '("\.pxd\'" . pyrex-mode) auto-mode-alist)) (setq auto-mode-alist (cons '("\.pxi\'" . python-mode) auto-mode-alist)) |
(setq auto-mode-alist (cons '("\.pyx\'" . pyrex-mode) auto-mode-alist)) (setq auto-mode-alist (cons '("\.pxd\'" . pyrex-mode) auto-mode-alist)) (setq auto-mode-alist (cons '("\.pxi\'" . python-mode) auto-mode-alist)) |
Line 37: | Line 26: |
* Start emacs. Now Python code and pyrex files are colored correctly, and there are a bunch of extra commands. |
* Start emacs. Now Python code and pyrex files are colored correctly, and there are a bunch of extra commands. |
Line 41: | Line 28: |
Line 45: | Line 29: |
If when running SAGE, the screen gets cluttered up, e.g., by the output of help, just type Ctrl-[_], i.e., Ctrl-Shift-[- key] to undo, which will remove the last chunk of output completely. |
If when running SAGE, the screen gets cluttered up, e.g., by the output of help, just type Ctrl-[_], i.e., Ctrl-Shift-[- key] to undo, which will remove the last chunk of output completely. |
Sage in Emacs
There is support for using SAGE interactively from within emacs, and editing Python code in emacs:
- Download sage.el and byte compile it, or download sage.elc.
- Download python-mode.el and byte compile it, or download python-mode.elc. This is highly recommended since it is a vast improvement over editing Python code without a special mode.
(NOTE: Recent versions of Emacs have their own major mode for Python called http://cvs.savannah.gnu.org/viewvc/emacs/lisp/progmodes/python.el?root=emacs&view=log. So those with GNU Emacs 22 or 23 shouldn't need python-mode.el. The modifications to your .emacs file suggested below will be the same, except you can remove or comment out (load "python-mode").)
- Download pyrex-mode.el and byte compile it, or download pyrex-mode.elc.
Put the .elc files all in a directory, e.g., /home/was/.emacs-scripts.
Add the following to your .emacs file, where you replace /home/was/.emacs-scripts with the directory where you put those elc files.
(add-to-list 'load-path (expand-file-name "/home/was/.emacs-scripts/")) (load "pyrex-mode") (load "python-mode") (setq ipython-command "~/bin/sage") ;; depends on where your sage is. (load "sage") (require 'ipython) (fset 'py-shell-fullscreen [?\M-x ?p ?y ?- ?s ?h ?e ?l ?l return ?\C-x ?1]) (define-key esc-map "i" 'py-shell-fullscreen) (setq auto-mode-alist (cons '("\\.pyx\\'" . pyrex-mode) auto-mode-alist)) (setq auto-mode-alist (cons '("\\.pxd\\'" . pyrex-mode) auto-mode-alist)) (setq auto-mode-alist (cons '("\\.pxi\\'" . python-mode) auto-mode-alist)) (setq auto-mode-alist (cons '("\\.sage\\'" . python-mode) auto-mode-alist))
- Start emacs. Now Python code and pyrex files are colored correctly, and there are a bunch of extra commands.
- Start emacs. Type Alt-i. A SAGE window should appear. Colors and tab completion should work. If you are in debugging mode (%pdb), then when an error occurs, an emacs window opens taking you to that point in the source code! (Note: Tab completion does not work when you run emacs with "emacs -nw".)
Hints
If when running SAGE, the screen gets cluttered up, e.g., by the output of help, just type Ctrl-[_], i.e., Ctrl-Shift-[- key] to undo, which will remove the last chunk of output completely.