1 ;;; octave-mod.el --- editing Octave source files under Emacs
3 ;; Copyright (C) 1997, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
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-inf.el contains code for interacting with an inferior
35 ;; Octave process using comint.
37 ;; See the documentation of `octave-mode' and
38 ;; `run-octave' for further information on usage and customization.
44 "Major mode for editing Octave source files."
45 :link
'(custom-group-link :tag
"Font Lock Faces group" font-lock-faces
)
48 (defvar inferior-octave-output-list nil
)
49 (defvar inferior-octave-output-string nil
)
50 (defvar inferior-octave-receive-in-progress nil
)
52 (declare-function inferior-octave-send-list-and-digest
"octave-inf" (list))
54 (defconst octave-maintainer-address
55 "Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>, bug-gnu-emacs@gnu.org"
56 "Current maintainer of the Emacs Octave package.")
58 (define-abbrev-table 'octave-abbrev-table
59 (mapcar (lambda (e) (append e
'(nil 0 t
)))
60 '(("`a" "all_va_args")
67 ("`et" "end_try_catch")
68 ("`eu" "end_unwind_protect")
70 ("`efu" "endfunction")
86 ("`up" "unwind_protect")
87 ("`upc" "unwind_protect_cleanup")
89 "Abbrev table for Octave's reserved words.
90 Used in `octave-mode' and inferior-octave-mode buffers.
91 All Octave abbrevs start with a grave accent (`)."
92 :regexp
"\\(?:[^`]\\|^\\)\\(\\(?:\\<\\|`\\)\\w+\\)\\W*")
94 (defvar octave-comment-char ?
#
95 "Character to start an Octave comment.")
96 (defvar octave-comment-start
97 (string octave-comment-char ?\
)
98 "String to insert to start a new Octave in-line comment.")
99 (defvar octave-comment-start-skip
"\\s<+\\s-*"
100 "Regexp to match the start of an Octave comment up to its body.")
102 (defvar octave-begin-keywords
103 '("do" "for" "function" "if" "switch" "try" "unwind_protect" "while"))
104 (defvar octave-else-keywords
105 '("case" "catch" "else" "elseif" "otherwise" "unwind_protect_cleanup"))
106 ;; FIXME: only use specific "end" tokens here to avoid confusion when "end"
107 ;; is used in indexing (the real fix is much more complex).
108 (defvar octave-end-keywords
109 '("endfor" "endfunction" "endif" "endswitch" "end_try_catch"
110 "end_unwind_protect" "endwhile" "until"))
112 (defvar octave-reserved-words
113 (append octave-begin-keywords
116 '("break" "continue" "end" "global" "persistent" "return"))
117 "Reserved words in Octave.")
119 (defvar octave-text-functions
120 '("casesen" "cd" "chdir" "clear" "diary" "dir" "document" "echo"
121 "edit_history" "format" "help" "history" "hold"
122 "load" "ls" "more" "run_history" "save" "type"
123 "which" "who" "whos")
124 "Text functions in Octave.")
126 (defvar octave-variables
127 '("DEFAULT_EXEC_PATH" "DEFAULT_LOADPATH"
128 "EDITOR" "EXEC_PATH" "F_DUPFD" "F_GETFD" "F_GETFL" "F_SETFD"
129 "F_SETFL" "I" "IMAGE_PATH" "Inf" "J"
130 "NaN" "OCTAVE_VERSION" "O_APPEND" "O_CREAT" "O_EXCL"
131 "O_NONBLOCK" "O_RDONLY" "O_RDWR" "O_TRUNC" "O_WRONLY" "PAGER" "PS1"
132 "PS2" "PS4" "PWD" "SEEK_CUR" "SEEK_END" "SEEK_SET" "__F_DUPFD__"
133 "__F_GETFD__" "__F_GETFL__" "__F_SETFD__" "__F_SETFL__" "__I__"
134 "__Inf__" "__J__" "__NaN__" "__OCTAVE_VERSION__" "__O_APPEND__"
135 "__O_CREAT__" "__O_EXCL__" "__O_NONBLOCK__" "__O_RDONLY__"
136 "__O_RDWR__" "__O_TRUNC__" "__O_WRONLY__" "__PWD__" "__SEEK_CUR__"
137 "__SEEK_END__" "__SEEK_SET__" "__argv__" "__e__" "__eps__"
138 "__i__" "__inf__" "__j__" "__nan__" "__pi__"
139 "__program_invocation_name__" "__program_name__" "__realmax__"
140 "__realmin__" "__stderr__" "__stdin__" "__stdout__" "ans" "argv"
141 "beep_on_error" "completion_append_char"
142 "crash_dumps_octave_core" "default_save_format"
143 "e" "echo_executing_commands" "eps"
144 "error_text" "gnuplot_binary" "history_file"
145 "history_size" "ignore_function_time_stamp"
146 "inf" "nan" "nargin" "output_max_field_width" "output_precision"
147 "page_output_immediately" "page_screen_output" "pi"
148 "print_answer_id_name" "print_empty_dimensions"
149 "program_invocation_name" "program_name"
150 "realmax" "realmin" "return_last_computed_value" "save_precision"
151 "saving_history" "sighup_dumps_octave_core" "sigterm_dumps_octave_core"
152 "silent_functions" "split_long_rows" "stderr" "stdin" "stdout"
153 "string_fill_char" "struct_levels_to_print"
154 "suppress_verbose_help_message")
155 "Builtin variables in Octave.")
157 (defvar octave-function-header-regexp
158 (concat "^\\s-*\\<\\(function\\)\\>"
159 "\\([^=;\n]*=[ \t]*\\|[ \t]*\\)\\(\\w+\\)\\>")
160 "Regexp to match an Octave function header.
161 The string `function' and its name are given by the first and third
162 parenthetical grouping.")
164 (defvar octave-font-lock-keywords
166 ;; Fontify all builtin keywords.
167 (cons (concat "\\<\\("
168 (mapconcat 'identity octave-reserved-words
"\\|")
169 (mapconcat 'identity octave-text-functions
"\\|")
171 'font-lock-keyword-face
)
172 ;; Fontify all builtin operators.
173 (cons "\\(&\\||\\|<=\\|>=\\|==\\|<\\|>\\|!=\\|!\\)"
174 (if (boundp 'font-lock-builtin-face
)
175 'font-lock-builtin-face
176 'font-lock-preprocessor-face
))
177 ;; Fontify all builtin variables.
178 (cons (concat "\\<\\("
179 (mapconcat 'identity octave-variables
"\\|")
181 'font-lock-variable-name-face
)
182 ;; Fontify all function declarations.
183 (list octave-function-header-regexp
184 '(1 font-lock-keyword-face
)
185 '(3 font-lock-function-name-face nil t
)))
186 "Additional Octave expressions to highlight.")
188 (defcustom inferior-octave-buffer
"*Inferior Octave*"
189 "Name of buffer for running an inferior Octave process."
191 :group
'octave-inferior
)
193 (defvar inferior-octave-process nil
)
195 (defvar octave-mode-map
196 (let ((map (make-sparse-keymap)))
197 (define-key map
"`" 'octave-abbrev-start
)
198 (define-key map
";" 'octave-electric-semi
)
199 (define-key map
" " 'octave-electric-space
)
200 (define-key map
"\n" 'octave-reindent-then-newline-and-indent
)
201 (define-key map
"\e;" 'octave-indent-for-comment
)
202 (define-key map
"\e\n" 'octave-indent-new-comment-line
)
203 (define-key map
"\e\t" 'octave-complete-symbol
)
204 (define-key map
"\M-\C-a" 'octave-beginning-of-defun
)
205 (define-key map
"\M-\C-e" 'octave-end-of-defun
)
206 (define-key map
"\M-\C-h" 'octave-mark-defun
)
207 (define-key map
"\M-\C-q" 'octave-indent-defun
)
208 (define-key map
"\C-c;" 'octave-comment-region
)
209 (define-key map
"\C-c:" 'octave-uncomment-region
)
210 (define-key map
"\C-c\C-b" 'octave-submit-bug-report
)
211 (define-key map
"\C-c\C-p" 'octave-previous-code-line
)
212 (define-key map
"\C-c\C-n" 'octave-next-code-line
)
213 (define-key map
"\C-c\C-a" 'octave-beginning-of-line
)
214 (define-key map
"\C-c\C-e" 'octave-end-of-line
)
215 (define-key map
"\C-c\M-\C-n" 'octave-forward-block
)
216 (define-key map
"\C-c\M-\C-p" 'octave-backward-block
)
217 (define-key map
"\C-c\M-\C-u" 'octave-backward-up-block
)
218 (define-key map
"\C-c\M-\C-d" 'octave-down-block
)
219 (define-key map
"\C-c\M-\C-h" 'octave-mark-block
)
220 (define-key map
"\C-c]" 'octave-close-block
)
221 (define-key map
"\C-c\C-f" 'octave-insert-defun
)
222 (define-key map
"\C-c\C-h" 'octave-help
)
223 (define-key map
"\C-c\C-il" 'octave-send-line
)
224 (define-key map
"\C-c\C-ib" 'octave-send-block
)
225 (define-key map
"\C-c\C-if" 'octave-send-defun
)
226 (define-key map
"\C-c\C-ir" 'octave-send-region
)
227 (define-key map
"\C-c\C-is" 'octave-show-process-buffer
)
228 (define-key map
"\C-c\C-ih" 'octave-hide-process-buffer
)
229 (define-key map
"\C-c\C-ik" 'octave-kill-process
)
230 (define-key map
"\C-c\C-i\C-l" 'octave-send-line
)
231 (define-key map
"\C-c\C-i\C-b" 'octave-send-block
)
232 (define-key map
"\C-c\C-i\C-f" 'octave-send-defun
)
233 (define-key map
"\C-c\C-i\C-r" 'octave-send-region
)
234 (define-key map
"\C-c\C-i\C-s" 'octave-show-process-buffer
)
235 (define-key map
"\C-c\C-i\C-h" 'octave-hide-process-buffer
)
236 (define-key map
"\C-c\C-i\C-k" 'octave-kill-process
)
238 "Keymap used in Octave mode.")
241 (defvar octave-mode-menu
244 ["Previous Code Line" octave-previous-code-line t
]
245 ["Next Code Line" octave-next-code-line t
]
246 ["Begin of Continuation" octave-beginning-of-line t
]
247 ["End of Continuation" octave-end-of-line t
]
248 ["Split Line at Point" octave-indent-new-comment-line t
])
250 ["Next Block" octave-forward-block t
]
251 ["Previous Block" octave-backward-block t
]
252 ["Down Block" octave-down-block t
]
253 ["Up Block" octave-backward-up-block t
]
254 ["Mark Block" octave-mark-block t
]
255 ["Close Block" octave-close-block t
])
257 ["Begin of Function" octave-beginning-of-defun
t]
258 ["End of Function" octave-end-of-defun
t]
259 ["Mark Function" octave-mark-defun
t]
260 ["Indent Function" octave-indent-defun
t]
261 ["Insert Function" octave-insert-defun
t])
264 ["Send Current Line" octave-send-line t
]
265 ["Send Current Block" octave-send-block t
]
266 ["Send Current Function" octave-send-defun
t]
267 ["Send Region" octave-send-region t
]
268 ["Show Process Buffer" octave-show-process-buffer t
]
269 ["Hide Process Buffer" octave-hide-process-buffer t
]
270 ["Kill Process" octave-kill-process t
])
272 ["Indent Line" indent-according-to-mode t
]
273 ["Complete Symbol" octave-complete-symbol t
]
275 ["Toggle Abbrev Mode" abbrev-mode t
]
276 ["Toggle Auto-Fill Mode" auto-fill-mode t
]
278 ["Submit Bug Report" octave-submit-bug-report t
]
280 ["Describe Octave Mode" octave-describe-major-mode t
]
281 ["Lookup Octave Index" octave-help t
])
282 "Menu for Octave mode.")
284 (defvar octave-mode-syntax-table
285 (let ((table (make-syntax-table)))
286 (modify-syntax-entry ?
\r " " table
)
287 (modify-syntax-entry ?
+ "." table
)
288 (modify-syntax-entry ?-
"." table
)
289 (modify-syntax-entry ?
= "." 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 ;; Was "w" for abbrevs, but now that it's not necessary any more,
300 (modify-syntax-entry ?\
` "." table
)
301 (modify-syntax-entry ?
\" "\"" table
)
302 (modify-syntax-entry ?.
"w" table
)
303 (modify-syntax-entry ?_
"w" table
)
304 (modify-syntax-entry ?\%
"<" table
)
305 (modify-syntax-entry ?\
# "<" table
)
306 (modify-syntax-entry ?
\n ">" table
)
308 "Syntax table in use in `octave-mode' buffers.")
310 (defcustom octave-auto-indent nil
311 "Non-nil means indent line after a semicolon or space in Octave mode."
315 (defcustom octave-auto-newline nil
316 "Non-nil means automatically newline after a semicolon in Octave mode."
320 (defcustom octave-blink-matching-block t
321 "Control the blinking of matching Octave block keywords.
322 Non-nil means show matching begin of block when inserting a space,
323 newline or semicolon after an else or end keyword."
326 (defcustom octave-block-offset
2
327 "Extra indentation applied to statements in Octave block structures."
331 (defvar octave-block-begin-regexp
333 (mapconcat 'identity octave-begin-keywords
"\\|")
335 (defvar octave-block-else-regexp
337 (mapconcat 'identity octave-else-keywords
"\\|")
339 (defvar octave-block-end-regexp
341 (mapconcat 'identity octave-end-keywords
"\\|")
343 (defvar octave-block-begin-or-end-regexp
344 (concat octave-block-begin-regexp
"\\|" octave-block-end-regexp
))
345 (defvar octave-block-else-or-end-regexp
346 (concat octave-block-else-regexp
"\\|" octave-block-end-regexp
))
347 ;; FIXME: only use specific "end" tokens here to avoid confusion when "end"
348 ;; is used in indexing (the real fix is much more complex).
349 (defvar octave-block-match-alist
352 ("function" .
("endfunction"))
353 ("if" .
("else" "elseif" "endif"))
354 ("switch" .
("case" "otherwise" "endswitch"))
355 ("try" .
("catch" "end_try_catch"))
356 ("unwind_protect" .
("unwind_protect_cleanup" "end_unwind_protect"))
357 ("while" .
("endwhile")))
358 "Alist with Octave's matching block keywords.
359 Has Octave's begin keywords as keys and a list of the matching else or
360 end keywords as associated values.")
362 (defvar octave-block-comment-start
363 (concat (make-string 2 octave-comment-char
) " ")
364 "String to insert to start a new Octave comment on an empty line.")
366 (defcustom octave-continuation-offset
4
367 "Extra indentation applied to Octave continuation lines."
370 (defvar octave-continuation-regexp
371 "[^#%\n]*\\(\\\\\\|\\.\\.\\.\\)\\s-*\\(\\s<.*\\)?$")
372 (defcustom octave-continuation-string
"\\"
373 "Character string used for Octave continuation lines. Normally \\."
377 (defvar octave-completion-alist nil
378 "Alist of Octave symbols for completion in Octave mode.
379 Each element looks like (VAR . VAR), where the car and cdr are the same
380 symbol (an Octave command or variable name).
381 Currently, only builtin variables can be completed.")
383 (defvar octave-mode-imenu-generic-expression
386 (list nil octave-function-header-regexp
3))
387 "Imenu expression for Octave mode. See `imenu-generic-expression'.")
389 (defcustom octave-mode-hook nil
390 "Hook to be run when Octave mode is started."
394 (defcustom octave-send-show-buffer t
395 "Non-nil means display `inferior-octave-buffer' after sending to it."
398 (defcustom octave-send-line-auto-forward t
399 "Control auto-forward after sending to the inferior Octave process.
400 Non-nil means always go to the next Octave code line after sending."
403 (defcustom octave-send-echo-input t
404 "Non-nil means echo input sent to the inferior Octave process."
410 (defun octave-mode ()
411 "Major mode for editing Octave code.
413 This mode makes it easier to write Octave code by helping with
414 indentation, doing some of the typing for you (with Abbrev mode) and by
415 showing keywords, comments, strings, etc.. in different faces (with
416 Font Lock mode on terminals that support it).
418 Octave itself is a high-level language, primarily intended for numerical
419 computations. It provides a convenient command line interface for
420 solving linear and nonlinear problems numerically. Function definitions
421 can also be stored in files, and it can be used in a batch mode (which
422 is why you need this mode!).
424 The latest released version of Octave is always available via anonymous
425 ftp from ftp.octave.org in the directory `/pub/octave'. Complete
426 source and binaries for several popular systems are available.
428 Type \\[list-abbrevs] to display the built-in abbrevs for Octave keywords.
435 Variables you can use to customize Octave mode
436 ==============================================
439 Non-nil means indent current line after a semicolon or space.
442 `octave-auto-newline'
443 Non-nil means auto-insert a newline and indent after a semicolon.
446 `octave-blink-matching-block'
447 Non-nil means show matching begin of block when inserting a space,
448 newline or semicolon after an else or end keyword. Default is t.
450 `octave-block-offset'
451 Extra indentation applied to statements in block structures.
454 `octave-continuation-offset'
455 Extra indentation applied to Octave continuation lines.
458 `octave-continuation-string'
459 String used for Octave continuation lines.
460 Default is a backslash.
462 `octave-send-echo-input'
463 Non-nil means always display `inferior-octave-buffer' after sending a
464 command to the inferior Octave process.
466 `octave-send-line-auto-forward'
467 Non-nil means always go to the next unsent line of Octave code after
468 sending a line to the inferior Octave process.
470 `octave-send-echo-input'
471 Non-nil means echo input sent to the inferior Octave process.
473 Turning on Octave mode runs the hook `octave-mode-hook'.
475 To begin using this mode for all `.m' files that you edit, add the
476 following lines to your `.emacs' file:
478 (add-to-list 'auto-mode-alist '(\"\\\\.m\\\\'\" . octave-mode))
480 To automatically turn on the abbrev and auto-fill features,
481 add the following lines to your `.emacs' file as well:
483 (add-hook 'octave-mode-hook
488 To submit a problem report, enter \\[octave-submit-bug-report] from \
489 an Octave mode buffer.
490 This automatically sets up a mail buffer with version information
491 already added. You just need to add a description of the problem,
492 including a reproducible test case and send the message."
494 (kill-all-local-variables)
496 (use-local-map octave-mode-map
)
497 (setq major-mode
'octave-mode
)
498 (setq mode-name
"Octave")
499 (setq local-abbrev-table octave-abbrev-table
)
500 (set-syntax-table octave-mode-syntax-table
)
502 (make-local-variable 'indent-line-function
)
503 (setq indent-line-function
'octave-indent-line
)
505 (make-local-variable 'comment-start
)
506 (setq comment-start octave-comment-start
)
507 (make-local-variable 'comment-end
)
508 (setq comment-end
"")
509 (make-local-variable 'comment-column
)
510 (setq comment-column
32)
511 (make-local-variable 'comment-start-skip
)
512 (setq comment-start-skip
"\\s<+\\s-*")
513 (make-local-variable 'comment-indent-function
)
514 (setq comment-indent-function
'octave-comment-indent
)
516 (make-local-variable 'parse-sexp-ignore-comments
)
517 (setq parse-sexp-ignore-comments t
)
518 (make-local-variable 'paragraph-start
)
519 (setq paragraph-start
(concat "\\s-*$\\|" page-delimiter
))
520 (make-local-variable 'paragraph-separate
)
521 (setq paragraph-separate paragraph-start
)
522 (make-local-variable 'paragraph-ignore-fill-prefix
)
523 (setq paragraph-ignore-fill-prefix t
)
524 (make-local-variable 'fill-paragraph-function
)
525 (setq fill-paragraph-function
'octave-fill-paragraph
)
526 (make-local-variable 'adaptive-fill-regexp
)
527 (setq adaptive-fill-regexp nil
)
528 (make-local-variable 'fill-column
)
529 (setq fill-column
72)
530 (make-local-variable 'normal-auto-fill-function
)
531 (setq normal-auto-fill-function
'octave-auto-fill
)
533 (make-local-variable 'font-lock-defaults
)
534 (setq font-lock-defaults
'(octave-font-lock-keywords nil nil
))
536 (make-local-variable 'imenu-generic-expression
)
537 (setq imenu-generic-expression octave-mode-imenu-generic-expression
538 imenu-case-fold-search nil
)
540 (octave-add-octave-menu)
541 (octave-initialize-completions)
542 (run-mode-hooks 'octave-mode-hook
))
544 (defun octave-help ()
545 "Get help on Octave symbols from the Octave info files.
546 Look up symbol in the function, operator and variable indices of the info files."
547 (let ((info-lookup-mode 'octave-mode
))
548 (call-interactively 'info-lookup-symbol
)))
550 ;;; Miscellaneous useful functions
551 (defun octave-describe-major-mode ()
552 "Describe the current major mode."
554 (describe-function major-mode
))
556 (defsubst octave-in-comment-p
()
557 "Return t if point is inside an Octave comment."
560 (nth 4 (parse-partial-sexp (line-beginning-position) (point)))))
562 (defsubst octave-in-string-p
()
563 "Return t if point is inside an Octave string."
566 (nth 3 (parse-partial-sexp (line-beginning-position) (point)))))
568 (defsubst octave-not-in-string-or-comment-p
()
569 "Return t if point is not inside an Octave string or comment."
570 (let ((pps (parse-partial-sexp (line-beginning-position) (point))))
571 (not (or (nth 3 pps
) (nth 4 pps
)))))
573 (defun octave-in-block-p ()
574 "Return t if point is inside an Octave block.
575 The block is taken to start at the first letter of the begin keyword and
576 to end after the end keyword."
581 (skip-syntax-forward "w")
583 (octave-forward-block)
588 (defun octave-looking-at-kw (regexp)
589 "Like `looking-at', but sets `case-fold-search' nil."
590 (let ((case-fold-search nil
))
591 (looking-at regexp
)))
593 (defun octave-re-search-forward-kw (regexp count
)
594 "Like `re-search-forward', but sets `case-fold-search' nil, and moves point."
595 (let ((case-fold-search nil
))
596 (re-search-forward regexp nil
'move count
)))
598 (defun octave-re-search-backward-kw (regexp count
)
599 "Like `re-search-backward', but sets `case-fold-search' nil, and moves point."
600 (let ((case-fold-search nil
))
601 (re-search-backward regexp nil
'move count
)))
603 (defun octave-in-defun-p ()
604 "Return t if point is inside an Octave function declaration.
605 The function is taken to start at the `f' of `function' and to end after
609 (or (and (octave-looking-at-kw "\\<function\\>")
610 (octave-not-in-string-or-comment-p))
611 (and (octave-beginning-of-defun)
614 (octave-forward-block)
619 (defun octave-maybe-insert-continuation-string ()
620 (if (or (octave-in-comment-p)
623 (looking-at octave-continuation-regexp
)))
625 (delete-horizontal-space)
626 (insert (concat " " octave-continuation-string
))))
629 (defun octave-comment-region (beg end
&optional arg
)
630 "Comment or uncomment each line in the region as Octave code.
631 See `comment-region'."
633 (let ((comment-start (char-to-string octave-comment-char
)))
634 (comment-region beg end arg
)))
636 (defun octave-uncomment-region (beg end
&optional arg
)
637 "Uncomment each line in the region as Octave code."
639 (or arg
(setq arg
1))
640 (octave-comment-region beg end
(- arg
)))
644 (defun calculate-octave-indent ()
645 "Return appropriate indentation for current line as Octave code.
646 Returns an integer (the column to indent to) unless the line is a
647 comment line with fixed goal golumn. In that case, returns a list whose
648 car is the column to indent to, and whose cdr is the current indentation
650 (let ((is-continuation-line
652 (if (zerop (octave-previous-code-line))
653 (looking-at octave-continuation-regexp
))))
657 ;; If we can move backward out one level of parentheses, take 1
658 ;; plus the indentation of that parenthesis. Otherwise, go back
659 ;; to the beginning of the previous code line, and compute the
660 ;; offset this line gives.
661 (if (condition-case nil
666 (setq icol
(+ 1 (current-column)))
667 (if (zerop (octave-previous-code-line))
669 (octave-beginning-of-line)
670 (back-to-indentation)
671 (setq icol
(current-column))
673 (eol (line-end-position)))
674 (while (< (point) eol
)
675 (if (octave-not-in-string-or-comment-p)
677 ((octave-looking-at-kw "\\<switch\\>")
678 (setq icol
(+ icol
(* 2 octave-block-offset
))))
679 ((octave-looking-at-kw octave-block-begin-regexp
)
680 (setq icol
(+ icol octave-block-offset
)))
681 ((octave-looking-at-kw octave-block-else-regexp
)
683 (setq icol
(+ icol octave-block-offset
))))
684 ((octave-looking-at-kw octave-block-end-regexp
)
685 (if (not (= bot
(point)))
687 (octave-block-end-offset)))))))
689 (if is-continuation-line
690 (setq icol
(+ icol octave-continuation-offset
)))))))
692 (back-to-indentation)
694 ((and (octave-looking-at-kw octave-block-else-regexp
)
695 (octave-not-in-string-or-comment-p))
696 (setq icol
(- icol octave-block-offset
)))
697 ((and (octave-looking-at-kw octave-block-end-regexp
)
698 (octave-not-in-string-or-comment-p))
699 (setq icol
(- icol
(octave-block-end-offset))))
700 ((or (looking-at "\\s<\\s<\\s<\\S<")
701 (octave-before-magic-comment-p))
702 (setq icol
(list 0 icol
)))
703 ((looking-at "\\s<\\S<")
704 (setq icol
(list comment-column icol
)))))
707 (defun octave-block-end-offset ()
709 (octave-backward-up-block 1)
710 (* octave-block-offset
711 (if (string-match (match-string 0) "switch") 2 1))))
713 (defun octave-before-magic-comment-p ()
716 (and (bobp) (looking-at "\\s-*#!"))))
718 (defun octave-comment-indent ()
719 (if (or (looking-at "\\s<\\s<\\s<")
720 (octave-before-magic-comment-p))
722 (if (looking-at "\\s<\\s<")
723 (calculate-octave-indent)
724 (skip-syntax-backward " ")
725 (max (if (bolp) 0 (+ 1 (current-column)))
728 (defun octave-indent-for-comment ()
729 "Maybe insert and indent an Octave comment.
730 If there is no comment already on this line, create a code-level comment
731 \(started by two comment characters) if the line is empty, or an in-line
732 comment (started by one comment character) otherwise.
733 Point is left after the start of the comment which is properly aligned."
736 (if (looking-at "^\\s-*$")
737 (insert octave-block-comment-start
)
738 (indent-for-comment))
739 (indent-according-to-mode))
741 (defun octave-indent-line (&optional arg
)
742 "Indent current line as Octave code.
743 With optional ARG, use this as offset unless this line is a comment with
746 (or arg
(setq arg
0))
747 (let ((icol (calculate-octave-indent))
748 (relpos (- (current-column) (current-indentation))))
750 (setq icol
(car icol
))
751 (setq icol
(+ icol arg
)))
753 (error "Unmatched end keyword")
754 (indent-line-to icol
)
756 (move-to-column (+ icol relpos
))))))
758 (defun octave-indent-new-comment-line ()
759 "Break Octave line at point, continuing comment if within one.
760 If within code, insert `octave-continuation-string' before breaking the
761 line. If within a string, signal an error.
762 The new line is properly indented."
764 (delete-horizontal-space)
766 ((octave-in-comment-p)
767 (indent-new-comment-line))
768 ((octave-in-string-p)
769 (error "Cannot split a code line inside a string"))
771 (insert (concat " " octave-continuation-string
))
772 (octave-reindent-then-newline-and-indent))))
774 (defun octave-indent-defun ()
775 "Properly indent the Octave function which contains point."
779 (message "Indenting function...")
780 (indent-region (point) (mark) nil
))
781 (message "Indenting function...done."))
785 (defun octave-next-code-line (&optional arg
)
786 "Move ARG lines of Octave code forward (backward if ARG is negative).
787 Skips past all empty and comment lines. Default for ARG is 1.
789 On success, return 0. Otherwise, go as far as possible and return -1."
791 (or arg
(setq arg
1))
794 (inc (if (> arg
0) 1 -
1)))
795 (while (and (/= arg
0) (= n
0))
796 (setq n
(forward-line inc
))
798 (looking-at "\\s-*\\($\\|\\s<\\)"))
799 (setq n
(forward-line inc
)))
800 (setq arg
(- arg inc
)))
803 (defun octave-previous-code-line (&optional arg
)
804 "Move ARG lines of Octave code backward (forward if ARG is negative).
805 Skips past all empty and comment lines. Default for ARG is 1.
807 On success, return 0. Otherwise, go as far as possible and return -1."
809 (or arg
(setq arg
1))
810 (octave-next-code-line (- arg
)))
812 (defun octave-beginning-of-line ()
813 "Move point to beginning of current Octave line.
814 If on an empty or comment line, go to the beginning of that line.
815 Otherwise, move backward to the beginning of the first Octave code line
816 which is not inside a continuation statement, i.e., which does not
817 follow a code line ending in `...' or `\\', or is inside an open
821 (if (not (looking-at "\\s-*\\($\\|\\s<\\)"))
822 (while (or (condition-case nil
828 (and (or (looking-at "\\s-*\\($\\|\\s<\\)")
830 (if (zerop (octave-previous-code-line))
831 (looking-at octave-continuation-regexp
))))
832 (zerop (forward-line -
1)))))))
834 (defun octave-end-of-line ()
835 "Move point to end of current Octave line.
836 If on an empty or comment line, go to the end of that line.
837 Otherwise, move forward to the end of the first Octave code line which
838 does not end in `...' or `\\' or is inside an open parenthesis list."
843 (looking-at "\\s-*\\($\\|\\s<\\)"))
845 (while (or (condition-case nil
853 (or (looking-at "\\s-*\\($\\|\\s<\\)")
854 (looking-at octave-continuation-regexp
)))
855 (zerop (forward-line 1)))))
858 (defun octave-scan-blocks (count depth
)
859 "Scan from point by COUNT Octave begin-end blocks.
860 Returns the character number of the position thus found.
862 If DEPTH is nonzero, block depth begins counting from that value.
863 Only places where the depth in blocks becomes zero are candidates for
864 stopping; COUNT such places are counted.
866 If the beginning or end of the buffer is reached and the depth is wrong,
867 an error is signaled."
868 (let ((min-depth (if (> depth
0) 0 depth
))
869 (inc (if (> count
0) 1 -
1)))
873 (while (or (octave-re-search-forward-kw
874 octave-block-begin-or-end-regexp inc
)
876 (error "Unbalanced block")))
877 (if (octave-not-in-string-or-comment-p)
881 (setq depth
(+ depth inc
)))
883 (setq depth
(- depth inc
))))
884 (if (< depth min-depth
)
885 (error "Containing expression ends prematurely"))
887 (throw 'foo nil
))))))
888 (setq count
(- count inc
)))
891 (defun octave-forward-block (&optional arg
)
892 "Move forward across one balanced Octave begin-end block.
893 With argument, do it that many times.
894 Negative arg -N means move backward across N blocks."
896 (or arg
(setq arg
1))
897 (goto-char (or (octave-scan-blocks arg
0) (buffer-end arg
))))
899 (defun octave-backward-block (&optional arg
)
900 "Move backward across one balanced Octave begin-end block.
901 With argument, do it that many times.
902 Negative arg -N means move forward across N blocks."
904 (or arg
(setq arg
1))
905 (octave-forward-block (- arg
)))
907 (defun octave-down-block (arg)
908 "Move forward down one begin-end block level of Octave code.
909 With argument, do this that many times.
910 A negative argument means move backward but still go down a level.
911 In Lisp programs, an argument is required."
913 (let ((inc (if (> arg
0) 1 -
1)))
915 (goto-char (or (octave-scan-blocks inc -
1)
917 (setq arg
(- arg inc
)))))
919 (defun octave-backward-up-block (arg)
920 "Move backward out of one begin-end block level of Octave code.
921 With argument, do this that many times.
922 A negative argument means move forward but still to a less deep spot.
923 In Lisp programs, an argument is required."
925 (octave-up-block (- arg
)))
927 (defun octave-up-block (arg)
928 "Move forward out of one begin-end block level of Octave code.
929 With argument, do this that many times.
930 A negative argument means move backward but still to a less deep spot.
931 In Lisp programs, an argument is required."
933 (let ((inc (if (> arg
0) 1 -
1)))
935 (goto-char (or (octave-scan-blocks inc
1)
937 (setq arg
(- arg inc
)))))
939 (defun octave-mark-block ()
940 "Put point at the beginning of this Octave block, mark at the end.
941 The block marked is the one that contains point or follows point."
944 (if (or (and (octave-in-block-p)
945 (skip-syntax-forward "w"))
948 (octave-down-block 1)
954 (octave-forward-block)
955 (exchange-point-and-mark))
957 (message "No block to mark found"))))
959 (defun octave-close-block ()
960 "Close the current Octave block on a separate line.
961 An error is signaled if no block to close is found."
967 (octave-backward-up-block 1)
968 (setq bb-keyword
(buffer-substring-no-properties
969 (match-beginning 1) (match-end 1))))
972 (looking-at "^\\s-*$"))
973 (indent-according-to-mode)
974 (octave-reindent-then-newline-and-indent))
975 (insert (car (reverse
977 octave-block-match-alist
))))
978 (octave-reindent-then-newline-and-indent)
980 (error (message "No block to close found")))))
982 (defun octave-blink-matching-block-open ()
983 "Blink the matching Octave begin block keyword.
984 If point is right after an Octave else or end type block keyword, move
985 cursor momentarily to the corresponding begin keyword.
986 Signal an error if the keywords are incompatible."
988 (let (bb-keyword bb-arg eb-keyword pos eol
)
989 (if (and (octave-not-in-string-or-comment-p)
992 (skip-syntax-backward "w")
993 (octave-looking-at-kw octave-block-else-or-end-regexp
)))
998 (buffer-substring-no-properties
999 (match-beginning 1) (match-end 1)))
1000 (octave-backward-up-block 1))
1003 (buffer-substring-no-properties
1004 (match-beginning 2) (match-end 2)))
1005 (octave-backward-block)))
1006 (setq pos
(match-end 0)
1008 (buffer-substring-no-properties
1009 (match-beginning 0) pos
)
1011 eol
(line-end-position)
1016 (while (and (skip-syntax-forward "^<" eol
)
1017 (octave-in-string-p)
1018 (not (forward-char 1))))
1019 (skip-syntax-backward " ")
1020 (buffer-substring-no-properties pos
(point)))))
1021 (if (member eb-keyword
1022 (cdr (assoc bb-keyword octave-block-match-alist
)))
1024 (message "Matches `%s %s'" bb-keyword bb-arg
)
1025 (if (pos-visible-in-window-p)
1026 (sit-for blink-matching-delay
)))
1027 (error "Block keywords `%s' and `%s' do not match"
1028 bb-keyword eb-keyword
))))))
1030 (defun octave-beginning-of-defun (&optional arg
)
1031 "Move backward to the beginning of an Octave function.
1032 With positive ARG, do it that many times. Negative argument -N means
1033 move forward to Nth following beginning of a function.
1034 Returns t unless search stops at the beginning or end of the buffer."
1036 (let* ((arg (or arg
1))
1037 (inc (if (> arg
0) 1 -
1))
1040 (not (and (> arg
0) (octave-looking-at-kw "\\<function\\>")))
1041 (skip-syntax-forward "w"))
1042 (while (and (/= arg
0)
1044 (octave-re-search-backward-kw "\\<function\\>" inc
)))
1045 (if (octave-not-in-string-or-comment-p)
1046 (setq arg
(- arg inc
))))
1049 (and (< inc
0) (goto-char (match-beginning 0)))
1052 (defun octave-end-of-defun (&optional arg
)
1053 "Move forward to the end of an Octave function.
1054 With positive ARG, do it that many times. Negative argument -N means
1055 move back to Nth preceding end of a function.
1057 An end of a function occurs right after the end keyword matching the
1058 `function' keyword that starts the function."
1060 (or arg
(setq arg
1))
1061 (and (< arg
0) (skip-syntax-backward "w"))
1062 (and (> arg
0) (skip-syntax-forward "w"))
1063 (if (octave-in-defun-p)
1064 (setq arg
(- arg
1)))
1065 (if (= arg
0) (setq arg -
1))
1066 (if (octave-beginning-of-defun (- arg
))
1067 (octave-forward-block)))
1069 (defun octave-mark-defun ()
1070 "Put point at the beginning of this Octave function, mark at its end.
1071 The function marked is the one containing point or following point."
1073 (let ((pos (point)))
1074 (if (or (octave-in-defun-p)
1075 (and (octave-beginning-of-defun -1)
1076 (octave-in-defun-p)))
1078 (skip-syntax-forward "w")
1079 (octave-beginning-of-defun)
1081 (octave-end-of-defun)
1082 (exchange-point-and-mark))
1084 (message "No function to mark found"))))
1088 (defun octave-auto-fill ()
1089 "Perform auto-fill in Octave mode.
1090 Returns nil if no feasible place to break the line could be found, and t
1093 (if (or (null (setq fc
(current-fill-column)))
1096 (and auto-fill-inhibit-regexp
1097 (octave-looking-at-kw auto-fill-inhibit-regexp
))))
1098 nil
; Can't do anything
1099 (if (and (not (octave-in-comment-p))
1100 (> (current-column) fc
))
1101 (setq fc
(- fc
(+ (length octave-continuation-string
) 1))))
1102 (while (and (not give-up
) (> (current-column) fc
))
1103 (let* ((opoint (point))
1106 (move-to-column (+ fc
1))
1107 (skip-chars-backward "^ \t\n")
1108 ;; If we're at the beginning of the line, break after
1111 (re-search-forward "[ \t]" opoint t
))
1112 ;; If we're in a comment line, don't break after the
1115 (skip-syntax-backward " <")
1117 (re-search-forward "[ \t]" (line-end-position)
1119 ;; If we're not in a comment line and just ahead the
1120 ;; continuation string, don't break here.
1121 (if (and (not (octave-in-comment-p))
1125 octave-continuation-string
)
1128 (skip-chars-backward " \t")
1132 (not (or (bolp) (eolp))))
1133 (let ((prev-column (current-column)))
1135 (skip-chars-backward " \t")
1138 (octave-maybe-insert-continuation-string)
1139 (indent-new-comment-line t
))
1142 (octave-maybe-insert-continuation-string)
1143 (indent-new-comment-line t
)))
1144 (if (>= (current-column) prev-column
)
1149 (defun octave-fill-paragraph (&optional arg
)
1150 "Fill paragraph of Octave code, handling Octave comments."
1151 ;; FIXME: now that the default fill-paragraph takes care of similar issues,
1152 ;; this seems obsolete. --Stef
1155 (let ((end (progn (forward-paragraph) (point)))
1157 (forward-paragraph -
1)
1158 (skip-chars-forward " \t\n")
1161 (cfc (current-fill-column))
1162 (ind (calculate-octave-indent))
1166 (narrow-to-region beg end
)
1167 (if (listp ind
) (setq ind
(nth 1 ind
)))
1170 (octave-indent-line ind
)
1176 (looking-at "^\\s-*\\($\\|\\s<+\\)"))))
1178 (move-to-column cfc
)
1179 ;; First check whether we need to combine non-empty comment lines
1180 (if (and (< (current-column) cfc
)
1181 (octave-in-comment-p)
1182 (not (save-excursion
1184 (looking-at "^\\s-*\\s<+\\s-*$"))))
1185 ;; This is a nonempty comment line which does not extend
1186 ;; past the fill column. If it is followed by a nonempty
1187 ;; comment line with the same comment prefix, try to
1188 ;; combine them, and repeat this until either we reach the
1189 ;; fill-column or there is nothing more to combine.
1191 ;; Get the comment prefix
1194 (while (and (re-search-forward "\\s<+")
1195 (not (octave-in-comment-p))))
1196 (setq comment-prefix
(match-string 0)))
1197 ;; And keep combining ...
1198 (while (and (< (current-column) cfc
)
1210 (re-search-forward comment-prefix
)
1211 (delete-region (match-beginning 0) (match-end 0))
1213 (move-to-column cfc
))))
1214 ;; We might also try to combine continued code lines> Perhaps
1215 ;; some other time ...
1216 (skip-chars-forward "^ \t\n")
1217 (delete-horizontal-space)
1218 (if (or (< (current-column) cfc
)
1219 (and (= (current-column) cfc
) (eolp)))
1221 (if (not (eolp)) (insert " "))
1222 (or (octave-auto-fill)
1223 (forward-line 1)))))
1228 (defun octave-initialize-completions ()
1229 "Create an alist for Octave completions."
1230 (if octave-completion-alist
1232 (setq octave-completion-alist
1233 (mapcar '(lambda (var) (cons var var
))
1234 (append octave-reserved-words
1235 octave-text-functions
1236 octave-variables
)))))
1238 (defun octave-complete-symbol ()
1239 "Perform completion on Octave symbol preceding point.
1240 Compare that symbol against Octave's reserved words and builtin
1242 ;; This code taken from lisp-complete-symbol
1244 (let* ((end (point))
1245 (beg (save-excursion (backward-sexp 1) (point)))
1246 (string (buffer-substring-no-properties beg end
))
1247 (completion (try-completion string octave-completion-alist
)))
1248 (cond ((eq completion t
)) ; ???
1250 (message "Can't find completion for \"%s\"" string
)
1252 ((not (string= string completion
))
1253 (delete-region beg end
)
1254 (insert completion
))
1256 (let ((list (all-completions string octave-completion-alist
))
1257 (conf (current-window-configuration)))
1258 ;; Taken from comint.el
1259 (message "Making completion list...")
1260 (with-output-to-temp-buffer "*Completions*"
1261 (display-completion-list list string
))
1262 (message "Hit space to flush")
1264 (if (with-current-buffer (get-buffer "*Completions*")
1265 (setq key
(read-key-sequence nil
)
1267 (and (consp first
) (consp (event-start first
))
1268 (eq (window-buffer (posn-window (event-start
1270 (get-buffer "*Completions*"))
1271 (eq (key-binding key
) 'mouse-choose-completion
)))
1273 (mouse-choose-completion first
)
1274 (set-window-configuration conf
))
1276 (set-window-configuration conf
)
1277 (setq unread-command-events
1278 (listify-key-sequence key
))))))))))
1281 ;;; Electric characters && friends
1282 (defun octave-reindent-then-newline-and-indent ()
1283 "Reindent current Octave line, insert newline, and indent the new line.
1284 If Abbrev mode is on, expand abbrevs first."
1286 (if abbrev-mode
(expand-abbrev))
1287 (if octave-blink-matching-block
1288 (octave-blink-matching-block-open))
1290 (delete-region (point) (progn (skip-chars-backward " \t") (point)))
1291 (indent-according-to-mode))
1293 (indent-according-to-mode))
1295 (defun octave-electric-semi ()
1296 "Insert a semicolon in Octave mode.
1297 Maybe expand abbrevs and blink matching block open keywords.
1298 Reindent the line of `octave-auto-indent' is non-nil.
1299 Insert a newline if `octave-auto-newline' is non-nil."
1301 (if (not (octave-not-in-string-or-comment-p))
1303 (if abbrev-mode
(expand-abbrev))
1304 (if octave-blink-matching-block
1305 (octave-blink-matching-block-open))
1306 (if octave-auto-indent
1307 (indent-according-to-mode))
1309 (if octave-auto-newline
1310 (newline-and-indent))))
1312 (defun octave-electric-space ()
1313 "Insert a space in Octave mode.
1314 Maybe expand abbrevs and blink matching block open keywords.
1315 Reindent the line of `octave-auto-indent' is non-nil."
1317 (setq last-command-char ?
)
1318 (if (and octave-auto-indent
1319 (not (octave-not-in-string-or-comment-p)))
1321 (indent-according-to-mode)
1322 (self-insert-command 1))
1323 (if abbrev-mode
(expand-abbrev))
1324 (if octave-blink-matching-block
1325 (octave-blink-matching-block-open))
1326 (if (and octave-auto-indent
1328 (skip-syntax-backward " ")
1330 (indent-according-to-mode))
1331 (self-insert-command 1)))
1333 (defun octave-abbrev-start ()
1334 "Start entering an Octave abbreviation.
1335 If Abbrev mode is turned on, typing ` (grave accent) followed by ? or
1336 \\[help-command] lists all Octave abbrevs. Any other key combination is
1338 Note that all Octave mode abbrevs start with a grave accent."
1340 (if (not abbrev-mode
)
1341 (self-insert-command 1)
1343 (insert last-command-char
)
1344 (if (if (featurep 'xemacs
)
1345 (or (eq (event-to-character (setq c
(next-event))) ??
)
1346 (eq (event-to-character c
) help-char
))
1347 (or (eq (setq c
(read-event)) ??
)
1349 (let ((abbrev-table-name-list '(octave-abbrev-table)))
1351 (setq unread-command-events
(list c
))))))
1353 (defun octave-insert-defun (name args vals
)
1354 "Insert an Octave function skeleton.
1355 Prompt for the function's name, arguments and return values (to be
1356 entered without parens)."
1359 (read-from-minibuffer "Function name: "
1360 (substring (buffer-name) 0 -
2))
1361 (read-from-minibuffer "Arguments: ")
1362 (read-from-minibuffer "Return values: ")))
1363 (let ((string (format "%s %s (%s)"
1365 ((string-equal vals
"")
1367 ((string-match "[ ,]" vals
)
1368 (concat " [" vals
"] ="))
1370 (concat " " vals
" =")))
1373 (prefix octave-block-comment-start
))
1374 (if (not (bobp)) (newline))
1375 (insert "function" string
)
1376 (indent-according-to-mode)
1378 (insert prefix
"usage: " string
)
1379 (reindent-then-newline-and-indent)
1381 (reindent-then-newline-and-indent)
1383 (indent-according-to-mode)
1386 (insert "endfunction")
1387 (indent-according-to-mode))))
1391 (defun octave-add-octave-menu ()
1392 "Add the `Octave' menu to the menu bar in Octave mode."
1394 (easy-menu-define octave-mode-menu-map octave-mode-map
1395 "Menu keymap for Octave mode." octave-mode-menu
)
1396 (easy-menu-add octave-mode-menu-map octave-mode-map
))
1399 ;;; Communication with the inferior Octave process
1400 (defun octave-kill-process ()
1401 "Kill inferior Octave process and its buffer."
1403 (if inferior-octave-process
1405 (process-send-string inferior-octave-process
"quit;\n")
1406 (accept-process-output inferior-octave-process
)))
1407 (if inferior-octave-buffer
1408 (kill-buffer inferior-octave-buffer
)))
1410 (defun octave-show-process-buffer ()
1411 "Make sure that `inferior-octave-buffer' is displayed."
1413 (if (get-buffer inferior-octave-buffer
)
1414 (display-buffer inferior-octave-buffer
)
1415 (message "No buffer named %s" inferior-octave-buffer
)))
1417 (defun octave-hide-process-buffer ()
1418 "Delete all windows that display `inferior-octave-buffer'."
1420 (if (get-buffer inferior-octave-buffer
)
1421 (delete-windows-on inferior-octave-buffer
)
1422 (message "No buffer named %s" inferior-octave-buffer
)))
1424 (defun octave-send-region (beg end
)
1425 "Send current region to the inferior Octave process."
1428 (let ((proc inferior-octave-process
)
1429 (string (buffer-substring-no-properties beg end
))
1431 (with-current-buffer inferior-octave-buffer
1432 (setq inferior-octave-output-list nil
)
1433 (while (not (string-equal string
""))
1434 (if (string-match "\n" string
)
1435 (setq line
(substring string
0 (match-beginning 0))
1436 string
(substring string
(match-end 0)))
1437 (setq line string string
""))
1438 (setq inferior-octave-receive-in-progress t
)
1439 (inferior-octave-send-list-and-digest (list (concat line
"\n")))
1440 (while inferior-octave-receive-in-progress
1441 (accept-process-output proc
))
1442 (insert-before-markers
1443 (mapconcat 'identity
1445 (if octave-send-echo-input
(list line
) (list ""))
1446 (mapcar 'inferior-octave-strip-ctrl-g
1447 inferior-octave-output-list
)
1448 (list inferior-octave-output-string
))
1450 (if octave-send-show-buffer
1451 (display-buffer inferior-octave-buffer
)))
1453 (defun octave-send-block ()
1454 "Send current Octave block to the inferior Octave process."
1458 (octave-send-region (point) (mark))))
1460 (defun octave-send-defun ()
1461 "Send current Octave function to the inferior Octave process."
1465 (octave-send-region (point) (mark))))
1467 (defun octave-send-line (&optional arg
)
1468 "Send current Octave code line to the inferior Octave process.
1469 With positive prefix ARG, send that many lines.
1470 If `octave-send-line-auto-forward' is non-nil, go to the next unsent
1473 (or arg
(setq arg
1))
1478 (octave-next-code-line (- arg
1))
1481 (if octave-send-line-auto-forward
1482 (octave-next-code-line 1))
1483 (octave-send-region beg end
))))
1485 (defun octave-eval-print-last-sexp ()
1486 "Evaluate Octave sexp before point and print value into current buffer."
1489 (let ((standard-output (current-buffer))
1490 (print-escape-newlines nil
)
1496 (inferior-octave-send-list-and-digest
1497 (list (concat (buffer-substring-no-properties (point) opoint
)
1499 (mapconcat 'identity inferior-octave-output-list
"\n")))
1503 (defun octave-submit-bug-report ()
1504 "Submit a bug report on the Emacs Octave package via mail."
1508 (y-or-n-p "Do you want to submit a bug report? ")
1509 (reporter-submit-bug-report
1510 octave-maintainer-address
1511 (concat "Emacs version " emacs-version
)
1514 'octave-auto-newline
1515 'octave-blink-matching-block
1516 'octave-block-offset
1517 'octave-comment-char
1518 'octave-continuation-offset
1519 'octave-continuation-string
1520 'octave-send-echo-input
1521 'octave-send-line-auto-forward
1522 'octave-send-show-buffer
))))
1526 (provide 'octave-mod
)
1528 ;; arch-tag: 05f1ce09-be87-4c00-803e-4919ffa26c23
1529 ;;; octave-mod.el ends here