Sophie

Sophie

distrib > Mageia > 4 > i586 > by-pkgid > b38d2da330d1936e5ab1307c039c4941 > files > 526

octave-doc-3.6.4-3.mga4.noarch.rpm

<html lang="en">
<head>
<title>Using Octave Mode - GNU Octave</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="GNU Octave">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Emacs-Octave-Support.html#Emacs-Octave-Support" title="Emacs Octave Support">
<link rel="prev" href="Installing-EOS.html#Installing-EOS" title="Installing EOS">
<link rel="next" href="Running-Octave-from-Within-Emacs.html#Running-Octave-from-Within-Emacs" title="Running Octave from Within Emacs">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
  pre.display { font-family:inherit }
  pre.format  { font-family:inherit }
  pre.smalldisplay { font-family:inherit; font-size:smaller }
  pre.smallformat  { font-family:inherit; font-size:smaller }
  pre.smallexample { font-size:smaller }
  pre.smalllisp    { font-size:smaller }
  span.sc    { font-variant:small-caps }
  span.roman { font-family:serif; font-weight:normal; } 
  span.sansserif { font-family:sans-serif; font-weight:normal; } 
--></style>
</head>
<body>
<div class="node">
<a name="Using-Octave-Mode"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="Running-Octave-from-Within-Emacs.html#Running-Octave-from-Within-Emacs">Running Octave from Within Emacs</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="Installing-EOS.html#Installing-EOS">Installing EOS</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Emacs-Octave-Support.html#Emacs-Octave-Support">Emacs Octave Support</a>
<hr>
</div>

<h3 class="appendixsec">H.2 Using Octave Mode</h3>

<p>If you are lucky, your sysadmins have already arranged everything so
that Emacs automatically goes into Octave mode whenever you visit an
Octave code file as characterized by its extension <samp><span class="file">.m</span></samp>.  If not,
proceed as follows.

     <ol type=1 start=1>
