octave-mode.texi 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. \input texinfo @c -*-texinfo-*-
  2. @c %**start of header
  3. @setfilename ../../info/octave-mode.info
  4. @settitle Octave Mode
  5. @include docstyle.texi
  6. @c %**end of header
  7. @copying
  8. Copyright @copyright{} 1996--2017 Free Software Foundation, Inc.
  9. @quotation
  10. Permission is granted to copy, distribute and/or modify this document
  11. under the terms of the GNU Free Documentation License, Version 1.3 or
  12. any later version published by the Free Software Foundation; with no
  13. Invariant Sections, with the Front-Cover Texts being ``A GNU Manual,''
  14. and with the Back-Cover Texts as in (a) below. A copy of the license
  15. is included in the section entitled ``GNU Free Documentation License.''
  16. (a) The FSF's Back-Cover Text is: ``You have the freedom to copy and
  17. modify this GNU manual.''
  18. @end quotation
  19. @end copying
  20. @dircategory Emacs editing modes
  21. @direntry
  22. * Octave mode: (octave-mode). Emacs mode for editing GNU Octave files.
  23. @end direntry
  24. @finalout
  25. @titlepage
  26. @title Octave Mode
  27. @subtitle An Emacs mode for programming in GNU Octave
  28. @page
  29. @vskip 0pt plus 1filll
  30. @insertcopying
  31. @end titlepage
  32. @contents
  33. @ifnottex
  34. @node Top
  35. @top Octave Mode
  36. @insertcopying
  37. @end ifnottex
  38. @menu
  39. * Overview::
  40. * Using Octave Mode::
  41. * Running Octave from Within Emacs::
  42. * GNU Free Documentation License::
  43. * Key Index::
  44. * Variable Index::
  45. * Lisp Function Index::
  46. * Concept Index::
  47. @end menu
  48. @node Overview
  49. @chapter Overview
  50. The development of Octave code can greatly be facilitated using Emacs
  51. with Octave mode, a major mode for editing Octave files which can
  52. e.g.@: automatically indent the code, do some of the typing (with
  53. Abbrev mode) and show keywords, comments, strings, etc.@: in different
  54. faces (with Font-lock mode on devices that support it).
  55. It is also possible to run Octave from within Emacs, either by
  56. directly entering commands at the prompt in a buffer in Inferior
  57. Octave mode, or by interacting with Octave from within a file with
  58. Octave code. This is useful in particular for debugging Octave code.
  59. @node Using Octave Mode
  60. @chapter Using Octave Mode
  61. @cindex Using Octave Mode
  62. In Octave mode, the following special Emacs commands can be used in
  63. addition to the standard Emacs commands.
  64. @table @kbd
  65. @item C-M-j
  66. @kindex C-M-j
  67. @findex octave-indent-new-comment-line
  68. @vindex octave-continuation-string
  69. Break Octave line at point, continuing comment if within one. Insert
  70. @code{octave-continuation-string} before breaking the line unless
  71. inside a list. Signal an error if within a single-quoted string.
  72. @item C-c ;
  73. @kindex C-c ;
  74. @findex octave-update-function-file-comment
  75. Query replace function names in function file comment.
  76. @item C-c C-p
  77. @kindex C-c C-p
  78. @findex octave-previous-code-line
  79. Move one line of Octave code backward, skipping empty and comment
  80. lines (@code{octave-previous-code-line}). With numeric prefix
  81. argument @var{n}, move that many code lines backward (forward if
  82. @var{n} is negative).
  83. @item C-c C-n
  84. @kindex C-c C-n
  85. @findex octave-next-code-line
  86. Move one line of Octave code forward, skipping empty and comment lines
  87. (@code{octave-next-code-line}). With numeric prefix argument @var{n},
  88. move that many code lines forward (backward if @var{n} is negative).
  89. @item C-c C-a
  90. @kindex C-c C-a
  91. @findex octave-beginning-of-line
  92. Move to the beginning of the physical line
  93. (@code{octave-beginning-of-line}). If point is in an empty or comment
  94. line, simply go to its beginning; otherwise, move backwards to the
  95. beginning of the first code line which is not inside a continuation
  96. statement, i.e., which does not follow a code line ending in
  97. @samp{...} or @samp{\}, or is inside an open parenthesis list.
  98. @item C-c C-e
  99. @kindex C-c C-e
  100. @findex octave-end-of-line
  101. Move to the end of the physical line (@code{octave-end-of-line}). If
  102. point is in a code line, move forward to the end of the first Octave
  103. code line which does not end in @samp{...} or @samp{\} or is inside an
  104. open parenthesis list. Otherwise, simply go to the end of the current
  105. line.
  106. @item C-c M-C-h
  107. @kindex C-c M-C-h
  108. @findex octave-mark-block
  109. Put point at the beginning of this block, mark at the end
  110. (@code{octave-mark-block}). The block marked is the one that contains
  111. point or follows point.
  112. @item C-c ]
  113. @kindex C-c ]
  114. Close the current block on a separate line (@code{smie-close-block}).
  115. An error is signaled if no block to close is found.
  116. @item C-c C-f
  117. @kindex C-c C-f
  118. @findex octave-insert-defun
  119. Insert a function skeleton, prompting for the function's name, arguments
  120. and return values which have to be entered without parentheses
  121. (@code{octave-insert-defun}).
  122. @noindent
  123. in one of your Emacs startup files.
  124. @end table
  125. The following variables can be used to customize Octave mode.
  126. @vtable @code
  127. @item octave-blink-matching-block
  128. Non-@code{nil} means show matching begin of block when inserting a space,
  129. newline or @samp{;} after an else or end keyword. Default is @code{t}.
  130. This is an extremely useful feature for automatically verifying that the
  131. keywords match---if they don't, an error message is displayed.
  132. @item octave-block-offset
  133. Extra indentation applied to statements in block structures.
  134. Default is 2.
  135. @item octave-continuation-offset
  136. Extra indentation applied to Octave continuation lines.
  137. Default is 4.
  138. @item octave-font-lock-texinfo-comment
  139. Highlight texinfo comment blocks. The default value is @code{t}.
  140. @end vtable
  141. If Font Lock mode is enabled, Octave mode will display
  142. @itemize @bullet
  143. @item
  144. strings in @code{font-lock-string-face}
  145. @item
  146. comments in @code{font-lock-comment-face}
  147. @item
  148. the Octave reserved words (such as all block keywords) and the text
  149. functions (such as @samp{cd} or @samp{who}) which are also reserved
  150. using @code{font-lock-keyword-face}
  151. @item
  152. the built-in operators (@samp{&&}, @samp{==}, @dots{}) using
  153. @code{font-lock-reference-face}
  154. @item
  155. and the function names in function declarations in
  156. @code{font-lock-function-name-face}.
  157. @item
  158. Function comments blocks in @code{octave-function-comment-block}
  159. @end itemize
  160. @cindex Imenu Support
  161. There is also rudimentary support for Imenu (@pxref{Imenu,,, emacs,
  162. The GNU Emacs Manual}). Currently, function names can be indexed.
  163. @cindex ElDoc Mode Support
  164. @vindex octave-eldoc-message-style
  165. ElDoc mode (@pxref{Lisp Doc,,, emacs, The GNU Emacs Manual}) is
  166. supported. By customizing @code{octave-eldoc-message-style} it can be
  167. changed from displaying one or multi line hints.
  168. @c @cindex TAGS
  169. @c @cindex Emacs TAGS files
  170. @c @cindex @file{octave-tags}
  171. @c You can generate TAGS files for Emacs from Octave @file{.m} files using
  172. @c the shell script @file{octave-tags} that is installed alongside your copy of
  173. @c Octave.
  174. @c
  175. @vindex octave-mode-hook
  176. Customization of Octave mode can be performed by modification of the
  177. variable @code{octave-mode-hook}.
  178. @node Running Octave from Within Emacs
  179. @chapter Running Octave from Within Emacs
  180. @cindex Inferior Octave Mode
  181. Octave mode provides commands for running an inferior
  182. Octave process in a special Emacs buffer. Use
  183. @lisp
  184. M-x run-octave
  185. @end lisp
  186. @noindent
  187. to directly start an inferior Octave process.
  188. @vindex inferior-octave-buffer
  189. This will start Octave in a special buffer the name of which is
  190. specified by the variable @code{inferior-octave-buffer} and defaults
  191. to @file{*Inferior Octave*}. From within this buffer, you can
  192. interact with the inferior Octave process ``as usual'', i.e., by
  193. entering Octave commands at the prompt. The buffer is in Inferior
  194. Octave mode, which is derived from the standard Comint mode, a major
  195. mode for interacting with an inferior interpreter. See the
  196. documentation for @code{comint-mode} for more details, and use
  197. @kbd{C-h b} to find out about available special keybindings.
  198. You can also communicate with an inferior Octave process from within
  199. files with Octave code (i.e., buffers in Octave mode), using the
  200. following commands.
  201. @table @kbd
  202. @item C-c C-i l
  203. @kindex C-c C-i l
  204. @findex octave-send-line
  205. @vindex octave-send-line-auto-forward
  206. Send the current line to the inferior Octave process
  207. (@code{octave-send-line}). With positive prefix argument @var{n},
  208. send that many lines. If @code{octave-send-line-auto-forward} is
  209. non-@code{nil}, go to the next unsent code line.
  210. @item C-c C-i b
  211. @kindex C-c C-i b
  212. @findex octave-send-block
  213. Send the current block to the inferior Octave process
  214. (@code{octave-send-block}).
  215. @item C-c C-i f
  216. @kindex C-c C-i f
  217. @findex octave-send-defun
  218. Send the current function to the inferior Octave process
  219. (@code{octave-send-defun}).
  220. @item C-c C-i r
  221. @kindex C-c C-i r
  222. @findex octave-send-region
  223. Send the region to the inferior Octave process
  224. (@code{octave-send-region}).
  225. @item C-c C-i a
  226. @kindex C-c C-i a
  227. @findex octave-send-buffer
  228. Send the entire buffer to the inferior Octave process
  229. (@code{octave-send-buffer}). If the buffer is associated with a file
  230. then sourcing the buffer by using @kbd{C-c C-l}
  231. (@code{octave-source-file}) should be preferred.
  232. @item C-c C-i s
  233. @kindex C-c C-i s
  234. @findex octave-show-process-buffer
  235. Make sure that @code{inferior-octave-buffer} is displayed
  236. (@code{octave-show-process-buffer}).
  237. @item C-c C-i q
  238. @kindex C-c C-i q
  239. @findex octave-hide-process-buffer
  240. Delete all windows that display the inferior Octave buffer
  241. (@code{octave-hide-process-buffer}).
  242. @item C-c C-i k
  243. @kindex C-c C-i k
  244. @findex octave-kill-process
  245. Kill the inferior Octave process and its buffer
  246. (@code{octave-kill-process}).
  247. @item C-c C-l
  248. @kindex C-c C-l
  249. @findex octave-source-file
  250. Parse and execute the current file in the inferior Octave buffer
  251. (@code{octave-source-file}). This is done using Octave's
  252. @code{source} function.
  253. @item M-.
  254. @kindex M-.
  255. @findex octave-find-definition
  256. @vindex octave-source-directories
  257. Find the definition of a function or variable. Functions implemented
  258. in C++ can be found if variable @code{octave-source-directories} is
  259. set correctly (@code{octave-find-definition}).
  260. @item C-h d
  261. @kindex C-h d
  262. @findex octave-help
  263. @vindex octave-help-buffer
  264. Display the documentation for function (@code{octave-help}). The
  265. buffer name can be changed by customizing @code{octave-help-buffer}.
  266. @item C-h a
  267. @kindex C-h a
  268. @findex octave-lookfor
  269. Search for a given string in all the first sentence of function help
  270. strings (@code{octave-lookfor}). With a @code{universal-argument} the
  271. entire help string is searched.
  272. @end table
  273. The effect of the commands which send code to the Octave process can be
  274. customized by the following variables.
  275. @vtable @code
  276. @item octave-send-echo-input
  277. Non-@code{nil} means echo input sent to the inferior Octave process.
  278. Default is @code{t}.
  279. @item octave-send-show-buffer
  280. Non-@code{nil} means display the buffer running the Octave process after
  281. sending a command (but without selecting it).
  282. Default is @code{t}.
  283. @end vtable
  284. If you send code and there is no inferior Octave process yet, it will
  285. be started automatically.
  286. @vindex inferior-octave-startup-args
  287. The startup of the inferior Octave process is highly customizable.
  288. The variable @code{inferior-octave-startup-args} can be used for
  289. specifying command lines arguments to be passed to Octave on startup
  290. as a list of strings. For example, to suppress the startup message
  291. and use ``traditional'' mode, set this to @code{("-q" "--traditional")}.
  292. You can also specify a startup file of Octave commands to be loaded on
  293. startup; note that these commands will not produce any visible output
  294. in the process buffer. Which file to use is controlled by the
  295. variable @code{inferior-octave-startup-file}. The default is
  296. @file{~/.emacs-octave} or if this file is not found
  297. @file{~/.emacs.d/init_octave.m}.
  298. @vindex inferior-octave-prompt-read-only
  299. By customizing @code{inferior-octave-prompt-read-only} the prompt can
  300. be changed to be read only. The default value is the same as
  301. @code{comint-prompt-read-only}.
  302. @vindex inferior-octave-mode-hook
  303. And finally, @code{inferior-octave-mode-hook} is run after starting
  304. the process and putting its buffer into Inferior Octave mode. Hence,
  305. if you like the up and down arrow keys to behave in the interaction
  306. buffer as in the shell, and you want this buffer to use nice colors,
  307. add
  308. @lisp
  309. (add-hook 'inferior-octave-mode-hook
  310. (lambda ()
  311. (define-key inferior-octave-mode-map [up]
  312. 'comint-previous-input)
  313. (define-key inferior-octave-mode-map [down]
  314. 'comint-next-input)))
  315. @end lisp
  316. @noindent
  317. to your @file{.emacs} or @file{init.el} file. You could also swap the
  318. roles of @kbd{C-a} (@code{beginning-of-line}) and @code{C-c C-a}
  319. (@code{comint-bol}) using this hook.
  320. @vindex inferior-octave-prompt
  321. @quotation
  322. @strong{Note} that if you set your Octave prompts to something different
  323. from the defaults, make sure that @code{inferior-octave-prompt} matches
  324. them. Otherwise, @emph{nothing} will work, because Emacs will not know
  325. when Octave is waiting for input, or done sending output.
  326. @end quotation
  327. @node GNU Free Documentation License
  328. @chapter GNU Free Documentation License
  329. @include doclicense.texi
  330. @node Key Index
  331. @unnumbered Key Index
  332. @printindex ky
  333. @node Variable Index
  334. @unnumbered Variable Index
  335. @printindex vr
  336. @node Lisp Function Index
  337. @unnumbered Function Index
  338. @printindex fn
  339. @node Concept Index
  340. @unnumbered Concept Index
  341. @printindex cp
  342. @bye
  343. @c TODO Update
  344. @c @node Using the Emacs Info Reader for Octave
  345. @c @chapter Using the Emacs Info Reader for Octave
  346. @c You may also use the Emacs Info reader with Octave's @code{doc} function.
  347. @c If @file{gnuserv} is installed, add the lines
  348. @c @lisp
  349. @c (autoload 'octave-help "octave-hlp" nil t)
  350. @c (require 'gnuserv)
  351. @c (gnuserv-start)
  352. @c @end lisp
  353. @c @noindent
  354. @c to your @file{.emacs} file.
  355. @c You can use either 'plain' Emacs Info or the function @code{octave-help}
  356. @c as your Octave info reader (for @samp{help -i}). In the former case,
  357. @c use @code{info_program ("info-emacs-info")}.
  358. @c The latter is perhaps more attractive because it allows you to look up keys
  359. @c in the indices of @emph{several} info files related to Octave (provided
  360. @c that the Emacs variable @code{octave-help-files} is set correctly). In
  361. @c this case, use @code{info_program ("info-emacs-octave-help")}.
  362. @c If you use Octave from within Emacs, it is best to add these settings to
  363. @c your @file{~/.emacs-octave} startup file (or the file pointed to by the
  364. @c Emacs variable @code{inferior-octave-startup-file}).