3093
|
1 ;;; octave-mod.el --- editing Octave source files under Emacs |
2617
|
2 |
3093
|
3 ;; Copyright (C) 1997 Free Software Foundation, Inc. |
2617
|
4 |
|
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> |
|
8 ;; Keywords: languages |
|
9 |
|
10 ;; This file is part of GNU Emacs. |
|
11 |
|
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) |
|
15 ;; any later version. |
|
16 |
|
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. |
|
21 |
|
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. |
|
26 |
|
27 ;;; Commentary: |
|
28 |
|
29 ;; This package provides Emacs support for Octave. |
|
30 ;; It defines Octave mode, a major mode for editing |
|
31 ;; Octave code. |
|
32 |
|
33 ;; The file octave-hlp.el provides `octave-help', a facility for looking up |
|
34 ;; documentation on a symbol in the Octave info files. |
|
35 |
|
36 ;; The file octave-inf.el contains code for interacting with an inferior |
|
37 ;; Octave process using comint. |
|
38 |
|
39 ;; See the documentation of `octave-mode', `octave-help' and |
|
40 ;; `run-octave' for further information on usage and customization. |
|
41 |
|
42 ;;; Code: |
3323
|
43 (require 'custom) |
2617
|
44 |
3270
|
45 (defgroup octave nil |
|
46 "Major mode for editing Octave source files." |
|
47 :group 'languages) |
|
48 |
3093
|
49 (defvar inferior-octave-output-list nil) |
|
50 (defvar inferior-octave-output-string nil) |
|
51 (defvar inferior-octave-receive-in-progress nil) |
|
52 |
2617
|
53 (defconst octave-maintainer-address |
3270
|
54 "Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>, bug-gnu-emacs@gnu.org" |
2617
|
55 "Current maintainer of the Emacs Octave package.") |
|
56 |
|
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 (if octave-abbrev-table |
|
62 () |
|
63 (let ((ac abbrevs-changed)) |
|
64 (define-abbrev-table 'octave-abbrev-table ()) |
|
65 (define-abbrev octave-abbrev-table "`a" "all_va_args" nil) |
|
66 (define-abbrev octave-abbrev-table "`b" "break" nil) |
2775
|
67 (define-abbrev octave-abbrev-table "`cs" "case" nil) |
2617
|
68 (define-abbrev octave-abbrev-table "`ca" "catch" nil) |
|
69 (define-abbrev octave-abbrev-table "`c" "continue" nil) |
|
70 (define-abbrev octave-abbrev-table "`el" "else" nil) |
|
71 (define-abbrev octave-abbrev-table "`eli" "elseif" nil) |
|
72 (define-abbrev octave-abbrev-table "`et" "end_try_catch" nil) |
|
73 (define-abbrev octave-abbrev-table "`eu" "end_unwind_protect" nil) |
|
74 (define-abbrev octave-abbrev-table "`ef" "endfor" nil) |
|
75 (define-abbrev octave-abbrev-table "`efu" "endfunction" nil) |
|
76 (define-abbrev octave-abbrev-table "`ei" "endif" nil) |
2775
|
77 (define-abbrev octave-abbrev-table "`es" "endswitch" nil) |
2617
|
78 (define-abbrev octave-abbrev-table "`ew" "endwhile" nil) |
|
79 (define-abbrev octave-abbrev-table "`f" "for" nil) |
|
80 (define-abbrev octave-abbrev-table "`fu" "function" nil) |
|
81 (define-abbrev octave-abbrev-table "`gl" "global" nil) |
|
82 (define-abbrev octave-abbrev-table "`gp" "gplot" nil) |
|
83 (define-abbrev octave-abbrev-table "`gs" "gsplot" nil) |
|
84 (define-abbrev octave-abbrev-table "`if" "if ()" nil) |
2775
|
85 (define-abbrev octave-abbrev-table "`o" "otherwise" nil) |
2617
|
86 (define-abbrev octave-abbrev-table "`rp" "replot" nil) |
|
87 (define-abbrev octave-abbrev-table "`r" "return" nil) |
2775
|
88 (define-abbrev octave-abbrev-table "`s" "switch" nil) |
2617
|
89 (define-abbrev octave-abbrev-table "`t" "try" nil) |
3485
|
90 (define-abbrev octave-abbrev-table "`u" "until ()" nil) |
2617
|
91 (define-abbrev octave-abbrev-table "`up" "unwind_protect" nil) |
|
92 (define-abbrev octave-abbrev-table "`upc" "unwind_protect_cleanup" nil) |
|
93 (define-abbrev octave-abbrev-table "`w" "while ()" nil) |
|
94 (setq abbrevs-changed ac))) |
|
95 |
|
96 (defvar octave-comment-char ?# |
|
97 "Character to start an Octave comment.") |
|
98 (defvar octave-comment-start |
|
99 (concat (make-string 1 octave-comment-char) " ") |
|
100 "String to insert to start a new Octave in-line comment.") |
|
101 (defvar octave-comment-start-skip "\\s<+\\s-*" |
|
102 "Regexp to match the start of an Octave comment up to its body.") |
|
103 |
|
104 (defvar octave-begin-keywords |
3485
|
105 '("do" "for" "function" "if" "switch" "try" "unwind_protect" "while")) |
2617
|
106 (defvar octave-else-keywords |
2775
|
107 '("case" "catch" "else" "elseif" "otherwise" "unwind_protect_cleanup")) |
2617
|
108 (defvar octave-end-keywords |
2775
|
109 '("end" "endfor" "endfunction" "endif" "endswitch" "end_try_catch" |
3485
|
110 "end_unwind_protect" "endwhile" "until")) |
2617
|
111 |
|
112 (defvar octave-reserved-words |
2788
|
113 (append octave-begin-keywords |
|
114 octave-else-keywords |
|
115 octave-end-keywords |
2617
|
116 '("all_va_args" "break" "continue" "global" "gplot" "gsplot" |
|
117 "replot" "return")) |
|
118 "Reserved words in Octave.") |
|
119 |
|
120 (defvar octave-text-functions |
|
121 '("casesen" "cd" "chdir" "clear" "diary" "dir" "document" "echo" |
|
122 "edit_history" "format" "gset" "gshow" "help" "history" "hold" |
|
123 "load" "ls" "more" "run_history" "save" "set" "show" "type" |
|
124 "which" "who" "whos") |
|
125 "Text functions in Octave (these names are also reserved).") |
|
126 |
|
127 (defvar octave-variables |
4451
|
128 '("DEFAULT_EXEC_PATH" "DEFAULT_LOADPATH" |
|
129 "EDITOR" "EXEC_PATH" "F_DUPFD" "F_GETFD" "F_GETFL" "F_SETFD" |
2617
|
130 "F_SETFL" "I" "IMAGEPATH" "INFO_FILE" "INFO_PROGRAM" "Inf" "J" |
|
131 "LOADPATH" "NaN" "OCTAVE_VERSION" "O_APPEND" "O_CREAT" "O_EXCL" |
|
132 "O_NONBLOCK" "O_RDONLY" "O_RDWR" "O_TRUNC" "O_WRONLY" "PAGER" "PS1" |
|
133 "PS2" "PS4" "PWD" "SEEK_CUR" "SEEK_END" "SEEK_SET" "__F_DUPFD__" |
|
134 "__F_GETFD__" "__F_GETFL__" "__F_SETFD__" "__F_SETFL__" "__I__" |
|
135 "__Inf__" "__J__" "__NaN__" "__OCTAVE_VERSION__" "__O_APPEND__" |
|
136 "__O_CREAT__" "__O_EXCL__" "__O_NONBLOCK__" "__O_RDONLY__" |
|
137 "__O_RDWR__" "__O_TRUNC__" "__O_WRONLY__" "__PWD__" "__SEEK_CUR__" |
|
138 "__SEEK_END__" "__SEEK_SET__" "__argv__" "__e__" "__eps__" |
|
139 "__error_text__" "__i__" "__inf__" "__j__" "__nan__" "__pi__" |
|
140 "__program_invocation_name__" "__program_name__" "__realmax__" |
|
141 "__realmin__" "__stderr__" "__stdin__" "__stdout__" "ans" "argv" |
|
142 "automatic_replot" "beep_on_error" "completion_append_char" |
4451
|
143 "crash_dumps_octave_core" |
2617
|
144 "default_return_value" "default_save_format" |
|
145 "define_all_return_values" "do_fortran_indexing" "e" |
|
146 "echo_executing_commands" "empty_list_elements_ok" "eps" |
4422
|
147 "error_text" "gnuplot_binary" "history_file" |
4452
|
148 "history_size" "ignore_function_time_stamp" |
4451
|
149 "inf" "nan" "nargin" |
2617
|
150 "output_max_field_width" "output_precision" |
|
151 "page_output_immediately" "page_screen_output" "pi" |
|
152 "prefer_column_vectors" "prefer_zero_one_indexing" |
|
153 "print_answer_id_name" "print_empty_dimensions" |
|
154 "program_invocation_name" "program_name" "propagate_empty_matrices" |
|
155 "realmax" "realmin" "resize_on_range_error" |
|
156 "return_last_computed_value" "save_precision" "saving_history" |
4451
|
157 "sighup_dumps_octave_core" "sigterm_dumps_octave_core" |
2617
|
158 "silent_functions" "split_long_rows" "stderr" "stdin" "stdout" |
|
159 "string_fill_char" "struct_levels_to_print" |
|
160 "suppress_verbose_help_message" "treat_neg_dim_as_zero" |
|
161 "warn_assign_as_truth_value" "warn_comma_in_global_decl" |
|
162 "warn_divide_by_zero" "warn_function_name_clash" |
4452
|
163 "warn_imag_to_real" "warn_missing_semicolon" |
|
164 "warn_num_to_str" "warn_str_to_num" "whitespace_in_literal_matrix") |
2617
|
165 "Builtin variables in Octave.") |
|
166 |
|
167 (defvar octave-function-header-regexp |
|
168 (concat "^\\s-*\\<\\(function\\)\\>" |
|
169 "\\([^=;\n]*=[ \t]*\\|[ \t]*\\)\\(\\w+\\)\\>") |
|
170 "Regexp to match an Octave function header. |
|
171 The string `function' and its name are given by the first and third |
|
172 parenthetical grouping.") |
|
173 |
|
174 (defvar octave-font-lock-keywords |
|
175 (list |
|
176 ;; Fontify all builtin keywords. |
|
177 (cons (concat "\\<\\(" |
|
178 (mapconcat 'identity octave-reserved-words "\\|") |
|
179 (mapconcat 'identity octave-text-functions "\\|") |
|
180 "\\)\\>") |
|
181 'font-lock-keyword-face) |
|
182 ;; Fontify all builtin operators. |
|
183 (cons "\\(&\\||\\|<=\\|>=\\|==\\|<\\|>\\|!=\\|!\\)" |
3607
|
184 (if (boundp 'font-lock-builtin-face) |
|
185 'font-lock-builtin-face |
|
186 'font-lock-preprocessor-face)) |
2617
|
187 ;; Fontify all builtin variables. |
|
188 (cons (concat "\\<\\(" |
|
189 (mapconcat 'identity octave-variables "\\|") |
|
190 "\\)\\>") |
|
191 'font-lock-variable-name-face) |
|
192 ;; Fontify all function declarations. |
|
193 (list octave-function-header-regexp |
|
194 '(1 font-lock-keyword-face) |
|
195 '(3 font-lock-function-name-face nil t))) |
|
196 "Additional Octave expressions to highlight.") |
|
197 |
3270
|
198 (defcustom inferior-octave-buffer "*Inferior Octave*" |
|
199 "*Name of buffer for running an inferior Octave process." |
|
200 :type 'string |
|
201 :group 'octave-inferior) |
2617
|
202 |
|
203 (defvar inferior-octave-process nil) |
|
204 |
|
205 (defvar octave-mode-map nil |
|
206 "Keymap used in Octave mode.") |
|
207 (if octave-mode-map |
|
208 () |
|
209 (let ((map (make-sparse-keymap))) |
|
210 (define-key map "`" 'octave-abbrev-start) |
|
211 (define-key map ";" 'octave-electric-semi) |
|
212 (define-key map " " 'octave-electric-space) |
|
213 (define-key map "\n" 'octave-reindent-then-newline-and-indent) |
|
214 (define-key map "\t" 'indent-according-to-mode) |
|
215 (define-key map "\e;" 'octave-indent-for-comment) |
|
216 (define-key map "\e\n" 'octave-indent-new-comment-line) |
|
217 (define-key map "\e\t" 'octave-complete-symbol) |
|
218 (define-key map "\M-\C-a" 'octave-beginning-of-defun) |
|
219 (define-key map "\M-\C-e" 'octave-end-of-defun) |
|
220 (define-key map "\M-\C-h" 'octave-mark-defun) |
|
221 (define-key map "\M-\C-q" 'octave-indent-defun) |
|
222 (define-key map "\C-c;" 'octave-comment-region) |
|
223 (define-key map "\C-c:" 'octave-uncomment-region) |
|
224 (define-key map "\C-c\C-b" 'octave-submit-bug-report) |
|
225 (define-key map "\C-c\C-p" 'octave-previous-code-line) |
|
226 (define-key map "\C-c\C-n" 'octave-next-code-line) |
|
227 (define-key map "\C-c\C-a" 'octave-beginning-of-line) |
|
228 (define-key map "\C-c\C-e" 'octave-end-of-line) |
|
229 (define-key map "\C-c\M-\C-n" 'octave-forward-block) |
|
230 (define-key map "\C-c\M-\C-p" 'octave-backward-block) |
|
231 (define-key map "\C-c\M-\C-u" 'octave-backward-up-block) |
|
232 (define-key map "\C-c\M-\C-d" 'octave-down-block) |
|
233 (define-key map "\C-c\M-\C-h" 'octave-mark-block) |
|
234 (define-key map "\C-c]" 'octave-close-block) |
4304
|
235 (define-key map "\C-c\C-f" 'octave-insert-defun) |
2617
|
236 (define-key map "\C-c\C-h" 'octave-help) |
4304
|
237 (define-key map "\C-c\C-il" 'octave-send-line) |
|
238 (define-key map "\C-c\C-ib" 'octave-send-block) |
|
239 (define-key map "\C-c\C-if" 'octave-send-defun) |
|
240 (define-key map "\C-c\C-ir" 'octave-send-region) |
|
241 (define-key map "\C-c\C-is" 'octave-show-process-buffer) |
|
242 (define-key map "\C-c\C-ih" 'octave-hide-process-buffer) |
|
243 (define-key map "\C-c\C-ik" 'octave-kill-process) |
|
244 (define-key map "\C-c\C-i\C-l" 'octave-send-line) |
|
245 (define-key map "\C-c\C-i\C-b" 'octave-send-block) |
|
246 (define-key map "\C-c\C-i\C-f" 'octave-send-defun) |
|
247 (define-key map "\C-c\C-i\C-r" 'octave-send-region) |
|
248 (define-key map "\C-c\C-i\C-s" 'octave-show-process-buffer) |
|
249 (define-key map "\C-c\C-i\C-h" 'octave-hide-process-buffer) |
|
250 (define-key map "\C-c\C-i\C-k" 'octave-kill-process) |
2617
|
251 (setq octave-mode-map map))) |
|
252 |
|
253 (defvar octave-mode-menu |
|
254 (list "Octave" |
|
255 (list "Lines" |
|
256 ["Previous Code Line" octave-previous-code-line t] |
|
257 ["Next Code Line" octave-next-code-line t] |
|
258 ["Begin of Continuation" octave-beginning-of-line t] |
|
259 ["End of Continuation" octave-end-of-line t] |
|
260 ["Split Line at Point" octave-indent-new-comment-line t]) |
|
261 (list "Blocks" |
|
262 ["Next Block" octave-forward-block t] |
|
263 ["Previous Block" octave-backward-block t] |
|
264 ["Down Block" octave-down-block t] |
|
265 ["Up Block" octave-backward-up-block t] |
|
266 ["Mark Block" octave-mark-block t] |
|
267 ["Close Block" octave-close-block t]) |
|
268 (list "Functions" |
|
269 ["Begin of Function" octave-beginning-of-defun t] |
|
270 ["End of Function" octave-end-of-defun t] |
|
271 ["Mark Function" octave-mark-defun t] |
|
272 ["Indent Function" octave-indent-defun t] |
|
273 ["Insert Function" octave-insert-defun t]) |
|
274 "-" |
|
275 (list "Debug" |
|
276 ["Send Current Line" octave-send-line t] |
|
277 ["Send Current Block" octave-send-block t] |
|
278 ["Send Current Function" octave-send-defun t] |
|
279 ["Send Region" octave-send-region t] |
|
280 ["Show Process Buffer" octave-show-process-buffer t] |
|
281 ["Hide Process Buffer" octave-hide-process-buffer t] |
|
282 ["Kill Process" octave-kill-process t]) |
|
283 "-" |
|
284 ["Indent Line" indent-according-to-mode t] |
|
285 ["Complete Symbol" octave-complete-symbol t] |
|
286 "-" |
|
287 ["Toggle Abbrev Mode" abbrev-mode t] |
|
288 ["Toggle Auto-Fill Mode" auto-fill-mode t] |
|
289 "-" |
|
290 ["Submit Bug Report" octave-submit-bug-report t] |
|
291 "-" |
|
292 ["Describe Octave Mode" octave-describe-major-mode t] |
|
293 ["Lookup Octave Index" octave-help t]) |
|
294 "Menu for Octave mode.") |
|
295 |
3475
|
296 ;; XXX FIXME XXX -- the syntax mode for `%' is punctuation instead of |
|
297 ;; begin-comment because if it is begin-comment, then typing M-; |
|
298 ;; (octave-indent-for-comment) on lines like |
|
299 ;; |
|
300 ;; sprintf ("%d", foobar); |
|
301 ;; |
|
302 ;; causes them to be improperly indented (the `%' is moved over to the |
|
303 ;; comment-column). |
|
304 |
2617
|
305 (defvar octave-mode-syntax-table nil |
|
306 "Syntax table in use in octave-mode buffers.") |
|
307 (if octave-mode-syntax-table |
|
308 () |
|
309 (let ((table (make-syntax-table))) |
|
310 (modify-syntax-entry ?\r " " table) |
|
311 (modify-syntax-entry ?+ "." table) |
|
312 (modify-syntax-entry ?- "." table) |
|
313 (modify-syntax-entry ?= "." table) |
|
314 (modify-syntax-entry ?* "." table) |
|
315 (modify-syntax-entry ?/ "." table) |
|
316 (modify-syntax-entry ?> "." table) |
|
317 (modify-syntax-entry ?< "." table) |
|
318 (modify-syntax-entry ?& "." table) |
|
319 (modify-syntax-entry ?| "." table) |
|
320 (modify-syntax-entry ?! "." table) |
|
321 (modify-syntax-entry ?\\ "\\" table) |
|
322 (modify-syntax-entry ?\' "." table) |
|
323 (modify-syntax-entry ?\` "w" table) |
|
324 (modify-syntax-entry ?\" "\"" table) |
|
325 (modify-syntax-entry ?. "w" table) |
|
326 (modify-syntax-entry ?_ "w" table) |
3475
|
327 (modify-syntax-entry ?\% "." table) ; see above |
2617
|
328 (modify-syntax-entry ?\# "<" table) |
|
329 (modify-syntax-entry ?\n ">" table) |
|
330 (setq octave-mode-syntax-table table))) |
|
331 |
3270
|
332 (defcustom octave-auto-indent nil |
|
333 "*Non-nil means indent line after a semicolon or space in Octave mode." |
|
334 :type 'boolean |
|
335 :group 'octave) |
3069
|
336 |
3270
|
337 (defcustom octave-auto-newline nil |
|
338 "*Non-nil means automatically newline after a semicolon in Octave mode." |
|
339 :type 'boolean |
|
340 :group 'octave) |
2617
|
341 |
3270
|
342 (defcustom octave-blink-matching-block t |
2617
|
343 "*Control the blinking of matching Octave block keywords. |
|
344 Non-nil means show matching begin of block when inserting a space, |
3270
|
345 newline or semicolon after an else or end keyword." |
|
346 :type 'boolean |
|
347 :group 'octave) |
|
348 (defcustom octave-block-offset 2 |
|
349 "*Extra indentation applied to statements in Octave block structures." |
|
350 :type 'integer |
|
351 :group 'octave) |
2617
|
352 |
|
353 (defvar octave-block-begin-regexp |
|
354 (concat "\\<\\(" |
|
355 (mapconcat 'identity octave-begin-keywords "\\|") |
|
356 "\\)\\>")) |
|
357 (defvar octave-block-else-regexp |
|
358 (concat "\\<\\(" |
|
359 (mapconcat 'identity octave-else-keywords "\\|") |
|
360 "\\)\\>")) |
|
361 (defvar octave-block-end-regexp |
|
362 (concat "\\<\\(" |
|
363 (mapconcat 'identity octave-end-keywords "\\|") |
|
364 "\\)\\>")) |
|
365 (defvar octave-block-begin-or-end-regexp |
|
366 (concat octave-block-begin-regexp "\\|" octave-block-end-regexp)) |
|
367 (defvar octave-block-else-or-end-regexp |
|
368 (concat octave-block-else-regexp "\\|" octave-block-end-regexp)) |
|
369 (defvar octave-block-match-alist |
3485
|
370 '(("do" . ("until")) |
|
371 ("for" . ("end" "endfor")) |
2617
|
372 ("function" . ("end" "endfunction")) |
|
373 ("if" . ("else" "elseif" "end" "endif")) |
3092
|
374 ("switch" . ("case" "otherwise" "end" "endswitch")) |
2617
|
375 ("try" . ("catch" "end" "end_try_catch")) |
|
376 ("unwind_protect" . ("unwind_protect_cleanup" "end" |
|
377 "end_unwind_protect")) |
|
378 ("while" . ("end" "endwhile"))) |
|
379 "Alist with Octave's matching block keywords. |
|
380 Has Octave's begin keywords as keys and a list of the matching else or |
|
381 end keywords as associated values.") |
|
382 |
|
383 (defvar octave-block-comment-start |
|
384 (concat (make-string 2 octave-comment-char) " ") |
|
385 "String to insert to start a new Octave comment on an empty line.") |
|
386 |
3270
|
387 (defcustom octave-continuation-offset 4 |
|
388 "*Extra indentation applied to Octave continuation lines." |
|
389 :type 'integer |
|
390 :group 'octave) |
2617
|
391 (defvar octave-continuation-regexp |
|
392 "[^#%\n]*\\(\\\\\\|\\.\\.\\.\\)\\s-*\\(\\s<.*\\)?$") |
3270
|
393 (defcustom octave-continuation-string "\\" |
|
394 "*Character string used for Octave continuation lines. Normally \\." |
|
395 :type 'string |
|
396 :group 'octave) |
2617
|
397 |
|
398 (defvar octave-completion-alist nil |
|
399 "Alist of Octave symbols for completion in Octave mode. |
|
400 Each element looks like (VAR . VAR), where the car and cdr are the same |
|
401 symbol (an Octave command or variable name). |
|
402 Currently, only builtin variables can be completed.") |
|
403 |
|
404 (defvar octave-mode-imenu-generic-expression |
|
405 (list |
|
406 ;; Functions |
|
407 (list nil octave-function-header-regexp 3)) |
|
408 "Imenu expression for Octave mode. See `imenu-generic-expression'.") |
|
409 |
3270
|
410 (defcustom octave-mode-startup-message t |
|
411 "*Nil means do not display the Octave mode startup message." |
|
412 :type 'boolean |
|
413 :group 'octave) |
2617
|
414 |
3270
|
415 (defcustom octave-mode-hook nil |
|
416 "*Hook to be run when Octave mode is started." |
|
417 :type 'hook |
|
418 :group 'octave) |
2617
|
419 |
3270
|
420 (defcustom octave-send-show-buffer t |
|
421 "*Non-nil means display `inferior-octave-buffer' after sending to it." |
|
422 :type 'boolean |
|
423 :group 'octave) |
|
424 (defcustom octave-send-line-auto-forward t |
2617
|
425 "*Control auto-forward after sending to the inferior Octave process. |
3270
|
426 Non-nil means always go to the next Octave code line after sending." |
|
427 :type 'boolean |
|
428 :group 'octave) |
|
429 (defcustom octave-send-echo-input t |
|
430 "*Non-nil means echo input sent to the inferior Octave process." |
|
431 :type 'boolean |
|
432 :group 'octave) |
2617
|
433 |
|
434 |
|
435 ;;;###autoload |
|
436 (defun octave-mode () |
|
437 "Major mode for editing Octave code. |
|
438 |
|
439 This mode makes it easier to write Octave code by helping with |
|
440 indentation, doing some of the typing for you (with Abbrev mode) and by |
|
441 showing keywords, comments, strings, etc. in different faces (with |
|
442 Font Lock mode on terminals that support it). |
|
443 |
|
444 Octave itself is a high-level language, primarily intended for numerical |
|
445 computations. It provides a convenient command line interface for |
|
446 solving linear and nonlinear problems numerically. Function definitions |
|
447 can also be stored in files, and it can be used in a batch mode (which |
|
448 is why you need this mode!). |
|
449 |
|
450 The latest released version of Octave is always available via anonymous |
|
451 ftp from bevo.che.wisc.edu in the directory `/pub/octave'. Complete |
|
452 source and binaries for several popular systems are available. |
|
453 |
|
454 Type \\[list-abbrevs] to display the built-in abbrevs for Octave keywords. |
|
455 |
|
456 Keybindings |
|
457 =========== |
|
458 |
|
459 \\{octave-mode-map} |
|
460 |
|
461 Variables you can use to customize Octave mode |
|
462 ============================================== |
|
463 |
3069
|
464 octave-auto-indent |
|
465 Non-nil means indent current line after a semicolon or space. |
|
466 Default is nil. |
|
467 |
2617
|
468 octave-auto-newline |
|
469 Non-nil means auto-insert a newline and indent after a semicolon. |
|
470 Default is nil. |
|
471 |
|
472 octave-blink-matching-block |
|
473 Non-nil means show matching begin of block when inserting a space, |
|
474 newline or semicolon after an else or end keyword. Default is t. |
|
475 |
|
476 octave-block-offset |
|
477 Extra indentation applied to statements in block structures. |
|
478 Default is 2. |
|
479 |
|
480 octave-continuation-offset |
|
481 Extra indentation applied to Octave continuation lines. |
|
482 Default is 4. |
|
483 |
|
484 octave-continuation-string |
|
485 String used for Octave continuation lines. |
|
486 Default is a backslash. |
|
487 |
|
488 octave-mode-startup-message |
|
489 Nil means do not display the Octave mode startup message. |
|
490 Default is t. |
|
491 |
|
492 octave-send-echo-input |
|
493 Non-nil means always display `inferior-octave-buffer' after sending a |
|
494 command to the inferior Octave process. |
|
495 |
|
496 octave-send-line-auto-forward |
|
497 Non-nil means always go to the next unsent line of Octave code after |
|
498 sending a line to the inferior Octave process. |
|
499 |
|
500 octave-send-echo-input |
|
501 Non-nil means echo input sent to the inferior Octave process. |
|
502 |
|
503 Turning on Octave mode runs the hook `octave-mode-hook'. |
|
504 |
|
505 To begin using this mode for all `.m' files that you edit, add the |
|
506 following lines to your `.emacs' file: |
|
507 |
|
508 (autoload 'octave-mode \"octave-mod\" nil t) |
|
509 (setq auto-mode-alist |
|
510 (cons '(\"\\\\.m$\" . octave-mode) auto-mode-alist)) |
|
511 |
|
512 To automatically turn on the abbrev, auto-fill and font-lock features, |
|
513 add the following lines to your `.emacs' file as well: |
|
514 |
|
515 (add-hook 'octave-mode-hook |
|
516 (lambda () |
|
517 (abbrev-mode 1) |
|
518 (auto-fill-mode 1) |
|
519 (if (eq window-system 'x) |
|
520 (font-lock-mode 1)))) |
|
521 |
|
522 To submit a problem report, enter \\[octave-submit-bug-report] from \ |
|
523 an Octave mode buffer. |
|
524 This automatically sets up a mail buffer with version information |
|
525 already added. You just need to add a description of the problem, |
|
526 including a reproducible test case and send the message." |
|
527 (interactive) |
|
528 (kill-all-local-variables) |
|
529 |
|
530 (use-local-map octave-mode-map) |
|
531 (setq major-mode 'octave-mode) |
|
532 (setq mode-name "Octave") |
|
533 (setq local-abbrev-table octave-abbrev-table) |
|
534 (set-syntax-table octave-mode-syntax-table) |
|
535 |
|
536 (make-local-variable 'indent-line-function) |
|
537 (setq indent-line-function 'octave-indent-line) |
|
538 |
|
539 (make-local-variable 'comment-start) |
|
540 (setq comment-start octave-comment-start) |
|
541 (make-local-variable 'comment-end) |
|
542 (setq comment-end "") |
|
543 (make-local-variable 'comment-column) |
|
544 (setq comment-column 32) |
|
545 (make-local-variable 'comment-start-skip) |
|
546 (setq comment-start-skip "\\s<+\\s-*") |
|
547 (make-local-variable 'comment-indent-function) |
|
548 (setq comment-indent-function 'octave-comment-indent) |
|
549 |
|
550 (make-local-variable 'parse-sexp-ignore-comments) |
|
551 (setq parse-sexp-ignore-comments t) |
|
552 (make-local-variable 'paragraph-start) |
|
553 (setq paragraph-start (concat "\\s-*$\\|" page-delimiter)) |
|
554 (make-local-variable 'paragraph-separate) |
|
555 (setq paragraph-separate paragraph-start) |
|
556 (make-local-variable 'paragraph-ignore-fill-prefix) |
|
557 (setq paragraph-ignore-fill-prefix t) |
|
558 (make-local-variable 'fill-paragraph-function) |
|
559 (setq fill-paragraph-function 'octave-fill-paragraph) |
|
560 (make-local-variable 'adaptive-fill-regexp) |
|
561 (setq adaptive-fill-regexp nil) |
|
562 (make-local-variable 'fill-column) |
|
563 (setq fill-column 72) |
|
564 (make-local-variable 'normal-auto-fill-function) |
|
565 (setq normal-auto-fill-function 'octave-auto-fill) |
|
566 |
|
567 (make-local-variable 'font-lock-defaults) |
|
568 (setq font-lock-defaults '(octave-font-lock-keywords nil nil)) |
|
569 |
|
570 (make-local-variable 'imenu-generic-expression) |
3270
|
571 (setq imenu-generic-expression octave-mode-imenu-generic-expression |
|
572 imenu-case-fold-search nil) |
3176
|
573 |
2617
|
574 (octave-add-octave-menu) |
|
575 (octave-initialize-completions) |
|
576 (run-hooks 'octave-mode-hook)) |
|
577 |
|
578 ;;; Miscellaneous useful functions |
|
579 (defun octave-describe-major-mode () |
|
580 "Describe the current major mode." |
|
581 (interactive) |
|
582 (describe-function major-mode)) |
|
583 |
|
584 (defun octave-point (position) |
|
585 "Returns the value of point at certain positions." |
|
586 (save-excursion |
|
587 (cond |
|
588 ((eq position 'bol) (beginning-of-line)) |
|
589 ((eq position 'eol) (end-of-line)) |
|
590 ((eq position 'boi) (back-to-indentation)) |
|
591 ((eq position 'bonl) (forward-line 1)) |
|
592 ((eq position 'bopl) (forward-line -1)) |
|
593 (t (error "unknown buffer position requested: %s" position))) |
|
594 (point))) |
|
595 |
|
596 (defsubst octave-in-comment-p () |
|
597 "Returns t if point is inside an Octave comment, nil otherwise." |
|
598 (interactive) |
|
599 (save-excursion |
|
600 (nth 4 (parse-partial-sexp (octave-point 'bol) (point))))) |
|
601 |
|
602 (defsubst octave-in-string-p () |
|
603 "Returns t if point is inside an Octave string, nil otherwise." |
|
604 (interactive) |
|
605 (save-excursion |
|
606 (nth 3 (parse-partial-sexp (octave-point 'bol) (point))))) |
|
607 |
|
608 (defsubst octave-not-in-string-or-comment-p () |
|
609 "Returns t iff point is not inside an Octave string or comment." |
|
610 (let ((pps (parse-partial-sexp (octave-point 'bol) (point)))) |
|
611 (not (or (nth 3 pps) (nth 4 pps))))) |
|
612 |
|
613 (defun octave-in-block-p () |
|
614 "Returns t if point is inside an Octave block, nil otherwise. |
|
615 The block is taken to start at the first letter of the begin keyword and |
|
616 to end after the end keyword." |
|
617 (let ((pos (point))) |
|
618 (save-excursion |
|
619 (condition-case nil |
|
620 (progn |
|
621 (skip-syntax-forward "w") |
|
622 (octave-up-block -1) |
|
623 (octave-forward-block) |
|
624 t) |
|
625 (error nil)) |
|
626 (< pos (point))))) |
|
627 |
|
628 (defun octave-in-defun-p () |
|
629 "Returns t iff point is inside an Octave function declaration. |
|
630 The function is taken to start at the `f' of `function' and to end after |
|
631 the end keyword." |
|
632 (let ((pos (point))) |
|
633 (save-excursion |
|
634 (or (and (looking-at "\\<function\\>") |
|
635 (octave-not-in-string-or-comment-p)) |
|
636 (and (octave-beginning-of-defun) |
|
637 (condition-case nil |
|
638 (progn |
|
639 (octave-forward-block) |
|
640 t) |
|
641 (error nil)) |
|
642 (< pos (point))))))) |
|
643 |
3083
|
644 (defun octave-maybe-insert-continuation-string () |
|
645 (if (or (octave-in-comment-p) |
|
646 (save-excursion |
|
647 (beginning-of-line) |
|
648 (looking-at octave-continuation-regexp))) |
|
649 nil |
|
650 (delete-horizontal-space) |
|
651 (insert (concat " " octave-continuation-string)))) |
|
652 |
3225
|
653 (defvar octave-xemacs-p |
|
654 (string-match "XEmacs\\|Lucid" emacs-version)) |
|
655 |
2617
|
656 ;;; Comments |
|
657 (defun octave-comment-region (beg end &optional arg) |
|
658 "Comment or uncomment each line in the region as Octave code. |
|
659 See `comment-region'." |
|
660 (interactive "r\nP") |
|
661 (let ((comment-start (char-to-string octave-comment-char))) |
|
662 (comment-region beg end arg))) |
|
663 |
|
664 (defun octave-uncomment-region (beg end &optional arg) |
|
665 "Uncomment each line in the region as Octave code." |
|
666 (interactive "r\nP") |
|
667 (or arg (setq arg 1)) |
|
668 (octave-comment-region beg end (- arg))) |
|
669 |
|
670 |
|
671 ;;; Indentation |
|
672 (defun calculate-octave-indent () |
|
673 "Return appropriate indentation for current line as Octave code. |
|
674 Returns an integer (the column to indent to) unless the line is a |
|
675 comment line with fixed goal golumn. In that case, returns a list whose |
|
676 car is the column to indent to, and whose cdr is the current indentation |
|
677 level." |
|
678 (let ((is-continuation-line |
|
679 (save-excursion |
|
680 (if (zerop (octave-previous-code-line)) |
|
681 (looking-at octave-continuation-regexp)))) |
|
682 (icol 0)) |
|
683 (save-excursion |
|
684 (beginning-of-line) |
|
685 ;; If we can move backward out one level of parentheses, take 1 |
|
686 ;; plus the indentation of that parenthesis. Otherwise, go back |
|
687 ;; to the beginning of the previous code line, and compute the |
|
688 ;; offset this line gives. |
|
689 (if (condition-case nil |
|
690 (progn |
|
691 (up-list -1) |
|
692 t) |
|
693 (error nil)) |
|
694 (setq icol (+ 1 (current-column))) |
|
695 (if (zerop (octave-previous-code-line)) |
|
696 (progn |
|
697 (octave-beginning-of-line) |
|
698 (back-to-indentation) |
|
699 (setq icol (current-column)) |
|
700 (let ((bot (point)) |
|
701 (eol (octave-point 'eol))) |
|
702 (while (< (point) eol) |
|
703 (if (octave-not-in-string-or-comment-p) |
|
704 (cond |
2788
|
705 ((looking-at "\\<switch\\>") |
|
706 (setq icol (+ icol (* 2 octave-block-offset)))) |
2617
|
707 ((looking-at octave-block-begin-regexp) |
|
708 (setq icol (+ icol octave-block-offset))) |
|
709 ((looking-at octave-block-else-regexp) |
|
710 (if (= bot (point)) |
|
711 (setq icol (+ icol octave-block-offset)))) |
|
712 ((looking-at octave-block-end-regexp) |
|
713 (if (not (= bot (point))) |
2788
|
714 (setq icol (- icol |
|
715 (octave-block-end-offset))))))) |
2617
|
716 (forward-char))) |
|
717 (if is-continuation-line |
|
718 (setq icol (+ icol octave-continuation-offset))))))) |
|
719 (save-excursion |
|
720 (back-to-indentation) |
|
721 (cond |
2788
|
722 ((and (looking-at octave-block-else-regexp) |
2617
|
723 (octave-not-in-string-or-comment-p)) |
|
724 (setq icol (- icol octave-block-offset))) |
2788
|
725 ((and (looking-at octave-block-end-regexp) |
|
726 (octave-not-in-string-or-comment-p)) |
|
727 (setq icol (- icol (octave-block-end-offset)))) |
3081
|
728 ((or (looking-at "\\s<\\s<\\s<\\S<") |
|
729 (octave-before-magic-comment-p)) |
2617
|
730 (setq icol (list 0 icol))) |
|
731 ((looking-at "\\s<\\S<") |
|
732 (setq icol (list comment-column icol))))) |
|
733 icol)) |
|
734 |
2788
|
735 (defun octave-block-end-offset () |
|
736 (save-excursion |
|
737 (octave-backward-up-block 1) |
|
738 (* octave-block-offset |
|
739 (if (string-match (match-string 0) "switch") 2 1)))) |
|
740 |
3081
|
741 (defun octave-before-magic-comment-p () |
|
742 (save-excursion |
|
743 (beginning-of-line) |
|
744 (and (bobp) (looking-at "\\s-*#!")))) |
|
745 |
2617
|
746 (defun octave-comment-indent () |
3081
|
747 (if (or (looking-at "\\s<\\s<\\s<") |
|
748 (octave-before-magic-comment-p)) |
2617
|
749 0 |
|
750 (if (looking-at "\\s<\\s<") |
|
751 (calculate-octave-indent) |
|
752 (skip-syntax-backward " ") |
2788
|
753 (max (if (bolp) 0 (+ 1 (current-column))) |
2617
|
754 comment-column)))) |
|
755 |
|
756 (defun octave-indent-for-comment () |
|
757 "Maybe insert and indent an Octave comment. |
|
758 If there is no comment already on this line, create a code-level comment |
|
759 (started by two comment characters) if the line is empty, or an in-line |
|
760 comment (started by one comment character) otherwise. |
|
761 Point is left after the start of the comment which is properly aligned." |
|
762 (interactive) |
|
763 (indent-for-comment) |
|
764 (indent-according-to-mode)) |
|
765 |
|
766 (defun octave-indent-line (&optional arg) |
|
767 "Indent current line as Octave code. |
|
768 With optional ARG, use this as offset unless this line is a comment with |
|
769 fixed goal column." |
|
770 (interactive) |
|
771 (or arg (setq arg 0)) |
|
772 (let ((icol (calculate-octave-indent)) |
|
773 (relpos (- (current-column) (current-indentation)))) |
|
774 (if (listp icol) |
|
775 (setq icol (car icol)) |
|
776 (setq icol (+ icol arg))) |
|
777 (if (< icol 0) |
|
778 (error "Unmatched end keyword") |
|
779 (indent-line-to icol) |
|
780 (if (> relpos 0) |
|
781 (move-to-column (+ icol relpos)))))) |
|
782 |
|
783 (defun octave-indent-new-comment-line () |
|
784 "Break Octave line at point, continuing comment if within one. |
|
785 If within code, insert `octave-continuation-string' before breaking the |
|
786 line. If within a string, signal an error. |
|
787 The new line is properly indented." |
|
788 (interactive) |
|
789 (delete-horizontal-space) |
|
790 (cond |
|
791 ((octave-in-comment-p) |
|
792 (indent-new-comment-line)) |
|
793 ((octave-in-string-p) |
|
794 (error "Cannot split a code line inside a string")) |
|
795 (t |
|
796 (insert (concat " " octave-continuation-string)) |
|
797 (octave-reindent-then-newline-and-indent)))) |
|
798 |
|
799 (defun octave-indent-defun () |
|
800 "Properly indents the Octave function which contains point." |
|
801 (interactive) |
|
802 (save-excursion |
|
803 (octave-mark-defun) |
|
804 (message "Indenting function...") |
|
805 (indent-region (point) (mark) nil)) |
|
806 (message "Indenting function...done.")) |
|
807 |
|
808 |
|
809 ;;; Motion |
|
810 (defun octave-next-code-line (&optional arg) |
|
811 "Move ARG lines of Octave code forward (backward if ARG is negative). |
|
812 Skips past all empty and comment lines. Default for ARG is 1. |
|
813 |
|
814 On success, return 0. Otherwise, go as far as possible and return -1." |
|
815 (interactive "p") |
|
816 (or arg (setq arg 1)) |
|
817 (beginning-of-line) |
|
818 (let ((n 0) |
|
819 (inc (if (> arg 0) 1 -1))) |
|
820 (while (and (/= arg 0) (= n 0)) |
|
821 (setq n (forward-line inc)) |
|
822 (while (and (= n 0) |
|
823 (looking-at "\\s-*\\($\\|\\s<\\)")) |
|
824 (setq n (forward-line inc))) |
|
825 (setq arg (- arg inc))) |
|
826 n)) |
|
827 |
|
828 (defun octave-previous-code-line (&optional arg) |
|
829 "Move ARG lines of Octave code backward (forward if ARG is negative). |
|
830 Skips past all empty and comment lines. Default for ARG is 1. |
|
831 |
|
832 On success, return 0. Otherwise, go as far as possible and return -1." |
|
833 (interactive "p") |
|
834 (or arg (setq arg 1)) |
|
835 (octave-next-code-line (- arg))) |
|
836 |
|
837 (defun octave-beginning-of-line () |
|
838 "Move point to beginning of current Octave line. |
|
839 If on an empty or comment line, go to the beginning of that line. |
|
840 Otherwise, move backward to the beginning of the first Octave code line |
|
841 which is not inside a continuation statement, i.e., which does not |
|
842 follow a code line ending in `...' or `\\', or is inside an open |
|
843 parenthesis list." |
|
844 (interactive) |
|
845 (beginning-of-line) |
|
846 (if (not (looking-at "\\s-*\\($\\|\\s<\\)")) |
|
847 (while (or (condition-case nil |
|
848 (progn |
|
849 (up-list -1) |
|
850 (beginning-of-line) |
|
851 t) |
|
852 (error nil)) |
|
853 (and (or (looking-at "\\s-*\\($\\|\\s<\\)") |
|
854 (save-excursion |
|
855 (if (zerop (octave-previous-code-line)) |
|
856 (looking-at octave-continuation-regexp)))) |
|
857 (zerop (forward-line -1))))))) |
|
858 |
|
859 (defun octave-end-of-line () |
|
860 "Move point to end of current Octave line. |
|
861 If on an empty or comment line, go to the end of that line. |
|
862 Otherwise, move forward to the end of the first Octave code line which |
|
863 does not end in `...' or `\\' or is inside an open parenthesis list." |
|
864 (interactive) |
|
865 (end-of-line) |
|
866 (if (save-excursion |
|
867 (beginning-of-line) |
|
868 (looking-at "\\s-*\\($\\|\\s<\\)")) |
|
869 () |
|
870 (while (or (condition-case nil |
|
871 (progn |
|
872 (up-list 1) |
|
873 (end-of-line) |
|
874 t) |
|
875 (error nil)) |
|
876 (and (save-excursion |
|
877 (beginning-of-line) |
|
878 (or (looking-at "\\s-*\\($\\|\\s<\\)") |
|
879 (looking-at octave-continuation-regexp))) |
|
880 (zerop (forward-line 1))))) |
|
881 (end-of-line))) |
|
882 |
|
883 (defun octave-scan-blocks (from count depth) |
|
884 "Scan from character number FROM by COUNT Octave begin-end blocks. |
|
885 Returns the character number of the position thus found. |
|
886 |
|
887 If DEPTH is nonzero, block depth begins counting from that value. |
|
888 Only places where the depth in blocks becomes zero are candidates for |
|
889 stopping; COUNT such places are counted. |
|
890 |
|
891 If the beginning or end of the buffer is reached and the depth is wrong, |
|
892 an error is signaled." |
|
893 (let ((min-depth (if (> depth 0) 0 depth)) |
|
894 (inc (if (> count 0) 1 -1))) |
|
895 (save-excursion |
|
896 (while (/= count 0) |
|
897 (catch 'foo |
|
898 (while (or (re-search-forward |
|
899 octave-block-begin-or-end-regexp nil 'move inc) |
|
900 (if (/= depth 0) |
|
901 (error "Unbalanced block"))) |
|
902 (if (octave-not-in-string-or-comment-p) |
|
903 (progn |
|
904 (cond |
|
905 ((match-end 1) |
|
906 (setq depth (+ depth inc))) |
|
907 ((match-end 2) |
|
908 (setq depth (- depth inc)))) |
|
909 (if (< depth min-depth) |
|
910 (error "Containing expression ends prematurely")) |
|
911 (if (= depth 0) |
|
912 (throw 'foo nil)))))) |
|
913 (setq count (- count inc))) |
|
914 (point)))) |
|
915 |
|
916 (defun octave-forward-block (&optional arg) |
|
917 "Move forward across one balanced Octave begin-end block. |
|
918 With argument, do it that many times. |
|
919 Negative arg -N means move backward across N blocks." |
|
920 (interactive "p") |
|
921 (or arg (setq arg 1)) |
|
922 (goto-char (or (octave-scan-blocks (point) arg 0) (buffer-end arg)))) |
|
923 |
|
924 (defun octave-backward-block (&optional arg) |
|
925 "Move backward across one balanced Octave begin-end block. |
|
926 With argument, do it that many times. |
|
927 Negative arg -N means move forward across N blocks." |
|
928 (interactive "p") |
|
929 (or arg (setq arg 1)) |
|
930 (octave-forward-block (- arg))) |
|
931 |
|
932 (defun octave-down-block (arg) |
|
933 "Move forward down one begin-end block level of Octave code. |
|
934 With argument, do this that many times. |
|
935 A negative argument means move backward but still go down a level. |
|
936 In Lisp programs, an argument is required." |
|
937 (interactive "p") |
|
938 (let ((inc (if (> arg 0) 1 -1))) |
|
939 (while (/= arg 0) |
|
940 (goto-char (or (octave-scan-blocks (point) inc -1) |
|
941 (buffer-end arg))) |
|
942 (setq arg (- arg inc))))) |
|
943 |
|
944 (defun octave-backward-up-block (arg) |
|
945 "Move backward out of one begin-end block level of Octave code. |
|
946 With argument, do this that many times. |
|
947 A negative argument means move forward but still to a less deep spot. |
|
948 In Lisp programs, an argument is required." |
|
949 (interactive "p") |
|
950 (octave-up-block (- arg))) |
|
951 |
|
952 (defun octave-up-block (arg) |
|
953 "Move forward out of one begin-end block level of Octave code. |
|
954 With argument, do this that many times. |
|
955 A negative argument means move backward but still to a less deep spot. |
|
956 In Lisp programs, an argument is required." |
|
957 (interactive "p") |
|
958 (let ((inc (if (> arg 0) 1 -1))) |
|
959 (while (/= arg 0) |
|
960 (goto-char (or (octave-scan-blocks (point) inc 1) |
|
961 (buffer-end arg))) |
|
962 (setq arg (- arg inc))))) |
|
963 |
|
964 (defun octave-mark-block () |
|
965 "Put point at the beginning of this Octave block, mark at the end. |
|
966 The block marked is the one that contains point or follows point." |
|
967 (interactive) |
|
968 (let ((pos (point))) |
|
969 (if (or (and (octave-in-block-p) |
|
970 (skip-syntax-forward "w")) |
|
971 (condition-case nil |
|
972 (progn |
|
973 (octave-down-block 1) |
|
974 (octave-in-block-p)) |
|
975 (error nil))) |
|
976 (progn |
|
977 (octave-up-block -1) |
|
978 (push-mark (point)) |
|
979 (octave-forward-block) |
|
980 (exchange-point-and-mark)) |
|
981 (goto-char pos) |
|
982 (message "No block to mark found")))) |
|
983 |
|
984 (defun octave-close-block () |
|
985 "Close the current Octave block on a separate line. |
|
986 An error is signaled if no block to close is found." |
|
987 (interactive) |
|
988 (let (bb-keyword) |
|
989 (condition-case nil |
|
990 (progn |
|
991 (save-excursion |
|
992 (octave-backward-up-block 1) |
|
993 (setq bb-keyword (buffer-substring-no-properties |
|
994 (match-beginning 1) (match-end 1)))) |
|
995 (if (save-excursion |
|
996 (beginning-of-line) |
|
997 (looking-at "^\\s-*$")) |
|
998 (indent-according-to-mode) |
|
999 (octave-reindent-then-newline-and-indent)) |
|
1000 (insert (car (reverse |
|
1001 (assoc bb-keyword |
|
1002 octave-block-match-alist)))) |
|
1003 (octave-reindent-then-newline-and-indent) |
|
1004 t) |
|
1005 (error (message "No block to close found"))))) |
|
1006 |
|
1007 (defun octave-blink-matching-block-open () |
|
1008 "Blink the matching Octave begin block keyword. |
|
1009 If point is right after an Octave else or end type block keyword, move |
|
1010 cursor momentarily to the corresponding begin keyword. |
|
1011 Signal an error if the keywords are incompatible." |
|
1012 (interactive) |
|
1013 (let (bb-keyword bb-arg eb-keyword pos eol) |
|
1014 (if (and (octave-not-in-string-or-comment-p) |
|
1015 (looking-at "\\>") |
|
1016 (save-excursion |
|
1017 (skip-syntax-backward "w") |
|
1018 (looking-at octave-block-else-or-end-regexp))) |
|
1019 (save-excursion |
|
1020 (cond |
|
1021 ((match-end 1) |
|
1022 (setq eb-keyword |
|
1023 (buffer-substring-no-properties |
|
1024 (match-beginning 1) (match-end 1))) |
|
1025 (octave-backward-up-block 1)) |
|
1026 ((match-end 2) |
|
1027 (setq eb-keyword |
|
1028 (buffer-substring-no-properties |
|
1029 (match-beginning 2) (match-end 2))) |
|
1030 (octave-backward-block))) |
|
1031 (setq pos (match-end 0) |
|
1032 bb-keyword |
|
1033 (buffer-substring-no-properties |
|
1034 (match-beginning 0) pos) |
|
1035 pos (+ pos 1) |
|
1036 eol (octave-point 'eol) |
|
1037 bb-arg |
|
1038 (save-excursion |
|
1039 (save-restriction |
|
1040 (goto-char pos) |
|
1041 (while (and (skip-syntax-forward "^<" eol) |
|
1042 (octave-in-string-p) |
|
1043 (not (forward-char 1)))) |
|
1044 (skip-syntax-backward " ") |
|
1045 (buffer-substring-no-properties pos (point))))) |
|
1046 (if (member eb-keyword |
|
1047 (cdr (assoc bb-keyword octave-block-match-alist))) |
|
1048 (progn |
|
1049 (message "Matches `%s %s'" bb-keyword bb-arg) |
|
1050 (if (pos-visible-in-window-p) |
|
1051 (sit-for blink-matching-delay))) |
|
1052 (error "Block keywords `%s' and `%s' do not match" |
|
1053 bb-keyword eb-keyword)))))) |
|
1054 |
|
1055 (defun octave-beginning-of-defun (&optional arg) |
|
1056 "Move backward to the beginning of an Octave function. |
|
1057 With positive ARG, do it that many times. Negative argument -N means |
|
1058 move forward to Nth following beginning of a function. |
|
1059 Returns t unless search stops at the beginning or end of the buffer." |
|
1060 (interactive "p") |
|
1061 (let* ((arg (or arg 1)) |
|
1062 (inc (if (> arg 0) 1 -1)) |
|
1063 (found)) |
|
1064 (and (not (eobp)) |
|
1065 (not (and (> arg 0) (looking-at "\\<function\\>"))) |
|
1066 (skip-syntax-forward "w")) |
|
1067 (while (and (/= arg 0) |
|
1068 (setq found |
|
1069 (re-search-backward "\\<function\\>" nil 'move inc))) |
|
1070 (if (octave-not-in-string-or-comment-p) |
|
1071 (setq arg (- arg inc)))) |
|
1072 (if found |
|
1073 (progn |
|
1074 (and (< inc 0) (goto-char (match-beginning 0))) |
|
1075 t)))) |
|
1076 |
|
1077 (defun octave-end-of-defun (&optional arg) |
|
1078 "Move forward to the end of an Octave function. |
|
1079 With positive ARG, do it that many times. Negative argument -N means |
|
1080 move back to Nth preceding end of a function. |
|
1081 |
|
1082 An end of a function occurs right after the end keyword matching the |
|
1083 `function' keyword that starts the function." |
|
1084 (interactive "p") |
|
1085 (or arg (setq arg 1)) |
|
1086 (and (< arg 0) (skip-syntax-backward "w")) |
|
1087 (and (> arg 0) (skip-syntax-forward "w")) |
|
1088 (if (octave-in-defun-p) |
|
1089 (setq arg (- arg 1))) |
|
1090 (if (= arg 0) (setq arg -1)) |
|
1091 (if (octave-beginning-of-defun (- arg)) |
|
1092 (octave-forward-block))) |
|
1093 |
|
1094 (defun octave-mark-defun () |
|
1095 "Put point at the beginning of this Octave function, mark at its end. |
|
1096 The function marked is the one containing point or following point." |
|
1097 (interactive) |
|
1098 (let ((pos (point))) |
|
1099 (if (or (octave-in-defun-p) |
|
1100 (and (octave-beginning-of-defun -1) |
|
1101 (octave-in-defun-p))) |
|
1102 (progn |
|
1103 (skip-syntax-forward "w") |
|
1104 (octave-beginning-of-defun) |
|
1105 (push-mark (point)) |
|
1106 (octave-end-of-defun) |
|
1107 (exchange-point-and-mark)) |
|
1108 (goto-char pos) |
|
1109 (message "No function to mark found")))) |
|
1110 |
|
1111 |
|
1112 ;;; Filling |
|
1113 (defun octave-auto-fill () |
3083
|
1114 "Perform auto-fill in Octave mode. |
|
1115 Returns nil if no feasible place to break the line could be found, and t |
|
1116 otherwise." |
|
1117 (let (fc give-up) |
|
1118 (if (or (null (setq fc (current-fill-column))) |
|
1119 (save-excursion |
|
1120 (beginning-of-line) |
|
1121 (and auto-fill-inhibit-regexp |
|
1122 (looking-at auto-fill-inhibit-regexp)))) |
|
1123 nil ; Can't do anything |
|
1124 (if (and (not (octave-in-comment-p)) |
|
1125 (> (current-column) fc)) |
|
1126 (setq fc (- fc (+ (length octave-continuation-string) 1)))) |
|
1127 (while (and (not give-up) (> (current-column) fc)) |
|
1128 (let* ((opoint (point)) |
|
1129 (fpoint |
|
1130 (save-excursion |
|
1131 (move-to-column (+ fc 1)) |
|
1132 (skip-chars-backward "^ \t\n") |
|
1133 ;; If we're at the beginning of the line, break after |
|
1134 ;; the first word |
|
1135 (if (bolp) |
|
1136 (re-search-forward "[ \t]" opoint t)) |
|
1137 ;; If we're in a comment line, don't break after the |
|
1138 ;; comment chars |
|
1139 (if (save-excursion |
|
1140 (skip-syntax-backward " <") |
|
1141 (bolp)) |
|
1142 (re-search-forward "[ \t]" (octave-point 'eol) |
|
1143 'move)) |
|
1144 ;; If we're not in a comment line and just ahead the |
|
1145 ;; continuation string, don't break here. |
|
1146 (if (and (not (octave-in-comment-p)) |
|
1147 (looking-at |
|
1148 (concat "\\s-*" |
|
1149 (regexp-quote |
|
1150 octave-continuation-string) |
|
1151 "\\s-*$"))) |
|
1152 (end-of-line)) |
|
1153 (skip-chars-backward " \t") |
|
1154 (point)))) |
|
1155 (if (save-excursion |
|
1156 (goto-char fpoint) |
|
1157 (not (or (bolp) (eolp)))) |
|
1158 (let ((prev-column (current-column))) |
|
1159 (if (save-excursion |
|
1160 (skip-chars-backward " \t") |
|
1161 (= (point) fpoint)) |
|
1162 (progn |
|
1163 (octave-maybe-insert-continuation-string) |
|
1164 (indent-new-comment-line t)) |
|
1165 (save-excursion |
|
1166 (goto-char fpoint) |
|
1167 (octave-maybe-insert-continuation-string) |
|
1168 (indent-new-comment-line t))) |
|
1169 (if (>= (current-column) prev-column) |
|
1170 (setq give-up t))) |
|
1171 (setq give-up t)))) |
|
1172 (not give-up)))) |
2617
|
1173 |
|
1174 (defun octave-fill-paragraph (&optional arg) |
|
1175 "Fill paragraph of Octave code, handling Octave comments." |
|
1176 (interactive "P") |
|
1177 (save-excursion |
|
1178 (let ((end (progn (forward-paragraph) (point))) |
|
1179 (beg (progn |
|
1180 (forward-paragraph -1) |
|
1181 (skip-chars-forward " \t\n") |
|
1182 (beginning-of-line) |
|
1183 (point))) |
|
1184 (cfc (current-fill-column)) |
|
1185 (ind (calculate-octave-indent)) |
|
1186 comment-prefix) |
|
1187 (save-restriction |
|
1188 (goto-char beg) |
|
1189 (narrow-to-region beg end) |
|
1190 (if (listp ind) (setq ind (nth 1 ind))) |
|
1191 (while (not (eobp)) |
|
1192 (condition-case nil |
|
1193 (octave-indent-line ind) |
|
1194 (error nil)) |
|
1195 (if (and (> ind 0) |
|
1196 (not |
|
1197 (save-excursion |
|
1198 (beginning-of-line) |
|
1199 (looking-at "^\\s-*\\($\\|\\s<+\\)")))) |
|
1200 (setq ind 0)) |
|
1201 (move-to-column cfc) |
|
1202 ;; First check whether we need to combine non-empty comment lines |
|
1203 (if (and (< (current-column) cfc) |
|
1204 (octave-in-comment-p) |
|
1205 (not (save-excursion |
|
1206 (beginning-of-line) |
|
1207 (looking-at "^\\s-*\\s<+\\s-*$")))) |
|
1208 ;; This is a nonempty comment line which does not extend |
|
1209 ;; past the fill column. If it is followed by an nonempty |
|
1210 ;; comment line with the same comment prefix, try to |
|
1211 ;; combine them, and repeat this until either we reach the |
|
1212 ;; fill-column or there is nothing more to combine. |
|
1213 (progn |
|
1214 ;; Get the comment prefix |
|
1215 (save-excursion |
|
1216 (beginning-of-line) |
|
1217 (while (and (re-search-forward "\\s<+") |
|
1218 (not (octave-in-comment-p)))) |
|
1219 (setq comment-prefix (match-string 0))) |
|
1220 ;; And keep combining ... |
|
1221 (while (and (< (current-column) cfc) |
|
1222 (save-excursion |
|
1223 (forward-line 1) |
|
1224 (and (looking-at |
|
1225 (concat "^\\s-*" |
|
1226 comment-prefix |
|
1227 "\\S<")) |
|
1228 (not (looking-at |
|
1229 (concat "^\\s-*" |
|
1230 comment-prefix |
|
1231 "\\s-*$")))))) |
|
1232 (delete-char 1) |
|
1233 (re-search-forward comment-prefix) |
|
1234 (delete-region (match-beginning 0) (match-end 0)) |
|
1235 (fixup-whitespace) |
|
1236 (move-to-column cfc)))) |
3083
|
1237 ;; We might also try to combine continued code lines> Perhaps |
|
1238 ;; some other time ... |
2617
|
1239 (skip-chars-forward "^ \t\n") |
|
1240 (delete-horizontal-space) |
|
1241 (if (or (< (current-column) cfc) |
|
1242 (and (= (current-column) cfc) (eolp))) |
|
1243 (forward-line 1) |
|
1244 (if (not (eolp)) (insert " ")) |
3083
|
1245 (or (octave-auto-fill) |
|
1246 (forward-line 1))))) |
2617
|
1247 t))) |
|
1248 |
|
1249 |
|
1250 ;;; Completions |
|
1251 (defun octave-initialize-completions () |
|
1252 "Create an alist for Octave completions." |
|
1253 (if octave-completion-alist |
|
1254 () |
|
1255 (setq octave-completion-alist |
|
1256 (mapcar '(lambda (var) (cons var var)) |
|
1257 (append octave-reserved-words |
|
1258 octave-text-functions |
|
1259 octave-variables))))) |
|
1260 |
|
1261 (defun octave-complete-symbol () |
|
1262 "Perform completion on Octave symbol preceding point. |
|
1263 Compare that symbol against Octave's reserved words and builtin |
|
1264 variables." |
|
1265 ;; This code taken from lisp-complete-symbol |
|
1266 (interactive) |
|
1267 (let* ((end (point)) |
|
1268 (beg (save-excursion (backward-sexp 1) (point))) |
|
1269 (string (buffer-substring-no-properties beg end)) |
|
1270 (completion (try-completion string octave-completion-alist))) |
|
1271 (cond ((eq completion t)) ; ??? |
|
1272 ((null completion) |
|
1273 (message "Can't find completion for \"%s\"" string) |
|
1274 (ding)) |
|
1275 ((not (string= string completion)) |
|
1276 (delete-region beg end) |
|
1277 (insert completion)) |
|
1278 (t |
|
1279 (let ((list (all-completions string octave-completion-alist)) |
|
1280 (conf (current-window-configuration))) |
|
1281 ;; Taken from comint.el |
|
1282 (message "Making completion list...") |
|
1283 (with-output-to-temp-buffer "*Completions*" |
|
1284 (display-completion-list list)) |
|
1285 (message "Hit space to flush") |
|
1286 (let (key first) |
|
1287 (if (save-excursion |
|
1288 (set-buffer (get-buffer "*Completions*")) |
|
1289 (setq key (read-key-sequence nil) |
|
1290 first (aref key 0)) |
|
1291 (and (consp first) (consp (event-start first)) |
|
1292 (eq (window-buffer (posn-window (event-start |
|
1293 first))) |
|
1294 (get-buffer "*Completions*")) |
|
1295 (eq (key-binding key) 'mouse-choose-completion))) |
|
1296 (progn |
|
1297 (mouse-choose-completion first) |
|
1298 (set-window-configuration conf)) |
|
1299 (if (eq first ?\ ) |
|
1300 (set-window-configuration conf) |
|
1301 (setq unread-command-events |
|
1302 (listify-key-sequence key)))))))))) |
|
1303 |
|
1304 |
|
1305 ;;; Electric characters && friends |
|
1306 (defun octave-reindent-then-newline-and-indent () |
|
1307 "Reindent current Octave line, insert newline, and indent the new line. |
|
1308 If Abbrev mode is on, expand abbrevs first." |
|
1309 (interactive) |
|
1310 (if abbrev-mode (expand-abbrev)) |
|
1311 (if octave-blink-matching-block |
|
1312 (octave-blink-matching-block-open)) |
|
1313 (save-excursion |
|
1314 (delete-region (point) (progn (skip-chars-backward " \t") (point))) |
|
1315 (indent-according-to-mode)) |
|
1316 (insert "\n") |
|
1317 (indent-according-to-mode)) |
|
1318 |
|
1319 (defun octave-electric-semi () |
|
1320 "Insert a semicolon in Octave mode. |
3083
|
1321 Maybe expand abbrevs and blink matching block open keywords. |
|
1322 Reindent the line of `octave-auto-indent' is non-nil. |
|
1323 Insert a newline if `octave-auto-newline' is non-nil." |
2617
|
1324 (interactive) |
|
1325 (if (not (octave-not-in-string-or-comment-p)) |
|
1326 (insert ";") |
|
1327 (if abbrev-mode (expand-abbrev)) |
|
1328 (if octave-blink-matching-block |
|
1329 (octave-blink-matching-block-open)) |
3069
|
1330 (if octave-auto-indent |
|
1331 (indent-according-to-mode)) |
2617
|
1332 (insert ";") |
|
1333 (if octave-auto-newline |
|
1334 (newline-and-indent)))) |
|
1335 |
|
1336 (defun octave-electric-space () |
|
1337 "Insert a space in Octave mode. |
3083
|
1338 Maybe expand abbrevs and blink matching block open keywords. |
|
1339 Reindent the line of `octave-auto-indent' is non-nil." |
2617
|
1340 (interactive) |
|
1341 (setq last-command-char ? ) |
|
1342 (if (not (octave-not-in-string-or-comment-p)) |
|
1343 (progn |
|
1344 (indent-according-to-mode) |
|
1345 (self-insert-command 1)) |
|
1346 (if abbrev-mode (expand-abbrev)) |
|
1347 (if octave-blink-matching-block |
|
1348 (octave-blink-matching-block-open)) |
3069
|
1349 (if (and octave-auto-indent |
|
1350 (save-excursion |
|
1351 (skip-syntax-backward " ") |
|
1352 (not (bolp)))) |
2617
|
1353 (indent-according-to-mode)) |
|
1354 (self-insert-command 1))) |
|
1355 |
|
1356 (defun octave-abbrev-start () |
|
1357 "Start entering an Octave abbreviation. |
|
1358 If Abbrev mode is turned on, typing ` (grave accent) followed by ? or |
|
1359 \\[help-command] lists all Octave abbrevs. Any other key combination is |
|
1360 executed normally. |
|
1361 Note that all Octave mode abbrevs start with a grave accent." |
|
1362 (interactive) |
|
1363 (if (not abbrev-mode) |
|
1364 (self-insert-command 1) |
|
1365 (let (c) |
|
1366 (insert last-command-char) |
3225
|
1367 (if (if octave-xemacs-p |
|
1368 (or (eq (event-to-character (setq c (next-event))) ??) |
|
1369 (eq (event-to-character c) help-char)) |
|
1370 (or (eq (setq c (read-event)) ??) |
|
1371 (eq c help-char))) |
|
1372 (let ((abbrev-table-name-list '(octave-abbrev-table))) |
2617
|
1373 (list-abbrevs)) |
|
1374 (setq unread-command-events (list c)))))) |
|
1375 |
|
1376 (defun octave-insert-defun (name args vals) |
|
1377 "Insert an Octave function skeleton. |
|
1378 Prompt for the function's name, arguments and return values (to be |
|
1379 entered without parens)." |
|
1380 (interactive |
|
1381 (list |
|
1382 (read-from-minibuffer "Function name: " |
|
1383 (substring (buffer-name) 0 -2)) |
|
1384 (read-from-minibuffer "Arguments: ") |
|
1385 (read-from-minibuffer "Return values: "))) |
|
1386 (let ((string (format "%s %s (%s)" |
|
1387 (cond |
|
1388 ((string-equal vals "") |
|
1389 vals) |
|
1390 ((string-match "[ ,]" vals) |
|
1391 (concat " [" vals "] =")) |
|
1392 (t |
|
1393 (concat " " vals " ="))) |
|
1394 name |
|
1395 args)) |
|
1396 (prefix octave-block-comment-start)) |
|
1397 (if (not (bobp)) (newline)) |
|
1398 (insert "function" string) |
|
1399 (indent-according-to-mode) |
|
1400 (newline 2) |
|
1401 (insert prefix "usage: " string) |
|
1402 (reindent-then-newline-and-indent) |
|
1403 (insert prefix) |
|
1404 (reindent-then-newline-and-indent) |
|
1405 (insert prefix) |
|
1406 (indent-according-to-mode) |
|
1407 (save-excursion |
|
1408 (newline 2) |
|
1409 (insert "endfunction") |
|
1410 (indent-according-to-mode)))) |
|
1411 |
|
1412 |
|
1413 ;;; Menu |
|
1414 (defun octave-add-octave-menu () |
|
1415 "Adds the `Octave' menu to the menu bar in Octave mode." |
|
1416 (require 'easymenu) |
|
1417 (easy-menu-define octave-mode-menu-map octave-mode-map |
|
1418 "Menu keymap for Octave mode." octave-mode-menu) |
|
1419 (easy-menu-add octave-mode-menu-map octave-mode-map)) |
|
1420 |
|
1421 |
|
1422 ;;; Communication with the inferior Octave process |
|
1423 (defun octave-kill-process () |
|
1424 "Kill inferior Octave process and its buffer." |
|
1425 (interactive) |
|
1426 (if inferior-octave-process |
|
1427 (progn |
|
1428 (process-send-string inferior-octave-process "quit;\n") |
|
1429 (accept-process-output inferior-octave-process))) |
|
1430 (if inferior-octave-buffer |
|
1431 (kill-buffer inferior-octave-buffer))) |
|
1432 |
|
1433 (defun octave-show-process-buffer () |
|
1434 "Make sure that `inferior-octave-buffer' is displayed." |
|
1435 (interactive) |
|
1436 (if (get-buffer inferior-octave-buffer) |
|
1437 (display-buffer inferior-octave-buffer) |
|
1438 (message "No buffer named %s" inferior-octave-buffer))) |
|
1439 |
|
1440 (defun octave-hide-process-buffer () |
|
1441 "Delete all windows that display `inferior-octave-buffer'." |
|
1442 (interactive) |
|
1443 (if (get-buffer inferior-octave-buffer) |
|
1444 (delete-windows-on inferior-octave-buffer) |
|
1445 (message "No buffer named %s" inferior-octave-buffer))) |
|
1446 |
|
1447 (defun octave-send-region (beg end) |
|
1448 "Send current region to the inferior Octave process." |
|
1449 (interactive "r") |
|
1450 (inferior-octave t) |
|
1451 (let ((proc inferior-octave-process) |
|
1452 (string (buffer-substring-no-properties beg end)) |
|
1453 line) |
|
1454 (save-excursion |
|
1455 (set-buffer inferior-octave-buffer) |
|
1456 (setq inferior-octave-output-list nil) |
|
1457 (while (not (string-equal string "")) |
|
1458 (if (string-match "\n" string) |
|
1459 (setq line (substring string 0 (match-beginning 0)) |
|
1460 string (substring string (match-end 0))) |
|
1461 (setq line string string "")) |
|
1462 (setq inferior-octave-receive-in-progress t) |
|
1463 (inferior-octave-send-list-and-digest (list (concat line "\n"))) |
|
1464 (while inferior-octave-receive-in-progress |
|
1465 (accept-process-output proc)) |
|
1466 (insert-before-markers |
|
1467 (mapconcat 'identity |
|
1468 (append |
|
1469 (if octave-send-echo-input (list line) (list "")) |
|
1470 (mapcar 'inferior-octave-strip-ctrl-g |
|
1471 inferior-octave-output-list) |
|
1472 (list inferior-octave-output-string)) |
|
1473 "\n"))))) |
|
1474 (if octave-send-show-buffer |
|
1475 (display-buffer inferior-octave-buffer))) |
|
1476 |
|
1477 (defun octave-send-block () |
|
1478 "Send current Octave block to the inferior Octave process." |
|
1479 (interactive) |
|
1480 (save-excursion |
|
1481 (octave-mark-block) |
|
1482 (octave-send-region (point) (mark)))) |
|
1483 |
|
1484 (defun octave-send-defun () |
|
1485 "Send current Octave function to the inferior Octave process." |
|
1486 (interactive) |
|
1487 (save-excursion |
|
1488 (octave-mark-defun) |
|
1489 (octave-send-region (point) (mark)))) |
|
1490 |
|
1491 (defun octave-send-line (&optional arg) |
|
1492 "Send current Octave code line to the inferior Octave process. |
|
1493 With positive prefix ARG, send that many lines. |
|
1494 If `octave-send-line-auto-forward' is non-nil, go to the next unsent |
|
1495 code line." |
|
1496 (interactive "P") |
|
1497 (or arg (setq arg 1)) |
|
1498 (if (> arg 0) |
|
1499 (let (beg end) |
|
1500 (beginning-of-line) |
|
1501 (setq beg (point)) |
|
1502 (octave-next-code-line (- arg 1)) |
|
1503 (end-of-line) |
|
1504 (setq end (point)) |
|
1505 (if octave-send-line-auto-forward |
|
1506 (octave-next-code-line 1)) |
|
1507 (octave-send-region beg end)))) |
|
1508 |
|
1509 (defun octave-eval-print-last-sexp () |
|
1510 "Evaluate Octave sexp before point and print value into current buffer." |
|
1511 (interactive) |
|
1512 (inferior-octave t) |
|
1513 (let ((standard-output (current-buffer)) |
|
1514 (print-escape-newlines nil) |
|
1515 (opoint (point))) |
|
1516 (terpri) |
|
1517 (prin1 |
|
1518 (save-excursion |
|
1519 (forward-sexp -1) |
|
1520 (inferior-octave-send-list-and-digest |
|
1521 (list (concat (buffer-substring-no-properties (point) opoint) |
|
1522 "\n"))) |
|
1523 (mapconcat 'identity inferior-octave-output-list "\n"))) |
|
1524 (terpri))) |
|
1525 |
|
1526 ;;; Bug reporting |
|
1527 (defun octave-submit-bug-report () |
|
1528 "Submit a bug report on the Emacs Octave package via mail." |
|
1529 (interactive) |
|
1530 (require 'reporter) |
|
1531 (and |
|
1532 (y-or-n-p "Do you want to submit a bug report? ") |
|
1533 (reporter-submit-bug-report |
|
1534 octave-maintainer-address |
|
1535 (concat "Emacs version " emacs-version) |
|
1536 (list |
3069
|
1537 'octave-auto-indent |
2617
|
1538 'octave-auto-newline |
|
1539 'octave-blink-matching-block |
|
1540 'octave-block-offset |
|
1541 'octave-comment-char |
|
1542 'octave-continuation-offset |
|
1543 'octave-continuation-string |
|
1544 'octave-help-files |
|
1545 'octave-mode-startup-message |
|
1546 'octave-send-echo-input |
|
1547 'octave-send-line-auto-forward |
|
1548 'octave-send-show-buffer)))) |
|
1549 |
|
1550 ;;; provide ourself |
|
1551 |
|
1552 (provide 'octave-mod) |
|
1553 |
|
1554 ;;; octave-mod.el ends here |