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