1 \input texinfo @c -*-texinfo-*-
3 @setfilename ../../info/octave-mode
5 @documentencoding UTF-8
9 Copyright @copyright{} 1996--2014 Free Software Foundation, Inc.
12 Permission is granted to copy, distribute and/or modify this document
13 under the terms of the GNU Free Documentation License, Version 1.3 or
14 any later version published by the Free Software Foundation; with no
15 Invariant Sections, with the Front-Cover texts being ``A GNU Manual,''
16 and with the Back-Cover Texts as in (a) below. A copy of the license
17 is included in the section entitled ``GNU Free Documentation License.''
19 (a) The FSF's Back-Cover Text is: ``You have the freedom to copy and
20 modify this GNU manual.''
24 @dircategory Emacs editing modes
26 * Octave mode: (octave-mode). Emacs mode for editing GNU Octave files.
33 @subtitle An Emacs mode for programming in GNU Octave
36 @vskip 0pt plus 1filll
52 * Running Octave from Within Emacs::
53 * GNU Free Documentation License::
56 * Lisp Function Index::
63 The development of Octave code can greatly be facilitated using Emacs
64 with Octave mode, a major mode for editing Octave files which can
65 e.g.@: automatically indent the code, do some of the typing (with
66 Abbrev mode) and show keywords, comments, strings, etc.@: in different
67 faces (with Font-lock mode on devices that support it).
69 It is also possible to run Octave from within Emacs, either by
70 directly entering commands at the prompt in a buffer in Inferior
71 Octave mode, or by interacting with Octave from within a file with
72 Octave code. This is useful in particular for debugging Octave code.
74 @node Using Octave Mode
75 @chapter Using Octave Mode
76 @cindex Using Octave Mode
78 In Octave mode, the following special Emacs commands can be used in
79 addition to the standard Emacs commands.
84 @findex octave-indent-new-comment-line
85 @vindex octave-continuation-string
86 Break Octave line at point, continuing comment if within one. Insert
87 @code{octave-continuation-string} before breaking the line unless
88 inside a list. Signal an error if within a single-quoted string.
92 @findex octave-update-function-file-comment
93 Query replace function names in function file comment.
97 @findex octave-previous-code-line
98 Move one line of Octave code backward, skipping empty and comment
99 lines (@code{octave-previous-code-line}). With numeric prefix
100 argument @var{n}, move that many code lines backward (forward if
101 @var{n} is negative).
105 @findex octave-next-code-line
106 Move one line of Octave code forward, skipping empty and comment lines
107 (@code{octave-next-code-line}). With numeric prefix argument @var{n},
108 move that many code lines forward (backward if @var{n} is negative).
112 @findex octave-beginning-of-line
113 Move to the beginning of the physical line
114 (@code{octave-beginning-of-line}). If point is in an empty or comment
115 line, simply go to its beginning; otherwise, move backwards to the
116 beginning of the first code line which is not inside a continuation
117 statement, i.e., which does not follow a code line ending in
118 @samp{...} or @samp{\}, or is inside an open parenthesis list.
122 @findex octave-end-of-line
123 Move to the end of the physical line (@code{octave-end-of-line}). If
124 point is in a code line, move forward to the end of the first Octave
125 code line which does not end in @samp{...} or @samp{\} or is inside an
126 open parenthesis list. Otherwise, simply go to the end of the current
131 @findex octave-mark-block
132 Put point at the beginning of this block, mark at the end
133 (@code{octave-mark-block}). The block marked is the one that contains
134 point or follows point.
138 Close the current block on a separate line (@code{smie-close-block}).
139 An error is signaled if no block to close is found.
143 @findex octave-insert-defun
144 Insert a function skeleton, prompting for the function's name, arguments
145 and return values which have to be entered without parentheses
146 (@code{octave-insert-defun}).
148 in one of your Emacs startup files.
151 @c FIXME: `electric-indent-mode' is enabled by default in GNU Emacs 24.4.
152 A common problem is that the @key{RET} key does @emph{not} indent the
153 line to where the new text should go after inserting the newline. This
154 is because the standard Emacs convention is that @key{RET} (aka
155 @kbd{C-m}) just adds a newline, whereas @key{LFD} (aka @kbd{C-j}) adds a
156 newline and indents it. This is particularly inconvenient for users with
157 keyboards which do not have a special @key{LFD} key at all; in such
158 cases, it is typically more convenient to use @key{RET} as the @key{LFD}
159 key (rather than typing @kbd{C-j}).
161 You can make @key{RET} do this by adding
163 (define-key octave-mode-map "\C-m"
164 'octave-reindent-then-newline-and-indent)
167 to one of your Emacs startup files. Another, more generally applicable
170 (defun RET-behaves-as-LFD ()
171 (let ((x (key-binding "\C-j")))
172 (local-set-key "\C-m" x)))
173 (add-hook 'octave-mode-hook 'RET-behaves-as-LFD)
176 (this works for all modes by adding to the startup hooks, without
177 having to know the particular binding of @key{RET} in that mode!).
178 Similar considerations apply for using @key{M-RET} as @key{M-LFD}. As
179 @email{bwarsaw@@cnri.reston.va.us, Barry A. Warsaw} says in the
180 documentation for his @code{cc-mode}, ``This is a very common
181 question. @code{:-)} If you want this to be the default behavior,
182 don't lobby me, lobby RMS!''
184 The following variables can be used to customize Octave mode.
187 @item octave-blink-matching-block
188 Non-@code{nil} means show matching begin of block when inserting a space,
189 newline or @samp{;} after an else or end keyword. Default is @code{t}.
190 This is an extremely useful feature for automatically verifying that the
191 keywords match---if they don't, an error message is displayed.
193 @item octave-block-offset
194 Extra indentation applied to statements in block structures.
197 @item octave-continuation-offset
198 Extra indentation applied to Octave continuation lines.
201 @item octave-font-lock-texinfo-comment
202 Highlight texinfo comment blocks. The default value is @code{t}.
205 If Font Lock mode is enabled, Octave mode will display
209 strings in @code{font-lock-string-face}
212 comments in @code{font-lock-comment-face}
215 the Octave reserved words (such as all block keywords) and the text
216 functions (such as @samp{cd} or @samp{who}) which are also reserved
217 using @code{font-lock-keyword-face}
220 the built-in operators (@samp{&&}, @samp{==}, @dots{}) using
221 @code{font-lock-reference-face}
224 and the function names in function declarations in
225 @code{font-lock-function-name-face}.
228 Function comments blocks in @code{octave-function-comment-block}
231 @cindex Imenu Support
232 There is also rudimentary support for Imenu (@pxref{Imenu,,, emacs,
233 The GNU Emacs Manual}). Currently, function names can be indexed.
235 @cindex ElDoc Mode Support
236 @vindex octave-eldoc-message-style
237 ElDoc mode (@pxref{Lisp Doc,,, emacs, The GNU Emacs Manual}) is
238 supported. By customizing @code{octave-eldoc-message-style} it can be
239 changed from displaying one or multi line hints.
242 @c @cindex Emacs TAGS files
243 @c @cindex @file{octave-tags}
244 @c You can generate TAGS files for Emacs from Octave @file{.m} files using
245 @c the shell script @file{octave-tags} that is installed alongside your copy of
248 @vindex octave-mode-hook
249 Customization of Octave mode can be performed by modification of the
250 variable @code{octave-mode-hook}.
252 @node Running Octave from Within Emacs
253 @chapter Running Octave from Within Emacs
254 @cindex Inferior Octave Mode
256 Octave mode provides commands for running an inferior
257 Octave process in a special Emacs buffer. Use
262 to directly start an inferior Octave process.
264 @vindex inferior-octave-buffer
265 This will start Octave in a special buffer the name of which is
266 specified by the variable @code{inferior-octave-buffer} and defaults
267 to @file{*Inferior Octave*}. From within this buffer, you can
268 interact with the inferior Octave process `as usual', i.e., by
269 entering Octave commands at the prompt. The buffer is in Inferior
270 Octave mode, which is derived from the standard Comint mode, a major
271 mode for interacting with an inferior interpreter. See the
272 documentation for @code{comint-mode} for more details, and use
273 @kbd{C-h b} to find out about available special keybindings.
275 You can also communicate with an inferior Octave process from within
276 files with Octave code (i.e., buffers in Octave mode), using the
282 @findex octave-send-line
283 @vindex octave-send-line-auto-forward
284 Send the current line to the inferior Octave process
285 (@code{octave-send-line}). With positive prefix argument @var{n},
286 send that many lines. If @code{octave-send-line-auto-forward} is
287 non-@code{nil}, go to the next unsent code line.
291 @findex octave-send-block
292 Send the current block to the inferior Octave process
293 (@code{octave-send-block}).
297 @findex octave-send-defun
298 Send the current function to the inferior Octave process
299 (@code{octave-send-defun}).
303 @findex octave-send-region
304 Send the region to the inferior Octave process
305 (@code{octave-send-region}).
309 @findex octave-send-buffer
310 Send the entire buffer to the inferior Octave process
311 (@code{octave-send-buffer}). If the buffer is associated with a file
312 then sourcing the buffer by using @kbd{C-c C-l}
313 (@code{octave-source-file}) should be preferred.
317 @findex octave-show-process-buffer
318 Make sure that `inferior-octave-buffer' is displayed
319 (@code{octave-show-process-buffer}).
323 @findex octave-hide-process-buffer
324 Delete all windows that display the inferior Octave buffer
325 (@code{octave-hide-process-buffer}).
329 @findex octave-kill-process
330 Kill the inferior Octave process and its buffer
331 (@code{octave-kill-process}).
335 @findex octave-source-file
336 Parse and execute the current file in the inferior Octave buffer
337 (@code{octave-source-file}). This is done using Octave's
338 @code{source} function.
342 @findex octave-find-definition
343 @vindex octave-source-directories
344 Find the definition of a function or variable. Functions implemented
345 in C++ can be found if variable @code{octave-source-directories} is
346 set correctly (@code{octave-find-definition}).
351 @vindex octave-help-buffer
352 Display the documentation for function (@code{octave-help}). The
353 buffer name can be changed by customizing @code{octave-help-buffer}.
357 @findex octave-lookfor
358 Search for a given string in all the first sentence of function help
359 strings (@code{octave-lookfor}). With a @code{universal-argument} the
360 entire help string is searched.
364 The effect of the commands which send code to the Octave process can be
365 customized by the following variables.
368 @item octave-send-echo-input
369 Non-@code{nil} means echo input sent to the inferior Octave process.
372 @item octave-send-show-buffer
373 Non-@code{nil} means display the buffer running the Octave process after
374 sending a command (but without selecting it).
378 If you send code and there is no inferior Octave process yet, it will
379 be started automatically.
381 @vindex inferior-octave-startup-args
382 The startup of the inferior Octave process is highly customizable.
383 The variable @code{inferior-octave-startup-args} can be used for
384 specifying command lines arguments to be passed to Octave on startup
385 as a list of strings. For example, to suppress the startup message
386 and use `traditional' mode, set this to @code{("-q" "--traditional")}.
387 You can also specify a startup file of Octave commands to be loaded on
388 startup; note that these commands will not produce any visible output
389 in the process buffer. Which file to use is controlled by the
390 variable @code{inferior-octave-startup-file}. The default is
391 @file{~/.emacs-octave} or if this file is not found
392 @file{~/.emacs.d/init_octave.m}.
394 @vindex inferior-octave-prompt-read-only
395 By customizing @code{inferior-octave-prompt-read-only} the prompt can
396 be changed to be read only. The default value is the same as
397 @code{comint-prompt-read-only}.
399 @vindex inferior-octave-mode-hook
400 And finally, @code{inferior-octave-mode-hook} is run after starting
401 the process and putting its buffer into Inferior Octave mode. Hence,
402 if you like the up and down arrow keys to behave in the interaction
403 buffer as in the shell, and you want this buffer to use nice colors,
406 (add-hook 'inferior-octave-mode-hook
408 (define-key inferior-octave-mode-map [up]
409 'comint-previous-input)
410 (define-key inferior-octave-mode-map [down]
411 'comint-next-input)))
414 to your @file{.emacs} or @file{init.el} file. You could also swap the
415 roles of @kbd{C-a} (@code{beginning-of-line}) and @code{C-c C-a}
416 (@code{comint-bol}) using this hook.
418 @vindex inferior-octave-prompt
420 @strong{Note} that if you set your Octave prompts to something different
421 from the defaults, make sure that @code{inferior-octave-prompt} matches
422 them. Otherwise, @emph{nothing} will work, because Emacs will not know
423 when Octave is waiting for input, or done sending output.
426 @node GNU Free Documentation License
427 @chapter GNU Free Documentation License
428 @include doclicense.texi
431 @unnumbered Key Index
436 @unnumbered Variable Index
440 @node Lisp Function Index
441 @unnumbered Function Index
446 @unnumbered Concept Index
455 @c @node Using the Emacs Info Reader for Octave
456 @c @chapter Using the Emacs Info Reader for Octave
458 @c You may also use the Emacs Info reader with Octave's @code{doc} function.
460 @c If @file{gnuserv} is installed, add the lines
462 @c (autoload 'octave-help "octave-hlp" nil t)
463 @c (require 'gnuserv)
467 @c to your @file{.emacs} file.
469 @c You can use either `plain' Emacs Info or the function @code{octave-help}
470 @c as your Octave info reader (for @samp{help -i}). In the former case,
471 @c use @code{info_program ("info-emacs-info")}.
472 @c The latter is perhaps more attractive because it allows to look up keys
473 @c in the indices of @emph{several} info files related to Octave (provided
474 @c that the Emacs variable @code{octave-help-files} is set correctly). In
475 @c this case, use @code{info_program ("info-emacs-octave-help")}.
477 @c If you use Octave from within Emacs, it is best to add these settings to
478 @c your @file{~/.emacs-octave} startup file (or the file pointed to by the
479 @c Emacs variable @code{inferior-octave-startup-file}).