The package octave provides commands for running an inferior Octave process in a special Emacs buffer. Use
to directly start an inferior Octave process. If Emacs does not know about this command, add the line
(autoload 'run-octave "octave-inf" nil t)
to your .emacs file.
This will start Octave in a special buffer the name of which is
specified by the variable
inferior-octave-buffer and defaults to
"*Inferior Octave*". From within this buffer, you can
interact with the inferior Octave process ‘as usual’, i.e., by entering
Octave commands at the prompt. The buffer is in Inferior Octave mode,
which is derived from the standard Comint mode, a major mode for
interacting with an inferior interpreter. See the documentation for
comint-mode for more details, and use C-h b to find out
about available special keybindings.
You can also communicate with an inferior Octave process from within files with Octave code (i.e., buffers in Octave mode), using the following commands.
Send the current line to the inferior Octave process
With positive prefix argument N, send that many lines.
octave-send-line-auto-forward is non-
nil, go to the
next unsent code line.
Send the current block to the inferior Octave process
Send the current function to the inferior Octave process
Send the region to the inferior Octave process
Make sure that ‘inferior-octave-buffer’ is displayed
Delete all windows that display the inferior Octave buffer
Kill the inferior Octave process and its buffer
The effect of the commands which send code to the Octave process can be customized by the following variables.
nil means echo input sent to the inferior Octave process.
nil means display the buffer running the Octave process after
sending a command (but without selecting it).
If you send code and there is no inferior Octave process yet, it will be started automatically.
The startup of the inferior Octave process is highly customizable.
inferior-octave-startup-args can be used for
specifying command lines arguments to be passed to Octave on startup
as a list of strings. For example, to suppress the startup message and
use ‘traditional’ mode, set this to
You can also specify a startup file of Octave commands to be loaded on
startup; note that these commands will not produce any visible output
in the process buffer. Which file to use is controlled by the variable
inferior-octave-startup-file. If this is
nil, the file
~/.emacs-octave is used if it exists.
inferior-octave-mode-hook is run after starting the
process and putting its buffer into Inferior Octave mode. Hence, if you
like the up and down arrow keys to behave in the interaction buffer as
in the shell, and you want this buffer to use nice colors, add
(add-hook 'inferior-octave-mode-hook (lambda () (turn-on-font-lock) (define-key inferior-octave-mode-map [up] 'comint-previous-input) (define-key inferior-octave-mode-map [down] 'comint-next-input)))
to your .emacs file. You could also swap the roles of C-a
C-c C-a (
Note that if you set your Octave prompts to something different from the defaults, make sure that
inferior-octave-promptmatches them. Otherwise, nothing will work, because Emacs will not know when Octave is waiting for input, or done sending output.