Differences between revisions 3 and 21 (spanning 18 versions)
Revision 3 as of 2008-06-29 22:34:59
Size: 2331
Editor: schilly
Comment:
Revision 21 as of 2023-02-23 20:10:56
Size: 2804
Editor: mkoeppe
Comment: trac->gh
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
= Sage in Emacs =
There is support for using SAGE interactively from within emacs, and editing Python code in emacs:
{{https://www.gnu.org/software/emacs/images/emacs.png||width=128px}}
Line 4: Line 3:
 * 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")}}}.)
= Sage and Emacs =
Line 8: Line 5:
 * 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.
The purpose of this page is to collect tips and tricks for Sage users
and developers using the text editor Emacs as an [[IDE]].

== sage-shell-mode ==

[[https://github.com/stakemori/sage-shell-mode|sage-shell-mode]] is the recommended mode for Sage in Emacs. This mode provides two features:

1. Run a Sage shell inside Emacs, fully equipped with command history,
completion, dynamic help and opening of source files, etc.

2. A major mode for `.sage` files along with functionality for sending chunks of code to a running Sage shell.

`sage-shell-mode` allows extensions for `auto-complete`, `helm`, `anything`, and embedding in `org-mode`. It was written from scratch by Sho Takemori.

`sage-shell-mode` is most easily installed using the Emacs package manager MELPA. Alternatively, go to [[https://github.com/stakemori/sage-shell-mode|the GitHub page]].

See: SageModeComparison, [[https://github.com/stakemori/sage-shell-mode]]

== emacs-jupyter ==

- See 2020 blog post: [[https://martinralbrecht.wordpress.com/2020/08/23/conda-jupyter-and-emacs/|Martin Albrecht: Conda, Jupyter and Emacs]]

== EIN: IPython notebook client in Emacs ==

https://github.com/tkf/emacs-ipython-notebook

This is currently non functional due to an incompatibility with the
ipython shipped with Sage. Yet this sounds promising. See:

- https://github.com/tkf/emacs-ipython-notebook/issues/131
- https://github.com/sagemath/sage/issues/16053

== Sage-mode ==

Note: `sage-mode` works only for Sage 7.3 and earlier.

This emacs mode allows for running a Sage interpreter inside emacs,
and interacting with it sending in chunks of code or doctests,
directly opening the appropriate source files from the help, the
debugger or the tracebacks. It also provides goodies for running
tests, typesetting output, etc.

See: SageModeComparison, [[sage-mode]], [[http://bitbucket.org/gvol/sage-mode]]

== Miscellaneous ==

 * Sage already provides an editor configuration for Emacs, using the file
``.dir-locals.el``, to use spaces instead of tabs. To avoid introducing [[https://doc.sagemath.org/html/en/developer/coding_basics.html#general-coding-style-regarding-whitespace|trailing whitespace]], see https://www.emacswiki.org/emacs/DeletingWhitespace
for various solutions.


 * which-function-mode: this minor mode displays in the status bar the
   name of the class or function being edited. This is a life saver for
   code with nested classes, and in particular category code.

   Setup: M-x customize-variable which-function-mode

== See also ==

- 2010 [[http://www.saltycrane.com/blog/2010/05/my-emacs-python-environment/|blog post]] on customizing emacs for Python

https://www.gnu.org/software/emacs/images/emacs.png

Sage and Emacs

The purpose of this page is to collect tips and tricks for Sage users and developers using the text editor Emacs as an IDE.

sage-shell-mode

sage-shell-mode is the recommended mode for Sage in Emacs. This mode provides two features:

1. Run a Sage shell inside Emacs, fully equipped with command history, completion, dynamic help and opening of source files, etc.

2. A major mode for .sage files along with functionality for sending chunks of code to a running Sage shell.

sage-shell-mode allows extensions for auto-complete, helm, anything, and embedding in org-mode. It was written from scratch by Sho Takemori.

sage-shell-mode is most easily installed using the Emacs package manager MELPA. Alternatively, go to the GitHub page.

See: SageModeComparison, https://github.com/stakemori/sage-shell-mode

emacs-jupyter

- See 2020 blog post: Martin Albrecht: Conda, Jupyter and Emacs

EIN: IPython notebook client in Emacs

https://github.com/tkf/emacs-ipython-notebook

This is currently non functional due to an incompatibility with the ipython shipped with Sage. Yet this sounds promising. See:

- https://github.com/tkf/emacs-ipython-notebook/issues/131 - https://github.com/sagemath/sage/issues/16053

Sage-mode

Note: sage-mode works only for Sage 7.3 and earlier.

This emacs mode allows for running a Sage interpreter inside emacs, and interacting with it sending in chunks of code or doctests, directly opening the appropriate source files from the help, the debugger or the tracebacks. It also provides goodies for running tests, typesetting output, etc.

See: SageModeComparison, sage-mode, http://bitbucket.org/gvol/sage-mode

Miscellaneous

  • Sage already provides an editor configuration for Emacs, using the file

.dir-locals.el, to use spaces instead of tabs. To avoid introducing trailing whitespace, see https://www.emacswiki.org/emacs/DeletingWhitespace for various solutions.

  • which-function-mode: this minor mode displays in the status bar the
    • name of the class or function being edited. This is a life saver for code with nested classes, and in particular category code. Setup: M-x customize-variable which-function-mode

See also

- 2010 blog post on customizing emacs for Python

Emacs (last edited 2023-02-23 20:10:56 by mkoeppe)