1 ;;; octave-mod.el --- editing Octave source files under Emacs
3 ;; Copyright (C) 1997, 2001, 2002, 2003, 2004, 2005, 2006, 2007
4 ;; Free Software Foundation, Inc.
6 ;; Author: Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
7 ;; Author: John Eaton <jwe@bevo.che.wisc.edu>
8 ;; Maintainer: Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 3, or (at your option)
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 ;; Boston, MA 02110-1301, USA.
30 ;; This package provides Emacs support for Octave.
31 ;; It defines Octave mode, a major mode for editing
34 ;; The file octave-hlp.el provides `octave-help', a facility for looking up
35 ;; documentation on a symbol in the Octave info files.
37 ;; The file octave-inf.el contains code for interacting with an inferior
38 ;; Octave process using comint.
40 ;; See the documentation of `octave-mode', `octave-help' and
41 ;; `run-octave' for further information on usage and customization.
47 "Major mode for editing Octave source files."
48 :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
51 (defvar inferior-octave-output-list nil)
52 (defvar inferior-octave-output-string nil)
53 (defvar inferior-octave-receive-in-progress nil)
55 (defconst octave-maintainer-address
56 "Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>, bug-gnu-emacs@gnu.org"
57 "Current maintainer of the Emacs Octave package.")
59 (defvar octave-abbrev-table nil
60 "Abbrev table for Octave's reserved words.
61 Used in `octave-mode' and inferior-octave-mode buffers.
62 All Octave abbrevs start with a grave accent (`).")
63 (unless octave-abbrev-table
64 (define-abbrev-table 'octave-abbrev-table ()))
66 (let ((abbrevs-changed abbrevs-changed))
67 (define-abbrev octave-abbrev-table "`a" "all_va_args" nil 0 t)
68 (define-abbrev octave-abbrev-table "`b" "break" nil 0 t)
69 (define-abbrev octave-abbrev-table "`cs" "case" nil 0 t)
70 (define-abbrev octave-abbrev-table "`ca" "catch" nil 0 t)
71 (define-abbrev octave-abbrev-table "`c" "continue" nil 0 t)
72 (define-abbrev octave-abbrev-table "`el" "else" nil 0 t)
73 (define-abbrev octave-abbrev-table "`eli" "elseif" nil 0 t)
74 (define-abbrev octave-abbrev-table "`et" "end_try_catch" nil 0 t)
75 (define-abbrev octave-abbrev-table "`eu" "end_unwind_protect" nil 0 t)
76 (define-abbrev octave-abbrev-table "`ef" "endfor" nil 0 t)
77 (define-abbrev octave-abbrev-table "`efu" "endfunction" nil 0 t)
78 (define-abbrev octave-abbrev-table "`ei" "endif" nil 0 t)
79 (define-abbrev octave-abbrev-table "`es" "endswitch" nil 0 t)
80 (define-abbrev octave-abbrev-table "`ew" "endwhile" nil 0 t)
81 (define-abbrev octave-abbrev-table "`f" "for" nil 0 t)
82 (define-abbrev octave-abbrev-table "`fu" "function" nil 0 t)
83 (define-abbrev octave-abbrev-table "`gl" "global" nil 0 t)
84 (define-abbrev octave-abbrev-table "`gp" "gplot" nil 0 t)
85 (define-abbrev octave-abbrev-table "`gs" "gsplot" nil 0 t)
86 (define-abbrev octave-abbrev-table "`if" "if ()" nil 0 t)
87 (define-abbrev octave-abbrev-table "`o" "otherwise" nil 0 t)
88 (define-abbrev octave-abbrev-table "`rp" "replot" nil 0 t)
89 (define-abbrev octave-abbrev-table "`r" "return" nil 0 t)
90 (define-abbrev octave-abbrev-table "`s" "switch" nil 0 t)
91 (define-abbrev octave-abbrev-table "`t" "try" nil 0 t)
92 (define-abbrev octave-abbrev-table "`u" "until ()" nil 0 t)
93 (define-abbrev octave-abbrev-table "`up" "unwind_protect" nil 0 t)
94 (define-abbrev octave-abbrev-table "`upc" "unwind_protect_cleanup" nil 0 t)
95 (define-abbrev octave-abbrev-table "`w" "while ()" nil 0 t))
97 (defvar octave-comment-char ?#
98 "Character to start an Octave comment.")
99 (defvar octave-comment-start
100 (string octave-comment-char ?\ )
101 "String to insert to start a new Octave in-line comment.")
102 (defvar octave-comment-start-skip "\\s<+\\s-*"
103 "Regexp to match the start of an Octave comment up to its body.")
105 (defvar octave-begin-keywords
106 '("do" "for" "function" "if" "switch" "try" "unwind_protect" "while"))
107 (defvar octave-else-keywords
108 '("case" "catch" "else" "elseif" "otherwise" "unwind_protect_cleanup"))
109 ;; FIXME: only use specific "end" tokens here to avoid confusion when "end"
110 ;; is used in indexing (the real fix is much more complex).
111 (defvar octave-end-keywords
112 '("endfor" "endfunction" "endif" "endswitch" "end_try_catch"
113 "end_unwind_protect" "endwhile" "until"))
115 (defvar octave-reserved-words
116 (append octave-begin-keywords
119 '("break" "continue" "end" "global" "persistent" "return"))
120 "Reserved words in Octave.")
122 (defvar octave-text-functions
123 '("casesen" "cd" "chdir" "clear" "diary" "dir" "document" "echo"
124 "edit_history" "format" "help" "history" "hold"
125 "load" "ls" "more" "run_history" "save" "type"
126 "which" "who" "whos")
127 "Text functions in Octave.")
129 (defvar octave-variables
130 '("DEFAULT_EXEC_PATH" "DEFAULT_LOADPATH"
131 "EDITOR" "EXEC_PATH" "F_DUPFD" "F_GETFD" "F_GETFL" "F_SETFD"
132 "F_SETFL" "I" "IMAGE_PATH" "Inf" "J"
133 "NaN" "OCTAVE_VERSION" "O_APPEND" "O_CREAT" "O_EXCL"
134 "O_NONBLOCK" "O_RDONLY" "O_RDWR" "O_TRUNC" "O_WRONLY" "PAGER" "PS1"
135 "PS2" "PS4" "PWD" "SEEK_CUR" "SEEK_END" "SEEK_SET" "__F_DUPFD__"
136 "__F_GETFD__" "__F_GETFL__" "__F_SETFD__" "__F_SETFL__" "__I__"
137 "__Inf__" "__J__" "__NaN__" "__OCTAVE_VERSION__" "__O_APPEND__"
138 "__O_CREAT__" "__O_EXCL__" "__O_NONBLOCK__" "__O_RDONLY__"
139 "__O_RDWR__" "__O_TRUNC__" "__O_WRONLY__" "__PWD__" "__SEEK_CUR__"
140 "__SEEK_END__" "__SEEK_SET__" "__argv__" "__e__" "__eps__"
141 "__i__" "__inf__" "__j__" "__nan__" "__pi__"
142 "__program_invocation_name__" "__program_name__" "__realmax__"
143 "__realmin__" "__stderr__" "__stdin__" "__stdout__" "ans" "argv"
144 "beep_on_error" "completion_append_char"
145 "crash_dumps_octave_core" "default_save_format"
146 "e" "echo_executing_commands" "eps"
147 "error_text" "gnuplot_binary" "history_file"
148 "history_size" "ignore_function_time_stamp"
149 "inf" "nan" "nargin" "output_max_field_width" "output_precision"
150 "page_output_immediately" "page_screen_output" "pi"
151 "print_answer_id_name" "print_empty_dimensions"
152 "program_invocation_name" "program_name"
153 "realmax" "realmin" "return_last_computed_value" "save_precision"
154 "saving_history" "sighup_dumps_octave_core" "sigterm_dumps_octave_core"
155 "silent_functions" "split_long_rows" "stderr" "stdin" "stdout"
156 "string_fill_char" "struct_levels_to_print"
157 "suppress_verbose_help_message")
158 "Builtin variables in Octave.")
160 (defvar octave-function-header-regexp
161 (concat "^\\s-*\\<\\(function\\)\\>"
162 "\\([^=;\n]*=[ \t]*\\|[ \t]*\\)\\(\\w+\\)\\>")
163 "Regexp to match an Octave function header.
164 The string `function' and its name are given by the first and third
165 parenthetical grouping.")
167 (defvar octave-font-lock-keywords
169 ;; Fontify all builtin keywords.
170 (cons (concat "\\<\\("
171 (mapconcat 'identity octave-reserved-words "\\|")
172 (mapconcat 'identity octave-text-functions "\\|")
174 'font-lock-keyword-face)
175 ;; Fontify all builtin operators.
176 (cons "\\(&\\||\\|<=\\|>=\\|==\\|<\\|>\\|!=\\|!\\)"
177 (if (boundp 'font-lock-builtin-face)
178 'font-lock-builtin-face
179 'font-lock-preprocessor-face))
180 ;; Fontify all builtin variables.
181 (cons (concat "\\<\\("
182 (mapconcat 'identity octave-variables "\\|")
184 'font-lock-variable-name-face)
185 ;; Fontify all function declarations.
186 (list octave-function-header-regexp
187 '(1 font-lock-keyword-face)
188 '(3 font-lock-function-name-face nil t)))
189 "Additional Octave expressions to highlight.")
191 (defcustom inferior-octave-buffer "*Inferior Octave*"
192 "Name of buffer for running an inferior Octave process."
194 :group 'octave-inferior)
196 (defvar inferior-octave-process nil)
198 (defvar octave-mode-map
199 (let ((map (make-sparse-keymap)))
200 (define-key map "`" 'octave-abbrev-start)
201 (define-key map ";" 'octave-electric-semi)
202 (define-key map " " 'octave-electric-space)
203 (define-key map "\n" 'octave-reindent-then-newline-and-indent)
204 (define-key map "\e;" 'octave-indent-for-comment)
205 (define-key map "\e\n" 'octave-indent-new-comment-line)
206 (define-key map "\e\t" 'octave-complete-symbol)
207 (define-key map "\M-\C-a" 'octave-beginning-of-defun)
208 (define-key map "\M-\C-e" 'octave-end-of-defun)
209 (define-key map "\M-\C-h" 'octave-mark-defun)
210 (define-key map "\M-\C-q" 'octave-indent-defun)
211 (define-key map "\C-c;" 'octave-comment-region)
212 (define-key map "\C-c:" 'octave-uncomment-region)
213 (define-key map "\C-c\C-b" 'octave-submit-bug-report)
214 (define-key map "\C-c\C-p" 'octave-previous-code-line)
215 (define-key map "\C-c\C-n" 'octave-next-code-line)
216 (define-key map "\C-c\C-a" 'octave-beginning-of-line)
217 (define-key map "\C-c\C-e" 'octave-end-of-line)
218 (define-key map "\C-c\M-\C-n" 'octave-forward-block)
219 (define-key map "\C-c\M-\C-p" 'octave-backward-block)
220 (define-key map "\C-c\M-\C-u" 'octave-backward-up-block)
221 (define-key map "\C-c\M-\C-d" 'octave-down-block)
222 (define-key map "\C-c\M-\C-h" 'octave-mark-block)
223 (define-key map "\C-c]" 'octave-close-block)
224 (define-key map "\C-c\C-f" 'octave-insert-defun)
225 (define-key map "\C-c\C-h" 'octave-help)
226 (define-key map "\C-c\C-il" 'octave-send-line)
227 (define-key map "\C-c\C-ib" 'octave-send-block)
228 (define-key map "\C-c\C-if" 'octave-send-defun)
229 (define-key map "\C-c\C-ir" 'octave-send-region)
230 (define-key map "\C-c\C-is" 'octave-show-process-buffer)
231 (define-key map "\C-c\C-ih" 'octave-hide-process-buffer)
232 (define-key map "\C-c\C-ik" 'octave-kill-process)
233 (define-key map "\C-c\C-i\C-l" 'octave-send-line)
234 (define-key map "\C-c\C-i\C-b" 'octave-send-block)
235 (define-key map "\C-c\C-i\C-f" 'octave-send-defun)
236 (define-key map "\C-c\C-i\C-r" 'octave-send-region)
237 (define-key map "\C-c\C-i\C-s" 'octave-show-process-buffer)
238 (define-key map "\C-c\C-i\C-h" 'octave-hide-process-buffer)
239 (define-key map "\C-c\C-i\C-k" 'octave-kill-process)
241 "Keymap used in Octave mode.")
244 (defvar octave-mode-menu
247 ["Previous Code Line" octave-previous-code-line t]
248 ["Next Code Line" octave-next-code-line t]
249 ["Begin of Continuation" octave-beginning-of-line t]
250 ["End of Continuation" octave-end-of-line t]
251 ["Split Line at Point" octave-indent-new-comment-line t])
253 ["Next Block" octave-forward-block t]
254 ["Previous Block" octave-backward-block t]
255 ["Down Block" octave-down-block t]
256 ["Up Block" octave-backward-up-block t]
257 ["Mark Block" octave-mark-block t]
258 ["Close Block" octave-close-block t])
260 ["Begin of Function" octave-beginning-of-defun t]
261 ["End of Function" octave-end-of-defun t]
262 ["Mark Function" octave-mark-defun t]
263 ["Indent Function" octave-indent-defun t]
264 ["Insert Function" octave-insert-defun t])
267 ["Send Current Line" octave-send-line t]
268 ["Send Current Block" octave-send-block t]
269 ["Send Current Function" octave-send-defun t]
270 ["Send Region" octave-send-region t]
271 ["Show Process Buffer" octave-show-process-buffer t]
272 ["Hide Process Buffer" octave-hide-process-buffer t]
273 ["Kill Process" octave-kill-process t])
275 ["Indent Line" indent-according-to-mode t]
276 ["Complete Symbol" octave-complete-symbol t]
278 ["Toggle Abbrev Mode" abbrev-mode t]
279 ["Toggle Auto-Fill Mode" auto-fill-mode t]
281 ["Submit Bug Report" octave-submit-bug-report t]
283 ["Describe Octave Mode" octave-describe-major-mode t]
284 ["Lookup Octave Index" octave-help t])
285 "Menu for Octave mode.")
287 (defvar octave-mode-syntax-table
288 (let ((table (make-syntax-table)))
289 (modify-syntax-entry ?\r " " table)
290 (modify-syntax-entry ?+ "." table)
291 (modify-syntax-entry ?- "." table)
292 (modify-syntax-entry ?= "." table)
293 (modify-syntax-entry ?* "." table)
294 (modify-syntax-entry ?/ "." table)
295 (modify-syntax-entry ?> "." table)
296 (modify-syntax-entry ?< "." table)
297 (modify-syntax-entry ?& "." table)
298 (modify-syntax-entry ?| "." table)
299 (modify-syntax-entry ?! "." table)
300 (modify-syntax-entry ?\\ "\\" table)
301 (modify-syntax-entry ?\' "." table)
302 (modify-syntax-entry ?\` "w" table)
303 (modify-syntax-entry ?\" "\"" table)
304 (modify-syntax-entry ?. "w" table)
305 (modify-syntax-entry ?_ "w" table)
306 (modify-syntax-entry ?\% "<" table)
307 (modify-syntax-entry ?\# "<" table)
308 (modify-syntax-entry ?\n ">" table)
310 "Syntax table in use in `octave-mode' buffers.")
312 (defcustom octave-auto-indent nil
313 "Non-nil means indent line after a semicolon or space in Octave mode."
317 (defcustom octave-auto-newline nil
318 "Non-nil means automatically newline after a semicolon in Octave mode."
322 (defcustom octave-blink-matching-block t
323 "Control the blinking of matching Octave block keywords.
324 Non-nil means show matching begin of block when inserting a space,
325 newline or semicolon after an else or end keyword."
328 (defcustom octave-block-offset 2
329 "Extra indentation applied to statements in Octave block structures."
333 (defvar octave-block-begin-regexp
335 (mapconcat 'identity octave-begin-keywords "\\|")
337 (defvar octave-block-else-regexp
339 (mapconcat 'identity octave-else-keywords "\\|")
341 (defvar octave-block-end-regexp
343 (mapconcat 'identity octave-end-keywords "\\|")
345 (defvar octave-block-begin-or-end-regexp
346 (concat octave-block-begin-regexp "\\|" octave-block-end-regexp))
347 (defvar octave-block-else-or-end-regexp
348 (concat octave-block-else-regexp "\\|" octave-block-end-regexp))
349 ;; FIXME: only use specific "end" tokens here to avoid confusion when "end"
350 ;; is used in indexing (the real fix is much more complex).
351 (defvar octave-block-match-alist
354 ("function" . ("endfunction"))
355 ("if" . ("else" "elseif" "endif"))
356 ("switch" . ("case" "otherwise" "endswitch"))
357 ("try" . ("catch" "end_try_catch"))
358 ("unwind_protect" . ("unwind_protect_cleanup" "end_unwind_protect"))
359 ("while" . ("endwhile")))
360 "Alist with Octave's matching block keywords.
361 Has Octave's begin keywords as keys and a list of the matching else or
362 end keywords as associated values.")
364 (defvar octave-block-comment-start
365 (concat (make-string 2 octave-comment-char) " ")
366 "String to insert to start a new Octave comment on an empty line.")
368 (defcustom octave-continuation-offset 4
369 "Extra indentation applied to Octave continuation lines."
372 (defvar octave-continuation-regexp
373 "[^#%\n]*\\(\\\\\\|\\.\\.\\.\\)\\s-*\\(\\s<.*\\)?$")
374 (defcustom octave-continuation-string "\\"
375 "Character string used for Octave continuation lines. Normally \\."
379 (defvar octave-completion-alist nil
380 "Alist of Octave symbols for completion in Octave mode.
381 Each element looks like (VAR . VAR), where the car and cdr are the same
382 symbol (an Octave command or variable name).
383 Currently, only builtin variables can be completed.")
385 (defvar octave-mode-imenu-generic-expression
388 (list nil octave-function-header-regexp 3))
389 "Imenu expression for Octave mode. See `imenu-generic-expression'.")
391 (defcustom octave-mode-hook nil
392 "Hook to be run when Octave mode is started."
396 (defcustom octave-send-show-buffer t
397 "Non-nil means display `inferior-octave-buffer' after sending to it."
400 (defcustom octave-send-line-auto-forward t
401 "Control auto-forward after sending to the inferior Octave process.
402 Non-nil means always go to the next Octave code line after sending."
405 (defcustom octave-send-echo-input t
406 "Non-nil means echo input sent to the inferior Octave process."
412 (defun octave-mode ()
413 "Major mode for editing Octave code.
415 This mode makes it easier to write Octave code by helping with
416 indentation, doing some of the typing for you (with Abbrev mode) and by
417 showing keywords, comments, strings, etc.. in different faces (with
418 Font Lock mode on terminals that support it).
420 Octave itself is a high-level language, primarily intended for numerical
421 computations. It provides a convenient command line interface for
422 solving linear and nonlinear problems numerically. Function definitions
423 can also be stored in files, and it can be used in a batch mode (which
424 is why you need this mode!).
426 The latest released version of Octave is always available via anonymous
427 ftp from ftp.octave.org in the directory `/pub/octave'. Complete
428 source and binaries for several popular systems are available.
430 Type \\[list-abbrevs] to display the built-in abbrevs for Octave keywords.
437 Variables you can use to customize Octave mode
438 ==============================================
441 Non-nil means indent current line after a semicolon or space.
444 `octave-auto-newline'
445 Non-nil means auto-insert a newline and indent after a semicolon.
448 `octave-blink-matching-block'
449 Non-nil means show matching begin of block when inserting a space,
450 newline or semicolon after an else or end keyword. Default is t.
452 `octave-block-offset'
453 Extra indentation applied to statements in block structures.
456 `octave-continuation-offset'
457 Extra indentation applied to Octave continuation lines.
460 `octave-continuation-string'
461 String used for Octave continuation lines.
462 Default is a backslash.
464 `octave-send-echo-input'
465 Non-nil means always display `inferior-octave-buffer' after sending a
466 command to the inferior Octave process.
468 `octave-send-line-auto-forward'
469 Non-nil means always go to the next unsent line of Octave code after
470 sending a line to the inferior Octave process.
472 `octave-send-echo-input'
473 Non-nil means echo input sent to the inferior Octave process.
475 Turning on Octave mode runs the hook `octave-mode-hook'.
477 To begin using this mode for all `.m' files that you edit, add the
478 following lines to your `.emacs' file:
480 (add-to-list 'auto-mode-alist '(\"\\\\.m\\\\'\" . octave-mode))
482 To automatically turn on the abbrev and auto-fill features,
483 add the following lines to your `.emacs' file as well:
485 (add-hook 'octave-mode-hook
490 To submit a problem report, enter \\[octave-submit-bug-report] from \
491 an Octave mode buffer.
492 This automatically sets up a mail buffer with version information
493 already added. You just need to add a description of the problem,
494 including a reproducible test case and send the message."
496 (kill-all-local-variables)
498 (use-local-map octave-mode-map)
499 (setq major-mode 'octave-mode)
500 (setq mode-name "Octave")
501 (setq local-abbrev-table octave-abbrev-table)
502 (set-syntax-table octave-mode-syntax-table)
504 (make-local-variable 'indent-line-function)
505 (setq indent-line-function 'octave-indent-line)
507 (make-local-variable 'comment-start)
508 (setq comment-start octave-comment-start)
509 (make-local-variable 'comment-end)
510 (setq comment-end "")
511 (make-local-variable 'comment-column)
512 (setq comment-column 32)
513 (make-local-variable 'comment-start-skip)
514 (setq comment-start-skip "\\s<+\\s-*")
515 (make-local-variable 'comment-indent-function)
516 (setq comment-indent-function 'octave-comment-indent)
518 (make-local-variable 'parse-sexp-ignore-comments)
519 (setq parse-sexp-ignore-comments t)
520 (make-local-variable 'paragraph-start)
521 (setq paragraph-start (concat "\\s-*$\\|" page-delimiter))
522 (make-local-variable 'paragraph-separate)
523 (setq paragraph-separate paragraph-start)
524 (make-local-variable 'paragraph-ignore-fill-prefix)
525 (setq paragraph-ignore-fill-prefix t)
526 (make-local-variable 'fill-paragraph-function)
527 (setq fill-paragraph-function 'octave-fill-paragraph)
528 (make-local-variable 'adaptive-fill-regexp)
529 (setq adaptive-fill-regexp nil)
530 (make-local-variable 'fill-column)
531 (setq fill-column 72)
532 (make-local-variable 'normal-auto-fill-function)
533 (setq normal-auto-fill-function 'octave-auto-fill)
535 (make-local-variable 'font-lock-defaults)
536 (setq font-lock-defaults '(octave-font-lock-keywords nil nil))
538 (make-local-variable 'imenu-generic-expression)
539 (setq imenu-generic-expression octave-mode-imenu-generic-expression
540 imenu-case-fold-search nil)
542 (octave-add-octave-menu)
543 (octave-initialize-completions)
544 (run-mode-hooks 'octave-mode-hook))
546 ;;; Miscellaneous useful functions
547 (defun octave-describe-major-mode ()
548 "Describe the current major mode."
550 (describe-function major-mode))
552 (defsubst octave-in-comment-p ()
553 "Return t if point is inside an Octave comment."
556 (nth 4 (parse-partial-sexp (line-beginning-position) (point)))))
558 (defsubst octave-in-string-p ()
559 "Return t if point is inside an Octave string."
562 (nth 3 (parse-partial-sexp (line-beginning-position) (point)))))
564 (defsubst octave-not-in-string-or-comment-p ()
565 "Return t if point is not inside an Octave string or comment."
566 (let ((pps (parse-partial-sexp (line-beginning-position) (point))))
567 (not (or (nth 3 pps) (nth 4 pps)))))
569 (defun octave-in-block-p ()
570 "Return t if point is inside an Octave block.
571 The block is taken to start at the first letter of the begin keyword and
572 to end after the end keyword."
577 (skip-syntax-forward "w")
579 (octave-forward-block)
584 (defun octave-in-defun-p ()
585 "Return t if point is inside an Octave function declaration.
586 The function is taken to start at the `f' of `function' and to end after
590 (or (and (looking-at "\\<function\\>")
591 (octave-not-in-string-or-comment-p))
592 (and (octave-beginning-of-defun)
595 (octave-forward-block)
600 (defun octave-maybe-insert-continuation-string ()
601 (if (or (octave-in-comment-p)
604 (looking-at octave-continuation-regexp)))
606 (delete-horizontal-space)
607 (insert (concat " " octave-continuation-string))))
609 (defvar octave-xemacs-p
610 (string-match "XEmacs\\|Lucid" emacs-version))
613 (defun octave-comment-region (beg end &optional arg)
614 "Comment or uncomment each line in the region as Octave code.
615 See `comment-region'."
617 (let ((comment-start (char-to-string octave-comment-char)))
618 (comment-region beg end arg)))
620 (defun octave-uncomment-region (beg end &optional arg)
621 "Uncomment each line in the region as Octave code."
623 (or arg (setq arg 1))
624 (octave-comment-region beg end (- arg)))
628 (defun calculate-octave-indent ()
629 "Return appropriate indentation for current line as Octave code.
630 Returns an integer (the column to indent to) unless the line is a
631 comment line with fixed goal golumn. In that case, returns a list whose
632 car is the column to indent to, and whose cdr is the current indentation
634 (let ((is-continuation-line
636 (if (zerop (octave-previous-code-line))
637 (looking-at octave-continuation-regexp))))
641 ;; If we can move backward out one level of parentheses, take 1
642 ;; plus the indentation of that parenthesis. Otherwise, go back
643 ;; to the beginning of the previous code line, and compute the
644 ;; offset this line gives.
645 (if (condition-case nil
650 (setq icol (+ 1 (current-column)))
651 (if (zerop (octave-previous-code-line))
653 (octave-beginning-of-line)
654 (back-to-indentation)
655 (setq icol (current-column))
657 (eol (line-end-position)))
658 (while (< (point) eol)
659 (if (octave-not-in-string-or-comment-p)
661 ((looking-at "\\<switch\\>")
662 (setq icol (+ icol (* 2 octave-block-offset))))
663 ((looking-at octave-block-begin-regexp)
664 (setq icol (+ icol octave-block-offset)))
665 ((looking-at octave-block-else-regexp)
667 (setq icol (+ icol octave-block-offset))))
668 ((looking-at octave-block-end-regexp)
669 (if (not (= bot (point)))
671 (octave-block-end-offset)))))))
673 (if is-continuation-line
674 (setq icol (+ icol octave-continuation-offset)))))))
676 (back-to-indentation)
678 ((and (looking-at octave-block-else-regexp)
679 (octave-not-in-string-or-comment-p))
680 (setq icol (- icol octave-block-offset)))
681 ((and (looking-at octave-block-end-regexp)
682 (octave-not-in-string-or-comment-p))
683 (setq icol (- icol (octave-block-end-offset))))
684 ((or (looking-at "\\s<\\s<\\s<\\S<")
685 (octave-before-magic-comment-p))
686 (setq icol (list 0 icol)))
687 ((looking-at "\\s<\\S<")
688 (setq icol (list comment-column icol)))))
691 (defun octave-block-end-offset ()
693 (octave-backward-up-block 1)
694 (* octave-block-offset
695 (if (string-match (match-string 0) "switch") 2 1))))
697 (defun octave-before-magic-comment-p ()
700 (and (bobp) (looking-at "\\s-*#!"))))
702 (defun octave-comment-indent ()
703 (if (or (looking-at "\\s<\\s<\\s<")
704 (octave-before-magic-comment-p))
706 (if (looking-at "\\s<\\s<")
707 (calculate-octave-indent)
708 (skip-syntax-backward " ")
709 (max (if (bolp) 0 (+ 1 (current-column)))
712 (defun octave-indent-for-comment ()
713 "Maybe insert and indent an Octave comment.
714 If there is no comment already on this line, create a code-level comment
715 \(started by two comment characters) if the line is empty, or an in-line
716 comment (started by one comment character) otherwise.
717 Point is left after the start of the comment which is properly aligned."
720 (if (looking-at "^\\s-*$")
721 (insert octave-block-comment-start)
722 (indent-for-comment))
723 (indent-according-to-mode))
725 (defun octave-indent-line (&optional arg)
726 "Indent current line as Octave code.
727 With optional ARG, use this as offset unless this line is a comment with
730 (or arg (setq arg 0))
731 (let ((icol (calculate-octave-indent))
732 (relpos (- (current-column) (current-indentation))))
734 (setq icol (car icol))
735 (setq icol (+ icol arg)))
737 (error "Unmatched end keyword")
738 (indent-line-to icol)
740 (move-to-column (+ icol relpos))))))
742 (defun octave-indent-new-comment-line ()
743 "Break Octave line at point, continuing comment if within one.
744 If within code, insert `octave-continuation-string' before breaking the
745 line. If within a string, signal an error.
746 The new line is properly indented."
748 (delete-horizontal-space)
750 ((octave-in-comment-p)
751 (indent-new-comment-line))
752 ((octave-in-string-p)
753 (error "Cannot split a code line inside a string"))
755 (insert (concat " " octave-continuation-string))
756 (octave-reindent-then-newline-and-indent))))
758 (defun octave-indent-defun ()
759 "Properly indent the Octave function which contains point."
763 (message "Indenting function...")
764 (indent-region (point) (mark) nil))
765 (message "Indenting function...done."))
769 (defun octave-next-code-line (&optional arg)
770 "Move ARG lines of Octave code forward (backward if ARG is negative).
771 Skips past all empty and comment lines. Default for ARG is 1.
773 On success, return 0. Otherwise, go as far as possible and return -1."
775 (or arg (setq arg 1))
778 (inc (if (> arg 0) 1 -1)))
779 (while (and (/= arg 0) (= n 0))
780 (setq n (forward-line inc))
782 (looking-at "\\s-*\\($\\|\\s<\\)"))
783 (setq n (forward-line inc)))
784 (setq arg (- arg inc)))
787 (defun octave-previous-code-line (&optional arg)
788 "Move ARG lines of Octave code backward (forward if ARG is negative).
789 Skips past all empty and comment lines. Default for ARG is 1.
791 On success, return 0. Otherwise, go as far as possible and return -1."
793 (or arg (setq arg 1))
794 (octave-next-code-line (- arg)))
796 (defun octave-beginning-of-line ()
797 "Move point to beginning of current Octave line.
798 If on an empty or comment line, go to the beginning of that line.
799 Otherwise, move backward to the beginning of the first Octave code line
800 which is not inside a continuation statement, i.e., which does not
801 follow a code line ending in `...' or `\\', or is inside an open
805 (if (not (looking-at "\\s-*\\($\\|\\s<\\)"))
806 (while (or (condition-case nil
812 (and (or (looking-at "\\s-*\\($\\|\\s<\\)")
814 (if (zerop (octave-previous-code-line))
815 (looking-at octave-continuation-regexp))))
816 (zerop (forward-line -1)))))))
818 (defun octave-end-of-line ()
819 "Move point to end of current Octave line.
820 If on an empty or comment line, go to the end of that line.
821 Otherwise, move forward to the end of the first Octave code line which
822 does not end in `...' or `\\' or is inside an open parenthesis list."
827 (looking-at "\\s-*\\($\\|\\s<\\)"))
829 (while (or (condition-case nil
837 (or (looking-at "\\s-*\\($\\|\\s<\\)")
838 (looking-at octave-continuation-regexp)))
839 (zerop (forward-line 1)))))
842 (defun octave-scan-blocks (count depth)
843 "Scan from point by COUNT Octave begin-end blocks.
844 Returns the character number of the position thus found.
846 If DEPTH is nonzero, block depth begins counting from that value.
847 Only places where the depth in blocks becomes zero are candidates for
848 stopping; COUNT such places are counted.
850 If the beginning or end of the buffer is reached and the depth is wrong,
851 an error is signaled."
852 (let ((min-depth (if (> depth 0) 0 depth))
853 (inc (if (> count 0) 1 -1)))
857 (while (or (re-search-forward
858 octave-block-begin-or-end-regexp nil 'move inc)
860 (error "Unbalanced block")))
861 (if (octave-not-in-string-or-comment-p)
865 (setq depth (+ depth inc)))
867 (setq depth (- depth inc))))
868 (if (< depth min-depth)
869 (error "Containing expression ends prematurely"))
871 (throw 'foo nil))))))
872 (setq count (- count inc)))
875 (defun octave-forward-block (&optional arg)
876 "Move forward across one balanced Octave begin-end block.
877 With argument, do it that many times.
878 Negative arg -N means move backward across N blocks."
880 (or arg (setq arg 1))
881 (goto-char (or (octave-scan-blocks arg 0) (buffer-end arg))))
883 (defun octave-backward-block (&optional arg)
884 "Move backward across one balanced Octave begin-end block.
885 With argument, do it that many times.
886 Negative arg -N means move forward across N blocks."
888 (or arg (setq arg 1))
889 (octave-forward-block (- arg)))
891 (defun octave-down-block (arg)
892 "Move forward down one begin-end block level of Octave code.
893 With argument, do this that many times.
894 A negative argument means move backward but still go down a level.
895 In Lisp programs, an argument is required."
897 (let ((inc (if (> arg 0) 1 -1)))
899 (goto-char (or (octave-scan-blocks inc -1)
901 (setq arg (- arg inc)))))
903 (defun octave-backward-up-block (arg)
904 "Move backward out of one begin-end block level of Octave code.
905 With argument, do this that many times.
906 A negative argument means move forward but still to a less deep spot.
907 In Lisp programs, an argument is required."
909 (octave-up-block (- arg)))
911 (defun octave-up-block (arg)
912 "Move forward out of one begin-end block level of Octave code.
913 With argument, do this that many times.
914 A negative argument means move backward but still to a less deep spot.
915 In Lisp programs, an argument is required."
917 (let ((inc (if (> arg 0) 1 -1)))
919 (goto-char (or (octave-scan-blocks inc 1)
921 (setq arg (- arg inc)))))
923 (defun octave-mark-block ()
924 "Put point at the beginning of this Octave block, mark at the end.
925 The block marked is the one that contains point or follows point."
928 (if (or (and (octave-in-block-p)
929 (skip-syntax-forward "w"))
932 (octave-down-block 1)
938 (octave-forward-block)
939 (exchange-point-and-mark))
941 (message "No block to mark found"))))
943 (defun octave-close-block ()
944 "Close the current Octave block on a separate line.
945 An error is signaled if no block to close is found."
951 (octave-backward-up-block 1)
952 (setq bb-keyword (buffer-substring-no-properties
953 (match-beginning 1) (match-end 1))))
956 (looking-at "^\\s-*$"))
957 (indent-according-to-mode)
958 (octave-reindent-then-newline-and-indent))
959 (insert (car (reverse
961 octave-block-match-alist))))
962 (octave-reindent-then-newline-and-indent)
964 (error (message "No block to close found")))))
966 (defun octave-blink-matching-block-open ()
967 "Blink the matching Octave begin block keyword.
968 If point is right after an Octave else or end type block keyword, move
969 cursor momentarily to the corresponding begin keyword.
970 Signal an error if the keywords are incompatible."
972 (let (bb-keyword bb-arg eb-keyword pos eol)
973 (if (and (octave-not-in-string-or-comment-p)
976 (skip-syntax-backward "w")
977 (looking-at octave-block-else-or-end-regexp)))
982 (buffer-substring-no-properties
983 (match-beginning 1) (match-end 1)))
984 (octave-backward-up-block 1))
987 (buffer-substring-no-properties
988 (match-beginning 2) (match-end 2)))
989 (octave-backward-block)))
990 (setq pos (match-end 0)
992 (buffer-substring-no-properties
993 (match-beginning 0) pos)
995 eol (line-end-position)
1000 (while (and (skip-syntax-forward "^<" eol)
1001 (octave-in-string-p)
1002 (not (forward-char 1))))
1003 (skip-syntax-backward " ")
1004 (buffer-substring-no-properties pos (point)))))
1005 (if (member eb-keyword
1006 (cdr (assoc bb-keyword octave-block-match-alist)))
1008 (message "Matches `%s %s'" bb-keyword bb-arg)
1009 (if (pos-visible-in-window-p)
1010 (sit-for blink-matching-delay)))
1011 (error "Block keywords `%s' and `%s' do not match"
1012 bb-keyword eb-keyword))))))
1014 (defun octave-beginning-of-defun (&optional arg)
1015 "Move backward to the beginning of an Octave function.
1016 With positive ARG, do it that many times. Negative argument -N means
1017 move forward to Nth following beginning of a function.
1018 Returns t unless search stops at the beginning or end of the buffer."
1020 (let* ((arg (or arg 1))
1021 (inc (if (> arg 0) 1 -1))
1024 (not (and (> arg 0) (looking-at "\\<function\\>")))
1025 (skip-syntax-forward "w"))
1026 (while (and (/= arg 0)
1028 (re-search-backward "\\<function\\>" nil 'move inc)))
1029 (if (octave-not-in-string-or-comment-p)
1030 (setq arg (- arg inc))))
1033 (and (< inc 0) (goto-char (match-beginning 0)))
1036 (defun octave-end-of-defun (&optional arg)
1037 "Move forward to the end of an Octave function.
1038 With positive ARG, do it that many times. Negative argument -N means
1039 move back to Nth preceding end of a function.
1041 An end of a function occurs right after the end keyword matching the
1042 `function' keyword that starts the function."
1044 (or arg (setq arg 1))
1045 (and (< arg 0) (skip-syntax-backward "w"))
1046 (and (> arg 0) (skip-syntax-forward "w"))
1047 (if (octave-in-defun-p)
1048 (setq arg (- arg 1)))
1049 (if (= arg 0) (setq arg -1))
1050 (if (octave-beginning-of-defun (- arg))
1051 (octave-forward-block)))
1053 (defun octave-mark-defun ()
1054 "Put point at the beginning of this Octave function, mark at its end.
1055 The function marked is the one containing point or following point."
1057 (let ((pos (point)))
1058 (if (or (octave-in-defun-p)
1059 (and (octave-beginning-of-defun -1)
1060 (octave-in-defun-p)))
1062 (skip-syntax-forward "w")
1063 (octave-beginning-of-defun)
1065 (octave-end-of-defun)
1066 (exchange-point-and-mark))
1068 (message "No function to mark found"))))
1072 (defun octave-auto-fill ()
1073 "Perform auto-fill in Octave mode.
1074 Returns nil if no feasible place to break the line could be found, and t
1077 (if (or (null (setq fc (current-fill-column)))
1080 (and auto-fill-inhibit-regexp
1081 (looking-at auto-fill-inhibit-regexp))))
1082 nil ; Can't do anything
1083 (if (and (not (octave-in-comment-p))
1084 (> (current-column) fc))
1085 (setq fc (- fc (+ (length octave-continuation-string) 1))))
1086 (while (and (not give-up) (> (current-column) fc))
1087 (let* ((opoint (point))
1090 (move-to-column (+ fc 1))
1091 (skip-chars-backward "^ \t\n")
1092 ;; If we're at the beginning of the line, break after
1095 (re-search-forward "[ \t]" opoint t))
1096 ;; If we're in a comment line, don't break after the
1099 (skip-syntax-backward " <")
1101 (re-search-forward "[ \t]" (line-end-position)
1103 ;; If we're not in a comment line and just ahead the
1104 ;; continuation string, don't break here.
1105 (if (and (not (octave-in-comment-p))
1109 octave-continuation-string)
1112 (skip-chars-backward " \t")
1116 (not (or (bolp) (eolp))))
1117 (let ((prev-column (current-column)))
1119 (skip-chars-backward " \t")
1122 (octave-maybe-insert-continuation-string)
1123 (indent-new-comment-line t))
1126 (octave-maybe-insert-continuation-string)
1127 (indent-new-comment-line t)))
1128 (if (>= (current-column) prev-column)
1133 (defun octave-fill-paragraph (&optional arg)
1134 "Fill paragraph of Octave code, handling Octave comments."
1135 ;; FIXME: now that the default fill-paragraph takes care of similar issues,
1136 ;; this seems obsolete. --Stef
1139 (let ((end (progn (forward-paragraph) (point)))
1141 (forward-paragraph -1)
1142 (skip-chars-forward " \t\n")
1145 (cfc (current-fill-column))
1146 (ind (calculate-octave-indent))
1150 (narrow-to-region beg end)
1151 (if (listp ind) (setq ind (nth 1 ind)))
1154 (octave-indent-line ind)
1160 (looking-at "^\\s-*\\($\\|\\s<+\\)"))))
1162 (move-to-column cfc)
1163 ;; First check whether we need to combine non-empty comment lines
1164 (if (and (< (current-column) cfc)
1165 (octave-in-comment-p)
1166 (not (save-excursion
1168 (looking-at "^\\s-*\\s<+\\s-*$"))))
1169 ;; This is a nonempty comment line which does not extend
1170 ;; past the fill column. If it is followed by a nonempty
1171 ;; comment line with the same comment prefix, try to
1172 ;; combine them, and repeat this until either we reach the
1173 ;; fill-column or there is nothing more to combine.
1175 ;; Get the comment prefix
1178 (while (and (re-search-forward "\\s<+")
1179 (not (octave-in-comment-p))))
1180 (setq comment-prefix (match-string 0)))
1181 ;; And keep combining ...
1182 (while (and (< (current-column) cfc)
1194 (re-search-forward comment-prefix)
1195 (delete-region (match-beginning 0) (match-end 0))
1197 (move-to-column cfc))))
1198 ;; We might also try to combine continued code lines> Perhaps
1199 ;; some other time ...
1200 (skip-chars-forward "^ \t\n")
1201 (delete-horizontal-space)
1202 (if (or (< (current-column) cfc)
1203 (and (= (current-column) cfc) (eolp)))
1205 (if (not (eolp)) (insert " "))
1206 (or (octave-auto-fill)
1207 (forward-line 1)))))
1212 (defun octave-initialize-completions ()
1213 "Create an alist for Octave completions."
1214 (if octave-completion-alist
1216 (setq octave-completion-alist
1217 (mapcar '(lambda (var) (cons var var))
1218 (append octave-reserved-words
1219 octave-text-functions
1220 octave-variables)))))
1222 (defun octave-complete-symbol ()
1223 "Perform completion on Octave symbol preceding point.
1224 Compare that symbol against Octave's reserved words and builtin
1226 ;; This code taken from lisp-complete-symbol
1228 (let* ((end (point))
1229 (beg (save-excursion (backward-sexp 1) (point)))
1230 (string (buffer-substring-no-properties beg end))
1231 (completion (try-completion string octave-completion-alist)))
1232 (cond ((eq completion t)) ; ???
1234 (message "Can't find completion for \"%s\"" string)
1236 ((not (string= string completion))
1237 (delete-region beg end)
1238 (insert completion))
1240 (let ((list (all-completions string octave-completion-alist))
1241 (conf (current-window-configuration)))
1242 ;; Taken from comint.el
1243 (message "Making completion list...")
1244 (with-output-to-temp-buffer "*Completions*"
1245 (display-completion-list list string))
1246 (message "Hit space to flush")
1249 (set-buffer (get-buffer "*Completions*"))
1250 (setq key (read-key-sequence nil)
1252 (and (consp first) (consp (event-start first))
1253 (eq (window-buffer (posn-window (event-start
1255 (get-buffer "*Completions*"))
1256 (eq (key-binding key) 'mouse-choose-completion)))
1258 (mouse-choose-completion first)
1259 (set-window-configuration conf))
1261 (set-window-configuration conf)
1262 (setq unread-command-events
1263 (listify-key-sequence key))))))))))
1266 ;;; Electric characters && friends
1267 (defun octave-reindent-then-newline-and-indent ()
1268 "Reindent current Octave line, insert newline, and indent the new line.
1269 If Abbrev mode is on, expand abbrevs first."
1271 (if abbrev-mode (expand-abbrev))
1272 (if octave-blink-matching-block
1273 (octave-blink-matching-block-open))
1275 (delete-region (point) (progn (skip-chars-backward " \t") (point)))
1276 (indent-according-to-mode))
1278 (indent-according-to-mode))
1280 (defun octave-electric-semi ()
1281 "Insert a semicolon in Octave mode.
1282 Maybe expand abbrevs and blink matching block open keywords.
1283 Reindent the line of `octave-auto-indent' is non-nil.
1284 Insert a newline if `octave-auto-newline' is non-nil."
1286 (if (not (octave-not-in-string-or-comment-p))
1288 (if abbrev-mode (expand-abbrev))
1289 (if octave-blink-matching-block
1290 (octave-blink-matching-block-open))
1291 (if octave-auto-indent
1292 (indent-according-to-mode))
1294 (if octave-auto-newline
1295 (newline-and-indent))))
1297 (defun octave-electric-space ()
1298 "Insert a space in Octave mode.
1299 Maybe expand abbrevs and blink matching block open keywords.
1300 Reindent the line of `octave-auto-indent' is non-nil."
1302 (setq last-command-char ? )
1303 (if (and octave-auto-indent
1304 (not (octave-not-in-string-or-comment-p)))
1306 (indent-according-to-mode)
1307 (self-insert-command 1))
1308 (if abbrev-mode (expand-abbrev))
1309 (if octave-blink-matching-block
1310 (octave-blink-matching-block-open))
1311 (if (and octave-auto-indent
1313 (skip-syntax-backward " ")
1315 (indent-according-to-mode))
1316 (self-insert-command 1)))
1318 (defun octave-abbrev-start ()
1319 "Start entering an Octave abbreviation.
1320 If Abbrev mode is turned on, typing ` (grave accent) followed by ? or
1321 \\[help-command] lists all Octave abbrevs. Any other key combination is
1323 Note that all Octave mode abbrevs start with a grave accent."
1325 (if (not abbrev-mode)
1326 (self-insert-command 1)
1328 (insert last-command-char)
1329 (if (if octave-xemacs-p
1330 (or (eq (event-to-character (setq c (next-event))) ??)
1331 (eq (event-to-character c) help-char))
1332 (or (eq (setq c (read-event)) ??)
1334 (let ((abbrev-table-name-list '(octave-abbrev-table)))
1336 (setq unread-command-events (list c))))))
1338 (defun octave-insert-defun (name args vals)
1339 "Insert an Octave function skeleton.
1340 Prompt for the function's name, arguments and return values (to be
1341 entered without parens)."
1344 (read-from-minibuffer "Function name: "
1345 (substring (buffer-name) 0 -2))
1346 (read-from-minibuffer "Arguments: ")
1347 (read-from-minibuffer "Return values: ")))
1348 (let ((string (format "%s %s (%s)"
1350 ((string-equal vals "")
1352 ((string-match "[ ,]" vals)
1353 (concat " [" vals "] ="))
1355 (concat " " vals " =")))
1358 (prefix octave-block-comment-start))
1359 (if (not (bobp)) (newline))
1360 (insert "function" string)
1361 (indent-according-to-mode)
1363 (insert prefix "usage: " string)
1364 (reindent-then-newline-and-indent)
1366 (reindent-then-newline-and-indent)
1368 (indent-according-to-mode)
1371 (insert "endfunction")
1372 (indent-according-to-mode))))
1376 (defun octave-add-octave-menu ()
1377 "Add the `Octave' menu to the menu bar in Octave mode."
1379 (easy-menu-define octave-mode-menu-map octave-mode-map
1380 "Menu keymap for Octave mode." octave-mode-menu)
1381 (easy-menu-add octave-mode-menu-map octave-mode-map))
1384 ;;; Communication with the inferior Octave process
1385 (defun octave-kill-process ()
1386 "Kill inferior Octave process and its buffer."
1388 (if inferior-octave-process
1390 (process-send-string inferior-octave-process "quit;\n")
1391 (accept-process-output inferior-octave-process)))
1392 (if inferior-octave-buffer
1393 (kill-buffer inferior-octave-buffer)))
1395 (defun octave-show-process-buffer ()
1396 "Make sure that `inferior-octave-buffer' is displayed."
1398 (if (get-buffer inferior-octave-buffer)
1399 (display-buffer inferior-octave-buffer)
1400 (message "No buffer named %s" inferior-octave-buffer)))
1402 (defun octave-hide-process-buffer ()
1403 "Delete all windows that display `inferior-octave-buffer'."
1405 (if (get-buffer inferior-octave-buffer)
1406 (delete-windows-on inferior-octave-buffer)
1407 (message "No buffer named %s" inferior-octave-buffer)))
1409 (defun octave-send-region (beg end)
1410 "Send current region to the inferior Octave process."
1413 (let ((proc inferior-octave-process)
1414 (string (buffer-substring-no-properties beg end))
1417 (set-buffer inferior-octave-buffer)
1418 (setq inferior-octave-output-list nil)
1419 (while (not (string-equal string ""))
1420 (if (string-match "\n" string)
1421 (setq line (substring string 0 (match-beginning 0))
1422 string (substring string (match-end 0)))
1423 (setq line string string ""))
1424 (setq inferior-octave-receive-in-progress t)
1425 (inferior-octave-send-list-and-digest (list (concat line "\n")))
1426 (while inferior-octave-receive-in-progress
1427 (accept-process-output proc))
1428 (insert-before-markers
1429 (mapconcat 'identity
1431 (if octave-send-echo-input (list line) (list ""))
1432 (mapcar 'inferior-octave-strip-ctrl-g
1433 inferior-octave-output-list)
1434 (list inferior-octave-output-string))
1436 (if octave-send-show-buffer
1437 (display-buffer inferior-octave-buffer)))
1439 (defun octave-send-block ()
1440 "Send current Octave block to the inferior Octave process."
1444 (octave-send-region (point) (mark))))
1446 (defun octave-send-defun ()
1447 "Send current Octave function to the inferior Octave process."
1451 (octave-send-region (point) (mark))))
1453 (defun octave-send-line (&optional arg)
1454 "Send current Octave code line to the inferior Octave process.
1455 With positive prefix ARG, send that many lines.
1456 If `octave-send-line-auto-forward' is non-nil, go to the next unsent
1459 (or arg (setq arg 1))
1464 (octave-next-code-line (- arg 1))
1467 (if octave-send-line-auto-forward
1468 (octave-next-code-line 1))
1469 (octave-send-region beg end))))
1471 (defun octave-eval-print-last-sexp ()
1472 "Evaluate Octave sexp before point and print value into current buffer."
1475 (let ((standard-output (current-buffer))
1476 (print-escape-newlines nil)
1482 (inferior-octave-send-list-and-digest
1483 (list (concat (buffer-substring-no-properties (point) opoint)
1485 (mapconcat 'identity inferior-octave-output-list "\n")))
1489 (defun octave-submit-bug-report ()
1490 "Submit a bug report on the Emacs Octave package via mail."
1494 (y-or-n-p "Do you want to submit a bug report? ")
1495 (reporter-submit-bug-report
1496 octave-maintainer-address
1497 (concat "Emacs version " emacs-version)
1500 'octave-auto-newline
1501 'octave-blink-matching-block
1502 'octave-block-offset
1503 'octave-comment-char
1504 'octave-continuation-offset
1505 'octave-continuation-string
1507 'octave-send-echo-input
1508 'octave-send-line-auto-forward
1509 'octave-send-show-buffer))))
1513 (provide 'octave-mod)
1515 ;; arch-tag: 05f1ce09-be87-4c00-803e-4919ffa26c23
1516 ;;; octave-mod.el ends here