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