<li>To begin using Octave mode for all <samp><span class="file">.m</span></samp> files you visit, add the
following lines to a file loaded by Emacs at startup time, typically
your <samp><span class="file">~/.emacs</span></samp> file:

     <pre class="lisp">          (autoload 'octave-mode "octave-mod" nil t)
          (setq auto-mode-alist
                (cons '("\\.m$" . octave-mode) auto-mode-alist))
</pre>
     <li>Finally, to turn on the abbrevs, auto-fill and font-lock features
automatically, also add the following lines to one of the Emacs startup
files:
     <pre class="lisp">          (add-hook 'octave-mode-hook
                    (lambda ()
                      (abbrev-mode 1)
                      (auto-fill-mode 1)
                      (if (eq window-system 'x)
                          (font-lock-mode 1))))
</pre>
     <p>See the Emacs manual for more information about how to customize
Font-lock mode.
        </ol>

   <p>In Octave mode, the following special Emacs commands can be used in
addition to the standard Emacs commands.

     <dl>
<dt><kbd>C-h m</kbd><dd>Describe the features of Octave mode.

     <br><dt><kbd>LFD</kbd><dd>Reindent the current Octave line, insert a newline and indent the new
line (<code>octave-reindent-then-newline-and-indent</code>).  An abbrev before
point is expanded if <code>abbrev-mode</code> is non-<code>nil</code>.

     <br><dt><kbd>TAB</kbd><dd>Indents current Octave line based on its contents and on previous
lines (<code>indent-according-to-mode</code>).

     <br><dt><kbd>;</kbd><dd>Insert an &ldquo;electric&rdquo; semicolon (<code>octave-electric-semi</code>).  If
<code>octave-auto-indent</code> is non-<code>nil</code>, reindent the current line. 
If <code>octave-auto-newline</code> is non-<code>nil</code>, automagically insert a
newline and indent the new line.

     <br><dt><kbd>`</kbd><dd>Start entering an abbreviation (<code>octave-abbrev-start</code>).  If Abbrev
mode is turned on, typing <kbd>`C-h</kbd> or <kbd>`?</kbd> lists all abbrevs. 
Any other key combination is executed normally.  Note that all Octave
abbrevs start with a grave accent.

     <br><dt><kbd>M-LFD</kbd><dd>Break line at point and insert continuation marker and alignment
(<code>octave-split-line</code>).

     <br><dt><kbd>M-TAB</kbd><dd>Perform completion on Octave symbol preceding point, comparing that
symbol against Octave's reserved words and built-in variables
(<code>octave-complete-symbol</code>).

     <br><dt><kbd>M-C-a</kbd><dd>Move backward to the beginning of a function
(<code>octave-beginning-of-defun</code>). 
With prefix argument <var>N</var>, do it that many times if <var>N</var> is
positive; otherwise, move forward to the <var>N</var>-th following beginning
of a function.

     <br><dt><kbd>M-C-e</kbd><dd>Move forward to the end of a function (<code>octave-end-of-defun</code>). 
With prefix argument <var>N</var>, do it that many times if <var>N</var> is
positive; otherwise, move back to the <var>N</var>-th preceding end of a
function.

     <br><dt><kbd>M-C-h</kbd><dd>Puts point at beginning and mark at the end of the current Octave
function, i.e., the one containing point or following point
(<code>octave-mark-defun</code>).

     <br><dt><kbd>M-C-q</kbd><dd>Properly indents the Octave function which contains point
(<code>octave-indent-defun</code>).

     <br><dt><kbd>M-;</kbd><dd>If there is no comment already on this line, create a code-level comment
(started by two comment characters) if the line is empty, or an in-line
comment (started by one comment character) otherwise
(<code>octave-indent-for-comment</code>). 
Point is left after the start of the comment which is properly aligned.

     <br><dt><kbd>C-c ;</kbd><dd>Puts the comment character &lsquo;<samp><span class="samp">#</span></samp>&rsquo; (more precisely, the string value of
<code>octave-comment-start</code>) at the beginning of every line in the
region (<code>octave-comment-region</code>).  With just <kbd>C-u</kbd> prefix
argument, uncomment each line in the region.  A numeric prefix argument
<var>N</var> means use <var>N</var> comment characters.

     <br><dt><kbd>C-c :</kbd><dd>Uncomments every line in the region (<code>octave-uncomment-region</code>).

     <br><dt><kbd>C-c C-p</kbd><dd>Move one line of Octave code backward, skipping empty and comment lines
(<code>octave-previous-code-line</code>).  With numeric prefix argument
<var>N</var>, move that many code lines backward (forward if <var>N</var> is
negative).

     <br><dt><kbd>C-c C-n</kbd><dd>Move one line of Octave code forward, skipping empty and comment lines
(<code>octave-next-code-line</code>).  With numeric prefix argument <var>N</var>,
move that many code lines forward (backward if <var>N</var> is negative).

     <br><dt><kbd>C-c C-a</kbd><dd>Move to the `real' beginning of the current line
(<code>octave-beginning-of-line</code>).  If point is in an empty or comment
line, simply go to its beginning; otherwise, move backwards to the
beginning of the first code line which is not inside a continuation
statement, i.e., which does not follow a code line ending in &lsquo;<samp><span class="samp">...</span></samp>&rsquo;
or &lsquo;<samp><span class="samp">\</span></samp>&rsquo;, or is inside an open parenthesis list.

     <br><dt><kbd>C-c C-e</kbd><dd>Move to the `real' end of the current line (<code>octave-end-of-line</code>). 
If point is in a code line, move forward to the end of the first Octave
code line which does not end in &lsquo;<samp><span class="samp">...</span></samp>&rsquo; or &lsquo;<samp><span class="samp">\</span></samp>&rsquo; or is inside an
open parenthesis list.  Otherwise, simply go to the end of the current
line.

     <br><dt><kbd>C-c M-C-n</kbd><dd>Move forward across one balanced begin-end block of Octave code
(<code>octave-forward-block</code>).  With numeric prefix argument <var>N</var>,
move forward across <var>n</var> such blocks (backward if <var>N</var> is
negative).

     <br><dt><kbd>C-c M-C-p</kbd><dd>Move back across one balanced begin-end block of Octave code
(<code>octave-backward-block</code>).  With numeric prefix argument <var>N</var>,
move backward across <var>N</var> such blocks (forward if <var>N</var> is
negative).

     <br><dt><kbd>C-c M-C-d</kbd><dd>Move forward down one begin-end block level of Octave code
(<code>octave-down-block</code>).  With numeric prefix argument, do it that
many times; a negative argument means move backward, but still go down
one level.

     <br><dt><kbd>C-c M-C-u</kbd><dd>Move backward out of one begin-end block level of Octave code
(<code>octave-backward-up-block</code>).  With numeric prefix argument, do it
that many times; a negative argument means move forward, but still to a
less deep spot.

     <br><dt><kbd>C-c M-C-h</kbd><dd>Put point at the beginning of this block, mark at the end
(<code>octave-mark-block</code>). 
The block marked is the one that contains point or follows point.

     <br><dt><kbd>C-c ]</kbd><dd>Close the current block on a separate line (<code>octave-close-block</code>). 
An error is signaled if no block to close is found.

     <br><dt><kbd>C-c f</kbd><dd>Insert a function skeleton, prompting for the function's name, arguments
and return values which have to be entered without parentheses
(<code>octave-insert-defun</code>).

     <br><dt><kbd>C-c C-h</kbd><dd>Search the function, operator and variable indices of all info files
with documentation for Octave for entries (<code>octave-help</code>).  If used
interactively, the entry is prompted for with completion.  If multiple
matches are found, one can cycle through them using the standard
&lsquo;<samp><span class="samp">,</span></samp>&rsquo; (<code>Info-index-next</code>) command of the Info reader.

     <p>The variable <code>octave-help-files</code> is a list of files to search
through and defaults to <code>'("octave")</code>.  If there is also an Octave
Local Guide with corresponding info file, say, <samp><span class="file">octave-LG</span></samp>, you can
have <code>octave-help</code> search both files by
     <pre class="lisp">          (setq octave-help-files '("octave" "octave-LG"))
</pre>
     <p class="noindent">in one of your Emacs startup files.

   </dl>

   <p>A common problem is that the &lt;RET&gt; key does <em>not</em> indent the
line to where the new text should go after inserting the newline.  This
is because the standard Emacs convention is that &lt;RET&gt; (aka
<kbd>C-m</kbd>) just adds a newline, whereas &lt;LFD&gt; (aka <kbd>C-j</kbd>) adds a
newline and indents it.  This is particularly inconvenient for users with
keyboards which do not have a special &lt;LFD&gt; key at all; in such
cases, it is typically more convenient to use &lt;RET&gt; as the &lt;LFD&gt;
key (rather than typing <kbd>C-j</kbd>).

   <p>You can make &lt;RET&gt; do this by adding
<pre class="lisp">     (define-key octave-mode-map "\C-m"
       'octave-reindent-then-newline-and-indent)
</pre>
   <p class="noindent">to one of your Emacs startup files.  Another, more generally applicable
solution is
<pre class="lisp">     (defun RET-behaves-as-LFD ()
       (let ((x (key-binding "\C-j")))
         (local-set-key "\C-m" x)))
     (add-hook 'octave-mode-hook 'RET-behaves-as-LFD)
</pre>
   <p class="noindent">(this works for all modes by adding to the startup hooks, without having
to know the particular binding of &lt;RET&gt; in that mode!).  Similar
considerations apply for using &lt;M-RET&gt; as &lt;M-LFD&gt;.  As Barry
A. Warsaw <a href="mailto:bwarsaw@cnri.reston.va.us">bwarsaw@cnri.reston.va.us</a> says in the documentation for his
<code>cc-mode</code>, &ldquo;This is a very common question.  <code>:-)</code> If you want
this to be the default behavior, don't lobby me, lobby RMS!&rdquo;

   <p>The following variables can be used to customize Octave mode.

     <dl>
<dt><code>octave-auto-indent</code><dd>Non-<code>nil</code> means auto-indent the current line after a semicolon or
space.  Default is <code>nil</code>.

     <br><dt><code>octave-auto-newline</code><dd>Non-<code>nil</code> means auto-insert a newline and indent after semicolons
are typed.  The default value is <code>nil</code>.

     <br><dt><code>octave-blink-matching-block</code><dd>Non-<code>nil</code> means show matching begin of block when inserting a space,
newline or &lsquo;<samp><span class="samp">;</span></samp>&rsquo; after an else or end keyword.  Default is <code>t</code>. 
This is an extremely useful feature for automatically verifying that the
keywords match&mdash;if they don't, an error message is displayed.

     <br><dt><code>octave-block-offset</code><dd>Extra indentation applied to statements in block structures. 
Default is 2.

     <br><dt><code>octave-continuation-offset</code><dd>Extra indentation applied to Octave continuation lines. 
Default is 4.

     <br><dt><code>octave-continuation-string</code><dd>String used for Octave continuation lines. 
Normally &lsquo;<samp><span class="samp">\</span></samp>&rsquo;.

     <br><dt><code>octave-mode-startup-message</code><dd>If <code>t</code> (default), a startup message is displayed when Octave mode
is called.

   </dl>

   <p>If Font Lock mode is enabled, Octave mode will display
     <ul>
<li>strings in <code>font-lock-string-face</code>

     <li>comments in <code>font-lock-comment-face</code>

     <li>the Octave reserved words (such as all block keywords) and the text
functions (such as &lsquo;<samp><span class="samp">cd</span></samp>&rsquo; or &lsquo;<samp><span class="samp">who</span></samp>&rsquo;) which are also reserved
using <code>font-lock-keyword-face</code>

     <li>the built-in operators (&lsquo;<samp><span class="samp">&amp;&amp;</span></samp>&rsquo;, &lsquo;<samp><span class="samp">==</span></samp>&rsquo;, <small class="dots">...</small>) using
<code>font-lock-reference-face</code>

     <li>and the function names in function declarations in
<code>font-lock-function-name-face</code>. 
</ul>

   <p>There is also rudimentary support for Imenu (currently, function names
can be indexed).

   <p><a name="index-TAGS-3456"></a><a name="index-Emacs-TAGS-files-3457"></a><a name="index-g_t_0040code_007boctave_002dtags_007d-3458"></a>You can generate TAGS files for Emacs from Octave <samp><span class="file">.m</span></samp> files using
the shell script <code>octave-tags</code> that is installed alongside your copy of
Octave.

   <p>Customization of Octave mode can be performed by modification of the
variable <code>octave-mode-hook</code>.  If the value of this variable is
non-<code>nil</code>, turning on Octave mode calls its value.

   <p>If you discover a problem with Octave mode, you can conveniently send a
bug report using <kbd>C-c C-b</kbd> (<code>octave-submit-bug-report</code>).  This
automatically sets up a mail buffer with version information already
added.  You just need to add a description of the problem, including a
reproducible test case and send the message.

   </body></html>