1 ;;; octave-mod.el --- editing Octave source files under Emacs
3 ;; Copyright (C) 1997 Free Software Foundation, Inc.
5 ;; Author: Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>
6 ;; Author: John Eaton <jwe@bevo.che.wisc.edu>
7 ;; Maintainer: Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
29 ;; This package provides Emacs support for Octave.
30 ;; It defines Octave mode, a major mode for editing
33 ;; The file octave-hlp.el provides `octave-help', a facility for looking up
34 ;; documentation on a symbol in the Octave info files.
36 ;; The file octave-inf.el contains code for interacting with an inferior
37 ;; Octave process using comint.
39 ;; See the documentation of `octave-mode', `octave-help' and
40 ;; `run-octave' for further information on usage and customization.
46 "Major mode for editing Octave source files."
49 (defvar inferior-octave-output-list nil
)
50 (defvar inferior-octave-output-string nil
)
51 (defvar inferior-octave-receive-in-progress nil
)
53 (defconst octave-maintainer-address
54 "Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>, bug-gnu-emacs@gnu.org"
55 "Current maintainer of the Emacs Octave package.")
57 (defvar octave-abbrev-table nil
58 "Abbrev table for Octave's reserved words.
59 Used in `octave-mode' and inferior-octave-mode buffers.
60 All Octave abbrevs start with a grave accent (`).")
61 (unless octave-abbrev-table
62 (let ((ac abbrevs-changed
))
63 (define-abbrev-table 'octave-abbrev-table
())
64 (define-abbrev octave-abbrev-table
"`a" "all_va_args" nil
0 t
)
65 (define-abbrev octave-abbrev-table
"`b" "break" nil
0 t
)
66 (define-abbrev octave-abbrev-table
"`cs" "case" nil
0 t
)
67 (define-abbrev octave-abbrev-table
"`ca" "catch" nil
0 t
)
68 (define-abbrev octave-abbrev-table
"`c" "continue" nil
0 t
)
69 (define-abbrev octave-abbrev-table
"`el" "else" nil
0 t
)
70 (define-abbrev octave-abbrev-table
"`eli" "elseif" nil
0 t
)
71 (define-abbrev octave-abbrev-table
"`et" "end_try_catch" nil
0 t
)
72 (define-abbrev octave-abbrev-table
"`eu" "end_unwind_protect" nil
0 t
)
73 (define-abbrev octave-abbrev-table
"`ef" "endfor" nil
0 t
)
74 (define-abbrev octave-abbrev-table
"`efu" "endfunction" nil
0 t
)
75 (define-abbrev octave-abbrev-table
"`ei" "endif" nil
0 t
)
76 (define-abbrev octave-abbrev-table
"`es" "endswitch" nil
0 t
)
77 (define-abbrev octave-abbrev-table
"`ew" "endwhile" nil
0 t
)
78 (define-abbrev octave-abbrev-table
"`f" "for" nil
0 t
)
79 (define-abbrev octave-abbrev-table
"`fu" "function" nil
0 t
)
80 (define-abbrev octave-abbrev-table
"`gl" "global" nil
0 t
)
81 (define-abbrev octave-abbrev-table
"`gp" "gplot" nil
0 t
)
82 (define-abbrev octave-abbrev-table
"`gs" "gsplot" nil
0 t
)
83 (define-abbrev octave-abbrev-table
"`if" "if ()" nil
0 t
)
84 (define-abbrev octave-abbrev-table
"`o" "otherwise" nil
0 t
)
85 (define-abbrev octave-abbrev-table
"`rp" "replot" nil
0 t
)
86 (define-abbrev octave-abbrev-table
"`r" "return" nil
0 t
)
87 (define-abbrev octave-abbrev-table
"`s" "switch" nil
0 t
)
88 (define-abbrev octave-abbrev-table
"`t" "try" nil
0 t
)
89 (define-abbrev octave-abbrev-table
"`up" "unwind_protect" nil
0 t
)
90 (define-abbrev octave-abbrev-table
"`upc" "unwind_protect_cleanup" nil
0 t
)
91 (define-abbrev octave-abbrev-table
"`w" "while ()" nil
0 t
)
92 (setq abbrevs-changed ac
)))
94 (defvar octave-comment-char ?
#
95 "Character to start an Octave comment.")
96 (defvar octave-comment-start
97 (concat (make-string 1 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 '("for" "function" "if" "switch" "try" "unwind_protect" "while"))
104 (defvar octave-else-keywords
105 '("case" "catch" "else" "elseif" "otherwise" "unwind_protect_cleanup"))
106 (defvar octave-end-keywords
107 '("end" "endfor" "endfunction" "endif" "endswitch" "end_try_catch"
108 "end_unwind_protect" "endwhile"))
110 (defvar octave-reserved-words
111 (append octave-begin-keywords
114 '("all_va_args" "break" "continue" "global" "gplot" "gsplot"
116 "Reserved words in Octave.")
118 (defvar octave-text-functions
119 '("casesen" "cd" "chdir" "clear" "diary" "dir" "document" "echo"
120 "edit_history" "format" "gset" "gshow" "help" "history" "hold"
121 "load" "ls" "more" "run_history" "save" "set" "show" "type"
122 "which" "who" "whos")
123 "Text functions in Octave (these names are also reserved).")
125 (defvar octave-variables
126 '("EDITOR" "EXEC_PATH" "F_DUPFD" "F_GETFD" "F_GETFL" "F_SETFD"
127 "F_SETFL" "I" "IMAGEPATH" "INFO_FILE" "INFO_PROGRAM" "Inf" "J"
128 "LOADPATH" "NaN" "OCTAVE_VERSION" "O_APPEND" "O_CREAT" "O_EXCL"
129 "O_NONBLOCK" "O_RDONLY" "O_RDWR" "O_TRUNC" "O_WRONLY" "PAGER" "PS1"
130 "PS2" "PS4" "PWD" "SEEK_CUR" "SEEK_END" "SEEK_SET" "__F_DUPFD__"
131 "__F_GETFD__" "__F_GETFL__" "__F_SETFD__" "__F_SETFL__" "__I__"
132 "__Inf__" "__J__" "__NaN__" "__OCTAVE_VERSION__" "__O_APPEND__"
133 "__O_CREAT__" "__O_EXCL__" "__O_NONBLOCK__" "__O_RDONLY__"
134 "__O_RDWR__" "__O_TRUNC__" "__O_WRONLY__" "__PWD__" "__SEEK_CUR__"
135 "__SEEK_END__" "__SEEK_SET__" "__argv__" "__e__" "__eps__"
136 "__error_text__" "__i__" "__inf__" "__j__" "__nan__" "__pi__"
137 "__program_invocation_name__" "__program_name__" "__realmax__"
138 "__realmin__" "__stderr__" "__stdin__" "__stdout__" "ans" "argv"
139 "automatic_replot" "beep_on_error" "completion_append_char"
140 "default_return_value" "default_save_format"
141 "define_all_return_values" "do_fortran_indexing" "e"
142 "echo_executing_commands" "empty_list_elements_ok" "eps"
143 "error_text" "gnuplot_binary" "gnuplot_has_multiplot" "history_file"
144 "history_size" "ignore_function_time_stamp" "implicit_str_to_num_ok"
145 "inf" "nan" "nargin" "ok_to_lose_imaginary_part"
146 "output_max_field_width" "output_precision"
147 "page_output_immediately" "page_screen_output" "pi"
148 "prefer_column_vectors" "prefer_zero_one_indexing"
149 "print_answer_id_name" "print_empty_dimensions"
150 "program_invocation_name" "program_name" "propagate_empty_matrices"
151 "realmax" "realmin" "resize_on_range_error"
152 "return_last_computed_value" "save_precision" "saving_history"
153 "silent_functions" "split_long_rows" "stderr" "stdin" "stdout"
154 "string_fill_char" "struct_levels_to_print"
155 "suppress_verbose_help_message" "treat_neg_dim_as_zero"
156 "warn_assign_as_truth_value" "warn_comma_in_global_decl"
157 "warn_divide_by_zero" "warn_function_name_clash"
158 "warn_missing_semicolon" "whitespace_in_literal_matrix")
159 "Builtin variables in Octave.")
161 (defvar octave-function-header-regexp
162 (concat "^\\s-*\\<\\(function\\)\\>"
163 "\\([^=;\n]*=[ \t]*\\|[ \t]*\\)\\(\\w+\\)\\>")
164 "Regexp to match an Octave function header.
165 The string `function' and its name are given by the first and third
166 parenthetical grouping.")
168 (defvar octave-font-lock-keywords
170 ;; Fontify all builtin keywords.
171 (cons (concat "\\<\\("
172 (mapconcat 'identity octave-reserved-words
"\\|")
173 (mapconcat 'identity octave-text-functions
"\\|")
175 'font-lock-keyword-face
)
176 ;; Fontify all builtin operators.
177 (cons "\\(&\\||\\|<=\\|>=\\|==\\|<\\|>\\|!=\\|!\\)"
178 (if (boundp 'font-lock-builtin-face
)
179 'font-lock-builtin-face
180 'font-lock-preprocessor-face
))
181 ;; Fontify all builtin variables.
182 (cons (concat "\\<\\("
183 (mapconcat 'identity octave-variables
"\\|")
185 'font-lock-variable-name-face
)
186 ;; Fontify all function declarations.
187 (list octave-function-header-regexp
188 '(1 font-lock-keyword-face
)
189 '(3 font-lock-function-name-face nil t
)))
190 "Additional Octave expressions to highlight.")
192 (defcustom inferior-octave-buffer
"*Inferior Octave*"
193 "*Name of buffer for running an inferior Octave process."
195 :group
'octave-inferior
)
197 (defvar inferior-octave-process nil
)
199 (defvar octave-mode-map nil
200 "Keymap used in Octave mode.")
203 (let ((map (make-sparse-keymap)))
204 (define-key map
"`" 'octave-abbrev-start
)
205 (define-key map
";" 'octave-electric-semi
)
206 (define-key map
" " 'octave-electric-space
)
207 (define-key map
"\n" 'octave-reindent-then-newline-and-indent
)
208 (define-key map
"\t" 'indent-according-to-mode
)
209 (define-key map
"\e;" 'octave-indent-for-comment
)
210 (define-key map
"\e\n" 'octave-indent-new-comment-line
)
211 (define-key map
"\e\t" 'octave-complete-symbol
)
212 (define-key map
"\M-\C-a" 'octave-beginning-of-defun
)
213 (define-key map
"\M-\C-e" 'octave-end-of-defun
)
214 (define-key map
"\M-\C-h" 'octave-mark-defun
)
215 (define-key map
"\M-\C-q" 'octave-indent-defun
)
216 (define-key map
"\C-c;" 'octave-comment-region
)
217 (define-key map
"\C-c:" 'octave-uncomment-region
)
218 (define-key map
"\C-c\C-b" 'octave-submit-bug-report
)
219 (define-key map
"\C-c\C-p" 'octave-previous-code-line
)
220 (define-key map
"\C-c\C-n" 'octave-next-code-line
)
221 (define-key map
"\C-c\C-a" 'octave-beginning-of-line
)
222 (define-key map
"\C-c\C-e" 'octave-end-of-line
)
223 (define-key map
"\C-c\M-\C-n" 'octave-forward-block
)
224 (define-key map
"\C-c\M-\C-p" 'octave-backward-block
)
225 (define-key map
"\C-c\M-\C-u" 'octave-backward-up-block
)
226 (define-key map
"\C-c\M-\C-d" 'octave-down-block
)
227 (define-key map
"\C-c\M-\C-h" 'octave-mark-block
)
228 (define-key map
"\C-c]" 'octave-close-block
)
229 (define-key map
"\C-cf" 'octave-insert-defun
)
230 (define-key map
"\C-c\C-h" 'octave-help
)
231 (define-key map
"\C-cil" 'octave-send-line
)
232 (define-key map
"\C-cib" 'octave-send-block
)
233 (define-key map
"\C-cif" 'octave-send-defun
)
234 (define-key map
"\C-cir" 'octave-send-region
)
235 (define-key map
"\C-cis" 'octave-show-process-buffer
)
236 (define-key map
"\C-cih" 'octave-hide-process-buffer
)
237 (define-key map
"\C-cik" 'octave-kill-process
)
238 (setq octave-mode-map map
)))
240 (defvar octave-mode-menu
243 ["Previous Code Line" octave-previous-code-line t
]
244 ["Next Code Line" octave-next-code-line t
]
245 ["Begin of Continuation" octave-beginning-of-line t
]
246 ["End of Continuation" octave-end-of-line t
]
247 ["Split Line at Point" octave-indent-new-comment-line t
])
249 ["Next Block" octave-forward-block t
]
250 ["Previous Block" octave-backward-block t
]
251 ["Down Block" octave-down-block t
]
252 ["Up Block" octave-backward-up-block t
]
253 ["Mark Block" octave-mark-block t
]
254 ["Close Block" octave-close-block t
])
256 ["Begin of Function" octave-beginning-of-defun
t]
257 ["End of Function" octave-end-of-defun
t]
258 ["Mark Function" octave-mark-defun
t]
259 ["Indent Function" octave-indent-defun
t]
260 ["Insert Function" octave-insert-defun
t])
263 ["Send Current Line" octave-send-line t
]
264 ["Send Current Block" octave-send-block t
]
265 ["Send Current Function" octave-send-defun
t]
266 ["Send Region" octave-send-region t
]
267 ["Show Process Buffer" octave-show-process-buffer t
]
268 ["Hide Process Buffer" octave-hide-process-buffer t
]
269 ["Kill Process" octave-kill-process t
])
271 ["Indent Line" indent-according-to-mode t
]
272 ["Complete Symbol" octave-complete-symbol t
]
274 ["Toggle Abbrev Mode" abbrev-mode t
]
275 ["Toggle Auto-Fill Mode" auto-fill-mode t
]
277 ["Submit Bug Report" octave-submit-bug-report t
]
279 ["Describe Octave Mode" octave-describe-major-mode t
]
280 ["Lookup Octave Index" octave-help t
])
281 "Menu for Octave mode.")
283 (defvar octave-mode-syntax-table nil
284 "Syntax table in use in octave-mode buffers.")
285 (if octave-mode-syntax-table
287 (let ((table (make-syntax-table)))
288 (modify-syntax-entry ?
\r " " 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 (modify-syntax-entry ?
\\ "\\" table
)
300 (modify-syntax-entry ?
\' "." table
)
301 (modify-syntax-entry ?\
` "w" table
)
302 (modify-syntax-entry ?
\" "\"" table
)
303 (modify-syntax-entry ?.
"w" table
)
304 (modify-syntax-entry ?_
"w" table
)
305 (modify-syntax-entry ?\%
"." table
)
306 (modify-syntax-entry ?\
# "<" table
)
307 (modify-syntax-entry ?
\n ">" table
)
308 (setq octave-mode-syntax-table table
)))
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 (defvar octave-block-match-alist
348 '(("for" .
("end" "endfor"))
349 ("function" .
("end" "endfunction"))
350 ("if" .
("else" "elseif" "end" "endif"))
351 ("switch" .
("case" "otherwise" "end" "endswitch"))
352 ("try" .
("catch" "end" "end_try_catch"))
353 ("unwind_protect" .
("unwind_protect_cleanup" "end"
354 "end_unwind_protect"))
355 ("while" .
("end" "endwhile")))
356 "Alist with Octave's matching block keywords.
357 Has Octave's begin keywords as keys and a list of the matching else or
358 end keywords as associated values.")
360 (defvar octave-block-comment-start
361 (concat (make-string 2 octave-comment-char
) " ")
362 "String to insert to start a new Octave comment on an empty line.")
364 (defcustom octave-continuation-offset
4
365 "*Extra indentation applied to Octave continuation lines."
368 (defvar octave-continuation-regexp
369 "[^#%\n]*\\(\\\\\\|\\.\\.\\.\\)\\s-*\\(\\s<.*\\)?$")
370 (defcustom octave-continuation-string
"\\"
371 "*Character string used for Octave continuation lines. Normally \\."
375 (defvar octave-completion-alist nil
376 "Alist of Octave symbols for completion in Octave mode.
377 Each element looks like (VAR . VAR), where the car and cdr are the same
378 symbol (an Octave command or variable name).
379 Currently, only builtin variables can be completed.")
381 (defvar octave-mode-imenu-generic-expression
384 (list nil octave-function-header-regexp
3))
385 "Imenu expression for Octave mode. See `imenu-generic-expression'.")
387 (defcustom octave-mode-startup-message t
388 "*nil means do not display the Octave mode startup message."
392 (defcustom octave-mode-hook nil
393 "*Hook to be run when Octave mode is started."
397 (defcustom octave-send-show-buffer t
398 "*Non-nil means display `inferior-octave-buffer' after sending to it."
401 (defcustom octave-send-line-auto-forward t
402 "*Control auto-forward after sending to the inferior Octave process.
403 Non-nil means always go to the next Octave code line after sending."
406 (defcustom octave-send-echo-input t
407 "*Non-nil means echo input sent to the inferior Octave process."
413 (defun octave-mode ()
414 "Major mode for editing Octave code.
416 This mode makes it easier to write Octave code by helping with
417 indentation, doing some of the typing for you (with Abbrev mode) and by
418 showing keywords, comments, strings, etc. in different faces (with
419 Font Lock mode on terminals that support it).
421 Octave itself is a high-level language, primarily intended for numerical
422 computations. It provides a convenient command line interface for
423 solving linear and nonlinear problems numerically. Function definitions
424 can also be stored in files, and it can be used in a batch mode (which
425 is why you need this mode!).
427 The latest released version of Octave is always available via anonymous
428 ftp from bevo.che.wisc.edu in the directory `/pub/octave'. Complete
429 source and binaries for several popular systems are available.
431 Type \\[list-abbrevs] to display the built-in abbrevs for Octave keywords.
438 Variables you can use to customize Octave mode
439 ==============================================
442 Non-nil means indent current line after a semicolon or space.
446 Non-nil means auto-insert a newline and indent after a semicolon.
449 octave-blink-matching-block
450 Non-nil means show matching begin of block when inserting a space,
451 newline or semicolon after an else or end keyword. Default is t.
454 Extra indentation applied to statements in block structures.
457 octave-continuation-offset
458 Extra indentation applied to Octave continuation lines.
461 octave-continuation-string
462 String used for Octave continuation lines.
463 Default is a backslash.
465 octave-mode-startup-message
466 nil means do not display the Octave mode startup message.
469 octave-send-echo-input
470 Non-nil means always display `inferior-octave-buffer' after sending a
471 command to the inferior Octave process.
473 octave-send-line-auto-forward
474 Non-nil means always go to the next unsent line of Octave code after
475 sending a line to the inferior Octave process.
477 octave-send-echo-input
478 Non-nil means echo input sent to the inferior Octave process.
480 Turning on Octave mode runs the hook `octave-mode-hook'.
482 To begin using this mode for all `.m' files that you edit, add the
483 following lines to your `.emacs' file:
485 (autoload 'octave-mode \"octave-mod\" nil t)
486 (setq auto-mode-alist
487 (cons '(\"\\\\.m$\" . octave-mode) auto-mode-alist))
489 To automatically turn on the abbrev, auto-fill and font-lock features,
490 add the following lines to your `.emacs' file as well:
492 (add-hook 'octave-mode-hook
496 (if (eq window-system 'x)
497 (font-lock-mode 1))))
499 To submit a problem report, enter \\[octave-submit-bug-report] from \
500 an Octave mode buffer.
501 This automatically sets up a mail buffer with version information
502 already added. You just need to add a description of the problem,
503 including a reproducible test case and send the message."
505 (kill-all-local-variables)
507 (use-local-map octave-mode-map
)
508 (setq major-mode
'octave-mode
)
509 (setq mode-name
"Octave")
510 (setq local-abbrev-table octave-abbrev-table
)
511 (set-syntax-table octave-mode-syntax-table
)
513 (make-local-variable 'indent-line-function
)
514 (setq indent-line-function
'octave-indent-line
)
516 (make-local-variable 'comment-start
)
517 (setq comment-start octave-comment-start
)
518 (make-local-variable 'comment-end
)
519 (setq comment-end
"")
520 (make-local-variable 'comment-column
)
521 (setq comment-column
32)
522 (make-local-variable 'comment-start-skip
)
523 (setq comment-start-skip
"\\s<+\\s-*")
524 (make-local-variable 'comment-indent-function
)
525 (setq comment-indent-function
'octave-comment-indent
)
527 (make-local-variable 'parse-sexp-ignore-comments
)
528 (setq parse-sexp-ignore-comments t
)
529 (make-local-variable 'paragraph-start
)
530 (setq paragraph-start
(concat "\\s-*$\\|" page-delimiter
))
531 (make-local-variable 'paragraph-separate
)
532 (setq paragraph-separate paragraph-start
)
533 (make-local-variable 'paragraph-ignore-fill-prefix
)
534 (setq paragraph-ignore-fill-prefix t
)
535 (make-local-variable 'fill-paragraph-function
)
536 (setq fill-paragraph-function
'octave-fill-paragraph
)
537 (make-local-variable 'adaptive-fill-regexp
)
538 (setq adaptive-fill-regexp nil
)
539 (make-local-variable 'fill-column
)
540 (setq fill-column
72)
541 (make-local-variable 'normal-auto-fill-function
)
542 (setq normal-auto-fill-function
'octave-auto-fill
)
544 (make-local-variable 'font-lock-defaults
)
545 (setq font-lock-defaults
'(octave-font-lock-keywords nil nil
))
547 (make-local-variable 'imenu-generic-expression
)
548 (setq imenu-generic-expression octave-mode-imenu-generic-expression
549 imenu-case-fold-search nil
)
551 (octave-add-octave-menu)
552 (octave-initialize-completions)
553 (run-hooks 'octave-mode-hook
))
555 ;;; Miscellaneous useful functions
556 (defun octave-describe-major-mode ()
557 "Describe the current major mode."
559 (describe-function major-mode
))
561 (defun octave-point (position)
562 "Returns the value of point at certain positions."
565 ((eq position
'bol
) (beginning-of-line))
566 ((eq position
'eol
) (end-of-line))
567 ((eq position
'boi
) (back-to-indentation))
568 ((eq position
'bonl
) (forward-line 1))
569 ((eq position
'bopl
) (forward-line -
1))
570 (t (error "unknown buffer position requested: %s" position
)))
573 (defsubst octave-in-comment-p
()
574 "Returns t if point is inside an Octave comment, nil otherwise."
577 (nth 4 (parse-partial-sexp (octave-point 'bol
) (point)))))
579 (defsubst octave-in-string-p
()
580 "Returns t if point is inside an Octave string, nil otherwise."
583 (nth 3 (parse-partial-sexp (octave-point 'bol
) (point)))))
585 (defsubst octave-not-in-string-or-comment-p
()
586 "Returns t iff point is not inside an Octave string or comment."
587 (let ((pps (parse-partial-sexp (octave-point 'bol
) (point))))
588 (not (or (nth 3 pps
) (nth 4 pps
)))))
590 (defun octave-in-block-p ()
591 "Returns t if point is inside an Octave block, nil otherwise.
592 The block is taken to start at the first letter of the begin keyword and
593 to end after the end keyword."
598 (skip-syntax-forward "w")
600 (octave-forward-block)
605 (defun octave-in-defun-p ()
606 "Returns t iff point is inside an Octave function declaration.
607 The function is taken to start at the `f' of `function' and to end after
611 (or (and (looking-at "\\<function\\>")
612 (octave-not-in-string-or-comment-p))
613 (and (octave-beginning-of-defun)
616 (octave-forward-block)
621 (defun octave-maybe-insert-continuation-string ()
622 (if (or (octave-in-comment-p)
625 (looking-at octave-continuation-regexp
)))
627 (delete-horizontal-space)
628 (insert (concat " " octave-continuation-string
))))
630 (defvar octave-xemacs-p
631 (string-match "XEmacs\\|Lucid" emacs-version
))
634 (defun octave-comment-region (beg end
&optional arg
)
635 "Comment or uncomment each line in the region as Octave code.
636 See `comment-region'."
638 (let ((comment-start (char-to-string octave-comment-char
)))
639 (comment-region beg end arg
)))
641 (defun octave-uncomment-region (beg end
&optional arg
)
642 "Uncomment each line in the region as Octave code."
644 (or arg
(setq arg
1))
645 (octave-comment-region beg end
(- arg
)))
649 (defun calculate-octave-indent ()
650 "Return appropriate indentation for current line as Octave code.
651 Returns an integer (the column to indent to) unless the line is a
652 comment line with fixed goal golumn. In that case, returns a list whose
653 car is the column to indent to, and whose cdr is the current indentation
655 (let ((is-continuation-line
657 (if (zerop (octave-previous-code-line))
658 (looking-at octave-continuation-regexp
))))
662 ;; If we can move backward out one level of parentheses, take 1
663 ;; plus the indentation of that parenthesis. Otherwise, go back
664 ;; to the beginning of the previous code line, and compute the
665 ;; offset this line gives.
666 (if (condition-case nil
671 (setq icol
(+ 1 (current-column)))
672 (if (zerop (octave-previous-code-line))
674 (octave-beginning-of-line)
675 (back-to-indentation)
676 (setq icol
(current-column))
678 (eol (octave-point 'eol
)))
679 (while (< (point) eol
)
680 (if (octave-not-in-string-or-comment-p)
682 ((looking-at "\\<switch\\>")
683 (setq icol
(+ icol
(* 2 octave-block-offset
))))
684 ((looking-at octave-block-begin-regexp
)
685 (setq icol
(+ icol octave-block-offset
)))
686 ((looking-at octave-block-else-regexp
)
688 (setq icol
(+ icol octave-block-offset
))))
689 ((looking-at octave-block-end-regexp
)
690 (if (not (= bot
(point)))
692 (octave-block-end-offset)))))))
694 (if is-continuation-line
695 (setq icol
(+ icol octave-continuation-offset
)))))))
697 (back-to-indentation)
699 ((and (looking-at octave-block-else-regexp
)
700 (octave-not-in-string-or-comment-p))
701 (setq icol
(- icol octave-block-offset
)))
702 ((and (looking-at octave-block-end-regexp
)
703 (octave-not-in-string-or-comment-p))
704 (setq icol
(- icol
(octave-block-end-offset))))
705 ((or (looking-at "\\s<\\s<\\s<\\S<")
706 (octave-before-magic-comment-p))
707 (setq icol
(list 0 icol
)))
708 ((looking-at "\\s<\\S<")
709 (setq icol
(list comment-column icol
)))))
712 (defun octave-block-end-offset ()
714 (octave-backward-up-block 1)
715 (* octave-block-offset
716 (if (string-match (match-string 0) "switch") 2 1))))
718 (defun octave-before-magic-comment-p ()
721 (and (bobp) (looking-at "\\s-*#!"))))
723 (defun octave-comment-indent ()
724 (if (or (looking-at "\\s<\\s<\\s<")
725 (octave-before-magic-comment-p))
727 (if (looking-at "\\s<\\s<")
728 (calculate-octave-indent)
729 (skip-syntax-backward " ")
730 (max (if (bolp) 0 (+ 1 (current-column)))
733 (defun octave-indent-for-comment ()
734 "Maybe insert and indent an Octave comment.
735 If there is no comment already on this line, create a code-level comment
736 \(started by two comment characters) if the line is empty, or an in-line
737 comment (started by one comment character) otherwise.
738 Point is left after the start of the comment which is properly aligned."
741 (indent-according-to-mode))
743 (defun octave-indent-line (&optional arg
)
744 "Indent current line as Octave code.
745 With optional ARG, use this as offset unless this line is a comment with
748 (or arg
(setq arg
0))
749 (let ((icol (calculate-octave-indent))
750 (relpos (- (current-column) (current-indentation))))
752 (setq icol
(car icol
))
753 (setq icol
(+ icol arg
)))
755 (error "Unmatched end keyword")
756 (indent-line-to icol
)
758 (move-to-column (+ icol relpos
))))))
760 (defun octave-indent-new-comment-line ()
761 "Break Octave line at point, continuing comment if within one.
762 If within code, insert `octave-continuation-string' before breaking the
763 line. If within a string, signal an error.
764 The new line is properly indented."
766 (delete-horizontal-space)
768 ((octave-in-comment-p)
769 (indent-new-comment-line))
770 ((octave-in-string-p)
771 (error "Cannot split a code line inside a string"))
773 (insert (concat " " octave-continuation-string
))
774 (octave-reindent-then-newline-and-indent))))
776 (defun octave-indent-defun ()
777 "Properly indents the Octave function which contains point."
781 (message "Indenting function...")
782 (indent-region (point) (mark) nil
))
783 (message "Indenting function...done."))
787 (defun octave-next-code-line (&optional arg
)
788 "Move ARG lines of Octave code forward (backward 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))
796 (inc (if (> arg
0) 1 -
1)))
797 (while (and (/= arg
0) (= n
0))
798 (setq n
(forward-line inc
))
800 (looking-at "\\s-*\\($\\|\\s<\\)"))
801 (setq n
(forward-line inc
)))
802 (setq arg
(- arg inc
)))
805 (defun octave-previous-code-line (&optional arg
)
806 "Move ARG lines of Octave code backward (forward if ARG is negative).
807 Skips past all empty and comment lines. Default for ARG is 1.
809 On success, return 0. Otherwise, go as far as possible and return -1."
811 (or arg
(setq arg
1))
812 (octave-next-code-line (- arg
)))
814 (defun octave-beginning-of-line ()
815 "Move point to beginning of current Octave line.
816 If on an empty or comment line, go to the beginning of that line.
817 Otherwise, move backward to the beginning of the first Octave code line
818 which is not inside a continuation statement, i.e., which does not
819 follow a code line ending in `...' or `\\', or is inside an open
823 (if (not (looking-at "\\s-*\\($\\|\\s<\\)"))
824 (while (or (condition-case nil
830 (and (or (looking-at "\\s-*\\($\\|\\s<\\)")
832 (if (zerop (octave-previous-code-line))
833 (looking-at octave-continuation-regexp
))))
834 (zerop (forward-line -
1)))))))
836 (defun octave-end-of-line ()
837 "Move point to end of current Octave line.
838 If on an empty or comment line, go to the end of that line.
839 Otherwise, move forward to the end of the first Octave code line which
840 does not end in `...' or `\\' or is inside an open parenthesis list."
845 (looking-at "\\s-*\\($\\|\\s<\\)"))
847 (while (or (condition-case nil
855 (or (looking-at "\\s-*\\($\\|\\s<\\)")
856 (looking-at octave-continuation-regexp
)))
857 (zerop (forward-line 1)))))
860 (defun octave-scan-blocks (from count depth
)
861 "Scan from character number FROM by COUNT Octave begin-end blocks.
862 Returns the character number of the position thus found.
864 If DEPTH is nonzero, block depth begins counting from that value.
865 Only places where the depth in blocks becomes zero are candidates for
866 stopping; COUNT such places are counted.
868 If the beginning or end of the buffer is reached and the depth is wrong,
869 an error is signaled."
870 (let ((min-depth (if (> depth
0) 0 depth
))
871 (inc (if (> count
0) 1 -
1)))
875 (while (or (re-search-forward
876 octave-block-begin-or-end-regexp nil
'move inc
)
878 (error "Unbalanced block")))
879 (if (octave-not-in-string-or-comment-p)
883 (setq depth
(+ depth inc
)))
885 (setq depth
(- depth inc
))))
886 (if (< depth min-depth
)
887 (error "Containing expression ends prematurely"))
889 (throw 'foo nil
))))))
890 (setq count
(- count inc
)))
893 (defun octave-forward-block (&optional arg
)
894 "Move forward across one balanced Octave begin-end block.
895 With argument, do it that many times.
896 Negative arg -N means move backward across N blocks."
898 (or arg
(setq arg
1))
899 (goto-char (or (octave-scan-blocks (point) arg
0) (buffer-end arg
))))
901 (defun octave-backward-block (&optional arg
)
902 "Move backward across one balanced Octave begin-end block.
903 With argument, do it that many times.
904 Negative arg -N means move forward across N blocks."
906 (or arg
(setq arg
1))
907 (octave-forward-block (- arg
)))
909 (defun octave-down-block (arg)
910 "Move forward down one begin-end block level of Octave code.
911 With argument, do this that many times.
912 A negative argument means move backward but still go down a level.
913 In Lisp programs, an argument is required."
915 (let ((inc (if (> arg
0) 1 -
1)))
917 (goto-char (or (octave-scan-blocks (point) inc -
1)
919 (setq arg
(- arg inc
)))))
921 (defun octave-backward-up-block (arg)
922 "Move backward out of one begin-end block level of Octave code.
923 With argument, do this that many times.
924 A negative argument means move forward but still to a less deep spot.
925 In Lisp programs, an argument is required."
927 (octave-up-block (- arg
)))
929 (defun octave-up-block (arg)
930 "Move forward out of one begin-end block level of Octave code.
931 With argument, do this that many times.
932 A negative argument means move backward but still to a less deep spot.
933 In Lisp programs, an argument is required."
935 (let ((inc (if (> arg
0) 1 -
1)))
937 (goto-char (or (octave-scan-blocks (point) inc
1)
939 (setq arg
(- arg inc
)))))
941 (defun octave-mark-block ()
942 "Put point at the beginning of this Octave block, mark at the end.
943 The block marked is the one that contains point or follows point."
946 (if (or (and (octave-in-block-p)
947 (skip-syntax-forward "w"))
950 (octave-down-block 1)
956 (octave-forward-block)
957 (exchange-point-and-mark))
959 (message "No block to mark found"))))
961 (defun octave-close-block ()
962 "Close the current Octave block on a separate line.
963 An error is signaled if no block to close is found."
969 (octave-backward-up-block 1)
970 (setq bb-keyword
(buffer-substring-no-properties
971 (match-beginning 1) (match-end 1))))
974 (looking-at "^\\s-*$"))
975 (indent-according-to-mode)
976 (octave-reindent-then-newline-and-indent))
977 (insert (car (reverse
979 octave-block-match-alist
))))
980 (octave-reindent-then-newline-and-indent)
982 (error (message "No block to close found")))))
984 (defun octave-blink-matching-block-open ()
985 "Blink the matching Octave begin block keyword.
986 If point is right after an Octave else or end type block keyword, move
987 cursor momentarily to the corresponding begin keyword.
988 Signal an error if the keywords are incompatible."
990 (let (bb-keyword bb-arg eb-keyword pos eol
)
991 (if (and (octave-not-in-string-or-comment-p)
994 (skip-syntax-backward "w")
995 (looking-at octave-block-else-or-end-regexp
)))
1000 (buffer-substring-no-properties
1001 (match-beginning 1) (match-end 1)))
1002 (octave-backward-up-block 1))
1005 (buffer-substring-no-properties
1006 (match-beginning 2) (match-end 2)))
1007 (octave-backward-block)))
1008 (setq pos
(match-end 0)
1010 (buffer-substring-no-properties
1011 (match-beginning 0) pos
)
1013 eol
(octave-point 'eol
)
1018 (while (and (skip-syntax-forward "^<" eol
)
1019 (octave-in-string-p)
1020 (not (forward-char 1))))
1021 (skip-syntax-backward " ")
1022 (buffer-substring-no-properties pos
(point)))))
1023 (if (member eb-keyword
1024 (cdr (assoc bb-keyword octave-block-match-alist
)))
1026 (message "Matches `%s %s'" bb-keyword bb-arg
)
1027 (if (pos-visible-in-window-p)
1028 (sit-for blink-matching-delay
)))
1029 (error "Block keywords `%s' and `%s' do not match"
1030 bb-keyword eb-keyword
))))))
1032 (defun octave-beginning-of-defun (&optional arg
)
1033 "Move backward to the beginning of an Octave function.
1034 With positive ARG, do it that many times. Negative argument -N means
1035 move forward to Nth following beginning of a function.
1036 Returns t unless search stops at the beginning or end of the buffer."
1038 (let* ((arg (or arg
1))
1039 (inc (if (> arg
0) 1 -
1))
1042 (not (and (> arg
0) (looking-at "\\<function\\>")))
1043 (skip-syntax-forward "w"))
1044 (while (and (/= arg
0)
1046 (re-search-backward "\\<function\\>" nil
'move inc
)))
1047 (if (octave-not-in-string-or-comment-p)
1048 (setq arg
(- arg inc
))))
1051 (and (< inc
0) (goto-char (match-beginning 0)))
1054 (defun octave-end-of-defun (&optional arg
)
1055 "Move forward to the end of an Octave function.
1056 With positive ARG, do it that many times. Negative argument -N means
1057 move back to Nth preceding end of a function.
1059 An end of a function occurs right after the end keyword matching the
1060 `function' keyword that starts the function."
1062 (or arg
(setq arg
1))
1063 (and (< arg
0) (skip-syntax-backward "w"))
1064 (and (> arg
0) (skip-syntax-forward "w"))
1065 (if (octave-in-defun-p)
1066 (setq arg
(- arg
1)))
1067 (if (= arg
0) (setq arg -
1))
1068 (if (octave-beginning-of-defun (- arg
))
1069 (octave-forward-block)))
1071 (defun octave-mark-defun ()
1072 "Put point at the beginning of this Octave function, mark at its end.
1073 The function marked is the one containing point or following point."
1075 (let ((pos (point)))
1076 (if (or (octave-in-defun-p)
1077 (and (octave-beginning-of-defun -1)
1078 (octave-in-defun-p)))
1080 (skip-syntax-forward "w")
1081 (octave-beginning-of-defun)
1083 (octave-end-of-defun)
1084 (exchange-point-and-mark))
1086 (message "No function to mark found"))))
1090 (defun octave-auto-fill ()
1091 "Perform auto-fill in Octave mode.
1092 Returns nil if no feasible place to break the line could be found, and t
1095 (if (or (null (setq fc
(current-fill-column)))
1098 (and auto-fill-inhibit-regexp
1099 (looking-at auto-fill-inhibit-regexp
))))
1100 nil
; Can't do anything
1101 (if (and (not (octave-in-comment-p))
1102 (> (current-column) fc
))
1103 (setq fc
(- fc
(+ (length octave-continuation-string
) 1))))
1104 (while (and (not give-up
) (> (current-column) fc
))
1105 (let* ((opoint (point))
1108 (move-to-column (+ fc
1))
1109 (skip-chars-backward "^ \t\n")
1110 ;; If we're at the beginning of the line, break after
1113 (re-search-forward "[ \t]" opoint t
))
1114 ;; If we're in a comment line, don't break after the
1117 (skip-syntax-backward " <")
1119 (re-search-forward "[ \t]" (octave-point 'eol
)
1121 ;; If we're not in a comment line and just ahead the
1122 ;; continuation string, don't break here.
1123 (if (and (not (octave-in-comment-p))
1127 octave-continuation-string
)
1130 (skip-chars-backward " \t")
1134 (not (or (bolp) (eolp))))
1135 (let ((prev-column (current-column)))
1137 (skip-chars-backward " \t")
1140 (octave-maybe-insert-continuation-string)
1141 (indent-new-comment-line t
))
1144 (octave-maybe-insert-continuation-string)
1145 (indent-new-comment-line t
)))
1146 (if (>= (current-column) prev-column
)
1151 (defun octave-fill-paragraph (&optional arg
)
1152 "Fill paragraph of Octave code, handling Octave comments."
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 an 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
))
1262 (message "Hit space to flush")
1265 (set-buffer (get-buffer "*Completions*"))
1266 (setq key
(read-key-sequence nil
)
1268 (and (consp first
) (consp (event-start first
))
1269 (eq (window-buffer (posn-window (event-start
1271 (get-buffer "*Completions*"))
1272 (eq (key-binding key
) 'mouse-choose-completion
)))
1274 (mouse-choose-completion first
)
1275 (set-window-configuration conf
))
1277 (set-window-configuration conf
)
1278 (setq unread-command-events
1279 (listify-key-sequence key
))))))))))
1282 ;;; Electric characters && friends
1283 (defun octave-reindent-then-newline-and-indent ()
1284 "Reindent current Octave line, insert newline, and indent the new line.
1285 If Abbrev mode is on, expand abbrevs first."
1287 (if abbrev-mode
(expand-abbrev))
1288 (if octave-blink-matching-block
1289 (octave-blink-matching-block-open))
1291 (delete-region (point) (progn (skip-chars-backward " \t") (point)))
1292 (indent-according-to-mode))
1294 (indent-according-to-mode))
1296 (defun octave-electric-semi ()
1297 "Insert a semicolon in Octave mode.
1298 Maybe expand abbrevs and blink matching block open keywords.
1299 Reindent the line of `octave-auto-indent' is non-nil.
1300 Insert a newline if `octave-auto-newline' is non-nil."
1302 (if (not (octave-not-in-string-or-comment-p))
1304 (if abbrev-mode
(expand-abbrev))
1305 (if octave-blink-matching-block
1306 (octave-blink-matching-block-open))
1307 (if octave-auto-indent
1308 (indent-according-to-mode))
1310 (if octave-auto-newline
1311 (newline-and-indent))))
1313 (defun octave-electric-space ()
1314 "Insert a space in Octave mode.
1315 Maybe expand abbrevs and blink matching block open keywords.
1316 Reindent the line of `octave-auto-indent' is non-nil."
1318 (setq last-command-char ?
)
1319 (if (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 octave-xemacs-p
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 "Adds 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
))
1432 (set-buffer inferior-octave-buffer
)
1433 (setq inferior-octave-output-list nil
)
1434 (while (not (string-equal string
""))
1435 (if (string-match "\n" string
)
1436 (setq line
(substring string
0 (match-beginning 0))
1437 string
(substring string
(match-end 0)))
1438 (setq line string string
""))
1439 (setq inferior-octave-receive-in-progress t
)
1440 (inferior-octave-send-list-and-digest (list (concat line
"\n")))
1441 (while inferior-octave-receive-in-progress
1442 (accept-process-output proc
))
1443 (insert-before-markers
1444 (mapconcat 'identity
1446 (if octave-send-echo-input
(list line
) (list ""))
1447 (mapcar 'inferior-octave-strip-ctrl-g
1448 inferior-octave-output-list
)
1449 (list inferior-octave-output-string
))
1451 (if octave-send-show-buffer
1452 (display-buffer inferior-octave-buffer
)))
1454 (defun octave-send-block ()
1455 "Send current Octave block to the inferior Octave process."
1459 (octave-send-region (point) (mark))))
1461 (defun octave-send-defun ()
1462 "Send current Octave function to the inferior Octave process."
1466 (octave-send-region (point) (mark))))
1468 (defun octave-send-line (&optional arg
)
1469 "Send current Octave code line to the inferior Octave process.
1470 With positive prefix ARG, send that many lines.
1471 If `octave-send-line-auto-forward' is non-nil, go to the next unsent
1474 (or arg
(setq arg
1))
1479 (octave-next-code-line (- arg
1))
1482 (if octave-send-line-auto-forward
1483 (octave-next-code-line 1))
1484 (octave-send-region beg end
))))
1486 (defun octave-eval-print-last-sexp ()
1487 "Evaluate Octave sexp before point and print value into current buffer."
1490 (let ((standard-output (current-buffer))
1491 (print-escape-newlines nil
)
1497 (inferior-octave-send-list-and-digest
1498 (list (concat (buffer-substring-no-properties (point) opoint
)
1500 (mapconcat 'identity inferior-octave-output-list
"\n")))
1504 (defun octave-submit-bug-report ()
1505 "Submit a bug report on the Emacs Octave package via mail."
1509 (y-or-n-p "Do you want to submit a bug report? ")
1510 (reporter-submit-bug-report
1511 octave-maintainer-address
1512 (concat "Emacs version " emacs-version
)
1515 'octave-auto-newline
1516 'octave-blink-matching-block
1517 'octave-block-offset
1518 'octave-comment-char
1519 'octave-continuation-offset
1520 'octave-continuation-string
1522 'octave-mode-startup-message
1523 'octave-send-echo-input
1524 'octave-send-line-auto-forward
1525 'octave-send-show-buffer
))))
1529 (provide 'octave-mod
)
1531 ;;; octave-mod.el ends here