Mercurial > emacs
annotate lisp/progmodes/octave-mod.el @ 22408:500bc7f67524
(apropos-print): The cross ref for a variable
should always do just describe-variable.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 09 Jun 1998 03:47:42 +0000 |
parents | 9861518505cb |
children | 7896e341d77f |
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 | |
21669
9861518505cb
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
20953
diff
changeset
|
311 :group 'octave |
9861518505cb
*** empty log message ***
Dan Nicolaescu <done@ece.arizona.edu>
parents:
20953
diff
changeset
|
312 :version "20.3") |
20181
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
313 |
20781 | 314 (defcustom octave-auto-newline nil |
315 "*Non-nil means automatically newline after a semicolon in Octave mode." | |
316 :type 'boolean | |
317 :group 'octave) | |
16901 | 318 |
20781 | 319 (defcustom octave-blink-matching-block t |
16901 | 320 "*Control the blinking of matching Octave block keywords. |
321 Non-nil means show matching begin of block when inserting a space, | |
20781 | 322 newline or semicolon after an else or end keyword." |
323 :type 'boolean | |
324 :group 'octave) | |
325 (defcustom octave-block-offset 2 | |
326 "*Extra indentation applied to statements in Octave block structures." | |
327 :type 'integer | |
328 :group 'octave) | |
16901 | 329 |
330 (defvar octave-block-begin-regexp | |
331 (concat "\\<\\(" | |
332 (mapconcat 'identity octave-begin-keywords "\\|") | |
333 "\\)\\>")) | |
334 (defvar octave-block-else-regexp | |
335 (concat "\\<\\(" | |
336 (mapconcat 'identity octave-else-keywords "\\|") | |
337 "\\)\\>")) | |
338 (defvar octave-block-end-regexp | |
339 (concat "\\<\\(" | |
340 (mapconcat 'identity octave-end-keywords "\\|") | |
341 "\\)\\>")) | |
342 (defvar octave-block-begin-or-end-regexp | |
343 (concat octave-block-begin-regexp "\\|" octave-block-end-regexp)) | |
344 (defvar octave-block-else-or-end-regexp | |
345 (concat octave-block-else-regexp "\\|" octave-block-end-regexp)) | |
346 (defvar octave-block-match-alist | |
347 '(("for" . ("end" "endfor")) | |
348 ("function" . ("end" "endfunction")) | |
349 ("if" . ("else" "elseif" "end" "endif")) | |
20181
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
350 ("switch" . ("case" "otherwise" "end" "endswitch")) |
16901 | 351 ("try" . ("catch" "end" "end_try_catch")) |
352 ("unwind_protect" . ("unwind_protect_cleanup" "end" | |
353 "end_unwind_protect")) | |
354 ("while" . ("end" "endwhile"))) | |
355 "Alist with Octave's matching block keywords. | |
356 Has Octave's begin keywords as keys and a list of the matching else or | |
357 end keywords as associated values.") | |
358 | |
359 (defvar octave-block-comment-start | |
360 (concat (make-string 2 octave-comment-char) " ") | |
361 "String to insert to start a new Octave comment on an empty line.") | |
362 | |
20781 | 363 (defcustom octave-continuation-offset 4 |
364 "*Extra indentation applied to Octave continuation lines." | |
365 :type 'integer | |
366 :group 'octave) | |
16901 | 367 (defvar octave-continuation-regexp |
368 "[^#%\n]*\\(\\\\\\|\\.\\.\\.\\)\\s-*\\(\\s<.*\\)?$") | |
20781 | 369 (defcustom octave-continuation-string "\\" |
370 "*Character string used for Octave continuation lines. Normally \\." | |
371 :type 'string | |
372 :group 'octave) | |
16901 | 373 |
374 (defvar octave-completion-alist nil | |
375 "Alist of Octave symbols for completion in Octave mode. | |
376 Each element looks like (VAR . VAR), where the car and cdr are the same | |
377 symbol (an Octave command or variable name). | |
378 Currently, only builtin variables can be completed.") | |
379 | |
380 (defvar octave-mode-imenu-generic-expression | |
381 (list | |
382 ;; Functions | |
383 (list nil octave-function-header-regexp 3)) | |
384 "Imenu expression for Octave mode. See `imenu-generic-expression'.") | |
385 | |
20781 | 386 (defcustom octave-mode-startup-message t |
387 "*Nil means do not display the Octave mode startup message." | |
388 :type 'boolean | |
389 :group 'octave) | |
16901 | 390 |
20781 | 391 (defcustom octave-mode-hook nil |
392 "*Hook to be run when Octave mode is started." | |
393 :type 'hook | |
394 :group 'octave) | |
16901 | 395 |
20781 | 396 (defcustom octave-send-show-buffer t |
397 "*Non-nil means display `inferior-octave-buffer' after sending to it." | |
398 :type 'boolean | |
399 :group 'octave) | |
400 (defcustom octave-send-line-auto-forward t | |
16901 | 401 "*Control auto-forward after sending to the inferior Octave process. |
20781 | 402 Non-nil means always go to the next Octave code line after sending." |
403 :type 'boolean | |
404 :group 'octave) | |
405 (defcustom octave-send-echo-input t | |
406 "*Non-nil means echo input sent to the inferior Octave process." | |
407 :type 'boolean | |
408 :group 'octave) | |
16901 | 409 |
410 | |
411 ;;;###autoload | |
412 (defun octave-mode () | |
413 "Major mode for editing Octave code. | |
414 | |
415 This mode makes it easier to write Octave code by helping with | |
416 indentation, doing some of the typing for you (with Abbrev mode) and by | |
417 showing keywords, comments, strings, etc. in different faces (with | |
418 Font Lock mode on terminals that support it). | |
419 | |
420 Octave itself is a high-level language, primarily intended for numerical | |
421 computations. It provides a convenient command line interface for | |
422 solving linear and nonlinear problems numerically. Function definitions | |
423 can also be stored in files, and it can be used in a batch mode (which | |
424 is why you need this mode!). | |
425 | |
426 The latest released version of Octave is always available via anonymous | |
427 ftp from bevo.che.wisc.edu in the directory `/pub/octave'. Complete | |
428 source and binaries for several popular systems are available. | |
429 | |
430 Type \\[list-abbrevs] to display the built-in abbrevs for Octave keywords. | |
431 | |
432 Keybindings | |
433 =========== | |
434 | |
435 \\{octave-mode-map} | |
436 | |
437 Variables you can use to customize Octave mode | |
438 ============================================== | |
439 | |
20181
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
440 octave-auto-indent |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
441 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
|
442 Default is nil. |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
443 |
16901 | 444 octave-auto-newline |
445 Non-nil means auto-insert a newline and indent after a semicolon. | |
446 Default is nil. | |
447 | |
448 octave-blink-matching-block | |
449 Non-nil means show matching begin of block when inserting a space, | |
450 newline or semicolon after an else or end keyword. Default is t. | |
451 | |
452 octave-block-offset | |
453 Extra indentation applied to statements in block structures. | |
454 Default is 2. | |
455 | |
456 octave-continuation-offset | |
457 Extra indentation applied to Octave continuation lines. | |
458 Default is 4. | |
459 | |
460 octave-continuation-string | |
461 String used for Octave continuation lines. | |
462 Default is a backslash. | |
463 | |
464 octave-mode-startup-message | |
465 Nil means do not display the Octave mode startup message. | |
466 Default is t. | |
467 | |
468 octave-send-echo-input | |
469 Non-nil means always display `inferior-octave-buffer' after sending a | |
470 command to the inferior Octave process. | |
471 | |
472 octave-send-line-auto-forward | |
473 Non-nil means always go to the next unsent line of Octave code after | |
474 sending a line to the inferior Octave process. | |
475 | |
476 octave-send-echo-input | |
477 Non-nil means echo input sent to the inferior Octave process. | |
478 | |
479 Turning on Octave mode runs the hook `octave-mode-hook'. | |
480 | |
481 To begin using this mode for all `.m' files that you edit, add the | |
482 following lines to your `.emacs' file: | |
483 | |
484 (autoload 'octave-mode \"octave-mod\" nil t) | |
485 (setq auto-mode-alist | |
486 (cons '(\"\\\\.m$\" . octave-mode) auto-mode-alist)) | |
487 | |
488 To automatically turn on the abbrev, auto-fill and font-lock features, | |
489 add the following lines to your `.emacs' file as well: | |
490 | |
491 (add-hook 'octave-mode-hook | |
492 (lambda () | |
493 (abbrev-mode 1) | |
494 (auto-fill-mode 1) | |
495 (if (eq window-system 'x) | |
496 (font-lock-mode 1)))) | |
497 | |
498 To submit a problem report, enter \\[octave-submit-bug-report] from \ | |
499 an Octave mode buffer. | |
500 This automatically sets up a mail buffer with version information | |
501 already added. You just need to add a description of the problem, | |
502 including a reproducible test case and send the message." | |
503 (interactive) | |
504 (kill-all-local-variables) | |
505 | |
506 (use-local-map octave-mode-map) | |
507 (setq major-mode 'octave-mode) | |
508 (setq mode-name "Octave") | |
509 (setq local-abbrev-table octave-abbrev-table) | |
510 (set-syntax-table octave-mode-syntax-table) | |
511 | |
512 (make-local-variable 'indent-line-function) | |
513 (setq indent-line-function 'octave-indent-line) | |
514 | |
515 (make-local-variable 'comment-start) | |
516 (setq comment-start octave-comment-start) | |
517 (make-local-variable 'comment-end) | |
518 (setq comment-end "") | |
519 (make-local-variable 'comment-column) | |
520 (setq comment-column 32) | |
521 (make-local-variable 'comment-start-skip) | |
522 (setq comment-start-skip "\\s<+\\s-*") | |
523 (make-local-variable 'comment-indent-function) | |
524 (setq comment-indent-function 'octave-comment-indent) | |
525 | |
526 (make-local-variable 'parse-sexp-ignore-comments) | |
527 (setq parse-sexp-ignore-comments t) | |
528 (make-local-variable 'paragraph-start) | |
529 (setq paragraph-start (concat "\\s-*$\\|" page-delimiter)) | |
530 (make-local-variable 'paragraph-separate) | |
531 (setq paragraph-separate paragraph-start) | |
532 (make-local-variable 'paragraph-ignore-fill-prefix) | |
533 (setq paragraph-ignore-fill-prefix t) | |
534 (make-local-variable 'fill-paragraph-function) | |
535 (setq fill-paragraph-function 'octave-fill-paragraph) | |
536 (make-local-variable 'adaptive-fill-regexp) | |
537 (setq adaptive-fill-regexp nil) | |
538 (make-local-variable 'fill-column) | |
539 (setq fill-column 72) | |
540 (make-local-variable 'normal-auto-fill-function) | |
541 (setq normal-auto-fill-function 'octave-auto-fill) | |
542 | |
543 (make-local-variable 'font-lock-defaults) | |
544 (setq font-lock-defaults '(octave-font-lock-keywords nil nil)) | |
545 | |
546 (make-local-variable 'imenu-generic-expression) | |
20459 | 547 (setq imenu-generic-expression octave-mode-imenu-generic-expression |
548 imenu-case-fold-search nil) | |
16901 | 549 |
550 (octave-add-octave-menu) | |
551 (octave-initialize-completions) | |
16902
6a94efd704e6
(octave-mode): Delete the startup message.
Richard M. Stallman <rms@gnu.org>
parents:
16901
diff
changeset
|
552 (run-hooks 'octave-mode-hook)) |
16901 | 553 |
554 ;;; Miscellaneous useful functions | |
555 (defun octave-describe-major-mode () | |
556 "Describe the current major mode." | |
557 (interactive) | |
558 (describe-function major-mode)) | |
559 | |
560 (defun octave-point (position) | |
561 "Returns the value of point at certain positions." | |
562 (save-excursion | |
563 (cond | |
564 ((eq position 'bol) (beginning-of-line)) | |
565 ((eq position 'eol) (end-of-line)) | |
566 ((eq position 'boi) (back-to-indentation)) | |
567 ((eq position 'bonl) (forward-line 1)) | |
568 ((eq position 'bopl) (forward-line -1)) | |
569 (t (error "unknown buffer position requested: %s" position))) | |
570 (point))) | |
571 | |
572 (defsubst octave-in-comment-p () | |
573 "Returns t if point is inside an Octave comment, nil otherwise." | |
574 (interactive) | |
575 (save-excursion | |
576 (nth 4 (parse-partial-sexp (octave-point 'bol) (point))))) | |
577 | |
578 (defsubst octave-in-string-p () | |
579 "Returns t if point is inside an Octave string, nil otherwise." | |
580 (interactive) | |
581 (save-excursion | |
582 (nth 3 (parse-partial-sexp (octave-point 'bol) (point))))) | |
583 | |
584 (defsubst octave-not-in-string-or-comment-p () | |
585 "Returns t iff point is not inside an Octave string or comment." | |
586 (let ((pps (parse-partial-sexp (octave-point 'bol) (point)))) | |
587 (not (or (nth 3 pps) (nth 4 pps))))) | |
588 | |
589 (defun octave-in-block-p () | |
590 "Returns t if point is inside an Octave block, nil otherwise. | |
591 The block is taken to start at the first letter of the begin keyword and | |
592 to end after the end keyword." | |
593 (let ((pos (point))) | |
594 (save-excursion | |
595 (condition-case nil | |
596 (progn | |
597 (skip-syntax-forward "w") | |
598 (octave-up-block -1) | |
599 (octave-forward-block) | |
600 t) | |
601 (error nil)) | |
602 (< pos (point))))) | |
603 | |
604 (defun octave-in-defun-p () | |
605 "Returns t iff point is inside an Octave function declaration. | |
606 The function is taken to start at the `f' of `function' and to end after | |
607 the end keyword." | |
608 (let ((pos (point))) | |
609 (save-excursion | |
610 (or (and (looking-at "\\<function\\>") | |
611 (octave-not-in-string-or-comment-p)) | |
612 (and (octave-beginning-of-defun) | |
613 (condition-case nil | |
614 (progn | |
615 (octave-forward-block) | |
616 t) | |
617 (error nil)) | |
618 (< pos (point))))))) | |
619 | |
20181
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
620 (defun octave-maybe-insert-continuation-string () |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
621 (if (or (octave-in-comment-p) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
622 (save-excursion |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
623 (beginning-of-line) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
624 (looking-at octave-continuation-regexp))) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
625 nil |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
626 (delete-horizontal-space) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
627 (insert (concat " " octave-continuation-string)))) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
628 |
16901 | 629 ;;; Comments |
630 (defun octave-comment-region (beg end &optional arg) | |
631 "Comment or uncomment each line in the region as Octave code. | |
632 See `comment-region'." | |
633 (interactive "r\nP") | |
634 (let ((comment-start (char-to-string octave-comment-char))) | |
635 (comment-region beg end arg))) | |
636 | |
637 (defun octave-uncomment-region (beg end &optional arg) | |
638 "Uncomment each line in the region as Octave code." | |
639 (interactive "r\nP") | |
640 (or arg (setq arg 1)) | |
641 (octave-comment-region beg end (- arg))) | |
642 | |
643 | |
644 ;;; Indentation | |
645 (defun calculate-octave-indent () | |
646 "Return appropriate indentation for current line as Octave code. | |
647 Returns an integer (the column to indent to) unless the line is a | |
648 comment line with fixed goal golumn. In that case, returns a list whose | |
649 car is the column to indent to, and whose cdr is the current indentation | |
650 level." | |
651 (let ((is-continuation-line | |
652 (save-excursion | |
653 (if (zerop (octave-previous-code-line)) | |
654 (looking-at octave-continuation-regexp)))) | |
655 (icol 0)) | |
656 (save-excursion | |
657 (beginning-of-line) | |
658 ;; If we can move backward out one level of parentheses, take 1 | |
659 ;; plus the indentation of that parenthesis. Otherwise, go back | |
660 ;; to the beginning of the previous code line, and compute the | |
661 ;; offset this line gives. | |
662 (if (condition-case nil | |
663 (progn | |
664 (up-list -1) | |
665 t) | |
666 (error nil)) | |
667 (setq icol (+ 1 (current-column))) | |
668 (if (zerop (octave-previous-code-line)) | |
669 (progn | |
670 (octave-beginning-of-line) | |
671 (back-to-indentation) | |
672 (setq icol (current-column)) | |
673 (let ((bot (point)) | |
674 (eol (octave-point 'eol))) | |
675 (while (< (point) eol) | |
676 (if (octave-not-in-string-or-comment-p) | |
677 (cond | |
17151
0663a5ce936c
(octave-abbrev-table): Add abbrevs for switch,
Karl Heuer <kwzh@gnu.org>
parents:
16911
diff
changeset
|
678 ((looking-at "\\<switch\\>") |
0663a5ce936c
(octave-abbrev-table): Add abbrevs for switch,
Karl Heuer <kwzh@gnu.org>
parents:
16911
diff
changeset
|
679 (setq icol (+ icol (* 2 octave-block-offset)))) |
16901 | 680 ((looking-at octave-block-begin-regexp) |
681 (setq icol (+ icol octave-block-offset))) | |
682 ((looking-at octave-block-else-regexp) | |
683 (if (= bot (point)) | |
684 (setq icol (+ icol octave-block-offset)))) | |
685 ((looking-at octave-block-end-regexp) | |
686 (if (not (= bot (point))) | |
17151
0663a5ce936c
(octave-abbrev-table): Add abbrevs for switch,
Karl Heuer <kwzh@gnu.org>
parents:
16911
diff
changeset
|
687 (setq icol (- icol |
0663a5ce936c
(octave-abbrev-table): Add abbrevs for switch,
Karl Heuer <kwzh@gnu.org>
parents:
16911
diff
changeset
|
688 (octave-block-end-offset))))))) |
16901 | 689 (forward-char))) |
690 (if is-continuation-line | |
691 (setq icol (+ icol octave-continuation-offset))))))) | |
692 (save-excursion | |
693 (back-to-indentation) | |
694 (cond | |
17151
0663a5ce936c
(octave-abbrev-table): Add abbrevs for switch,
Karl Heuer <kwzh@gnu.org>
parents:
16911
diff
changeset
|
695 ((and (looking-at octave-block-else-regexp) |
16901 | 696 (octave-not-in-string-or-comment-p)) |
697 (setq icol (- icol octave-block-offset))) | |
17151
0663a5ce936c
(octave-abbrev-table): Add abbrevs for switch,
Karl Heuer <kwzh@gnu.org>
parents:
16911
diff
changeset
|
698 ((and (looking-at octave-block-end-regexp) |
0663a5ce936c
(octave-abbrev-table): Add abbrevs for switch,
Karl Heuer <kwzh@gnu.org>
parents:
16911
diff
changeset
|
699 (octave-not-in-string-or-comment-p)) |
0663a5ce936c
(octave-abbrev-table): Add abbrevs for switch,
Karl Heuer <kwzh@gnu.org>
parents:
16911
diff
changeset
|
700 (setq icol (- icol (octave-block-end-offset)))) |
20181
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
701 ((or (looking-at "\\s<\\s<\\s<\\S<") |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
702 (octave-before-magic-comment-p)) |
16901 | 703 (setq icol (list 0 icol))) |
704 ((looking-at "\\s<\\S<") | |
705 (setq icol (list comment-column icol))))) | |
706 icol)) | |
707 | |
17151
0663a5ce936c
(octave-abbrev-table): Add abbrevs for switch,
Karl Heuer <kwzh@gnu.org>
parents:
16911
diff
changeset
|
708 (defun octave-block-end-offset () |
0663a5ce936c
(octave-abbrev-table): Add abbrevs for switch,
Karl Heuer <kwzh@gnu.org>
parents:
16911
diff
changeset
|
709 (save-excursion |
0663a5ce936c
(octave-abbrev-table): Add abbrevs for switch,
Karl Heuer <kwzh@gnu.org>
parents:
16911
diff
changeset
|
710 (octave-backward-up-block 1) |
0663a5ce936c
(octave-abbrev-table): Add abbrevs for switch,
Karl Heuer <kwzh@gnu.org>
parents:
16911
diff
changeset
|
711 (* octave-block-offset |
0663a5ce936c
(octave-abbrev-table): Add abbrevs for switch,
Karl Heuer <kwzh@gnu.org>
parents:
16911
diff
changeset
|
712 (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
|
713 |
20181
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
714 (defun octave-before-magic-comment-p () |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
715 (save-excursion |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
716 (beginning-of-line) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
717 (and (bobp) (looking-at "\\s-*#!")))) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
718 |
16901 | 719 (defun octave-comment-indent () |
20181
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
720 (if (or (looking-at "\\s<\\s<\\s<") |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
721 (octave-before-magic-comment-p)) |
16901 | 722 0 |
723 (if (looking-at "\\s<\\s<") | |
724 (calculate-octave-indent) | |
725 (skip-syntax-backward " ") | |
17151
0663a5ce936c
(octave-abbrev-table): Add abbrevs for switch,
Karl Heuer <kwzh@gnu.org>
parents:
16911
diff
changeset
|
726 (max (if (bolp) 0 (+ 1 (current-column))) |
16901 | 727 comment-column)))) |
728 | |
729 (defun octave-indent-for-comment () | |
730 "Maybe insert and indent an Octave comment. | |
731 If there is no comment already on this line, create a code-level comment | |
732 (started by two comment characters) if the line is empty, or an in-line | |
733 comment (started by one comment character) otherwise. | |
734 Point is left after the start of the comment which is properly aligned." | |
735 (interactive) | |
736 (indent-for-comment) | |
737 (indent-according-to-mode)) | |
738 | |
739 (defun octave-indent-line (&optional arg) | |
740 "Indent current line as Octave code. | |
741 With optional ARG, use this as offset unless this line is a comment with | |
742 fixed goal column." | |
743 (interactive) | |
744 (or arg (setq arg 0)) | |
745 (let ((icol (calculate-octave-indent)) | |
746 (relpos (- (current-column) (current-indentation)))) | |
747 (if (listp icol) | |
748 (setq icol (car icol)) | |
749 (setq icol (+ icol arg))) | |
750 (if (< icol 0) | |
751 (error "Unmatched end keyword") | |
752 (indent-line-to icol) | |
753 (if (> relpos 0) | |
754 (move-to-column (+ icol relpos)))))) | |
755 | |
756 (defun octave-indent-new-comment-line () | |
757 "Break Octave line at point, continuing comment if within one. | |
758 If within code, insert `octave-continuation-string' before breaking the | |
759 line. If within a string, signal an error. | |
760 The new line is properly indented." | |
761 (interactive) | |
762 (delete-horizontal-space) | |
763 (cond | |
764 ((octave-in-comment-p) | |
765 (indent-new-comment-line)) | |
766 ((octave-in-string-p) | |
767 (error "Cannot split a code line inside a string")) | |
768 (t | |
769 (insert (concat " " octave-continuation-string)) | |
770 (octave-reindent-then-newline-and-indent)))) | |
771 | |
772 (defun octave-indent-defun () | |
773 "Properly indents the Octave function which contains point." | |
774 (interactive) | |
775 (save-excursion | |
776 (octave-mark-defun) | |
777 (message "Indenting function...") | |
778 (indent-region (point) (mark) nil)) | |
779 (message "Indenting function...done.")) | |
780 | |
781 | |
782 ;;; Motion | |
783 (defun octave-next-code-line (&optional arg) | |
784 "Move ARG lines of Octave code forward (backward if ARG is negative). | |
785 Skips past all empty and comment lines. Default for ARG is 1. | |
786 | |
787 On success, return 0. Otherwise, go as far as possible and return -1." | |
788 (interactive "p") | |
789 (or arg (setq arg 1)) | |
790 (beginning-of-line) | |
791 (let ((n 0) | |
792 (inc (if (> arg 0) 1 -1))) | |
793 (while (and (/= arg 0) (= n 0)) | |
794 (setq n (forward-line inc)) | |
795 (while (and (= n 0) | |
796 (looking-at "\\s-*\\($\\|\\s<\\)")) | |
797 (setq n (forward-line inc))) | |
798 (setq arg (- arg inc))) | |
799 n)) | |
800 | |
801 (defun octave-previous-code-line (&optional arg) | |
802 "Move ARG lines of Octave code backward (forward if ARG is negative). | |
803 Skips past all empty and comment lines. Default for ARG is 1. | |
804 | |
805 On success, return 0. Otherwise, go as far as possible and return -1." | |
806 (interactive "p") | |
807 (or arg (setq arg 1)) | |
808 (octave-next-code-line (- arg))) | |
809 | |
810 (defun octave-beginning-of-line () | |
811 "Move point to beginning of current Octave line. | |
812 If on an empty or comment line, go to the beginning of that line. | |
813 Otherwise, move backward to the beginning of the first Octave code line | |
814 which is not inside a continuation statement, i.e., which does not | |
815 follow a code line ending in `...' or `\\', or is inside an open | |
816 parenthesis list." | |
817 (interactive) | |
818 (beginning-of-line) | |
819 (if (not (looking-at "\\s-*\\($\\|\\s<\\)")) | |
820 (while (or (condition-case nil | |
821 (progn | |
822 (up-list -1) | |
823 (beginning-of-line) | |
824 t) | |
825 (error nil)) | |
826 (and (or (looking-at "\\s-*\\($\\|\\s<\\)") | |
827 (save-excursion | |
828 (if (zerop (octave-previous-code-line)) | |
829 (looking-at octave-continuation-regexp)))) | |
830 (zerop (forward-line -1))))))) | |
831 | |
832 (defun octave-end-of-line () | |
833 "Move point to end of current Octave line. | |
834 If on an empty or comment line, go to the end of that line. | |
835 Otherwise, move forward to the end of the first Octave code line which | |
836 does not end in `...' or `\\' or is inside an open parenthesis list." | |
837 (interactive) | |
838 (end-of-line) | |
839 (if (save-excursion | |
840 (beginning-of-line) | |
841 (looking-at "\\s-*\\($\\|\\s<\\)")) | |
842 () | |
843 (while (or (condition-case nil | |
844 (progn | |
845 (up-list 1) | |
846 (end-of-line) | |
847 t) | |
848 (error nil)) | |
849 (and (save-excursion | |
850 (beginning-of-line) | |
851 (or (looking-at "\\s-*\\($\\|\\s<\\)") | |
852 (looking-at octave-continuation-regexp))) | |
853 (zerop (forward-line 1))))) | |
854 (end-of-line))) | |
855 | |
856 (defun octave-scan-blocks (from count depth) | |
857 "Scan from character number FROM by COUNT Octave begin-end blocks. | |
858 Returns the character number of the position thus found. | |
859 | |
860 If DEPTH is nonzero, block depth begins counting from that value. | |
861 Only places where the depth in blocks becomes zero are candidates for | |
862 stopping; COUNT such places are counted. | |
863 | |
864 If the beginning or end of the buffer is reached and the depth is wrong, | |
865 an error is signaled." | |
866 (let ((min-depth (if (> depth 0) 0 depth)) | |
867 (inc (if (> count 0) 1 -1))) | |
868 (save-excursion | |
869 (while (/= count 0) | |
870 (catch 'foo | |
871 (while (or (re-search-forward | |
872 octave-block-begin-or-end-regexp nil 'move inc) | |
873 (if (/= depth 0) | |
874 (error "Unbalanced block"))) | |
875 (if (octave-not-in-string-or-comment-p) | |
876 (progn | |
877 (cond | |
878 ((match-end 1) | |
879 (setq depth (+ depth inc))) | |
880 ((match-end 2) | |
881 (setq depth (- depth inc)))) | |
882 (if (< depth min-depth) | |
883 (error "Containing expression ends prematurely")) | |
884 (if (= depth 0) | |
885 (throw 'foo nil)))))) | |
886 (setq count (- count inc))) | |
887 (point)))) | |
888 | |
889 (defun octave-forward-block (&optional arg) | |
890 "Move forward across one balanced Octave begin-end block. | |
891 With argument, do it that many times. | |
892 Negative arg -N means move backward across N blocks." | |
893 (interactive "p") | |
894 (or arg (setq arg 1)) | |
895 (goto-char (or (octave-scan-blocks (point) arg 0) (buffer-end arg)))) | |
896 | |
897 (defun octave-backward-block (&optional arg) | |
898 "Move backward across one balanced Octave begin-end block. | |
899 With argument, do it that many times. | |
900 Negative arg -N means move forward across N blocks." | |
901 (interactive "p") | |
902 (or arg (setq arg 1)) | |
903 (octave-forward-block (- arg))) | |
904 | |
905 (defun octave-down-block (arg) | |
906 "Move forward down one begin-end block level of Octave code. | |
907 With argument, do this that many times. | |
908 A negative argument means move backward but still go down a level. | |
909 In Lisp programs, an argument is required." | |
910 (interactive "p") | |
911 (let ((inc (if (> arg 0) 1 -1))) | |
912 (while (/= arg 0) | |
913 (goto-char (or (octave-scan-blocks (point) inc -1) | |
914 (buffer-end arg))) | |
915 (setq arg (- arg inc))))) | |
916 | |
917 (defun octave-backward-up-block (arg) | |
918 "Move backward out of one begin-end block level of Octave code. | |
919 With argument, do this that many times. | |
920 A negative argument means move forward but still to a less deep spot. | |
921 In Lisp programs, an argument is required." | |
922 (interactive "p") | |
923 (octave-up-block (- arg))) | |
924 | |
925 (defun octave-up-block (arg) | |
926 "Move forward out of one begin-end block level of Octave code. | |
927 With argument, do this that many times. | |
928 A negative argument means move backward but still to a less deep spot. | |
929 In Lisp programs, an argument is required." | |
930 (interactive "p") | |
931 (let ((inc (if (> arg 0) 1 -1))) | |
932 (while (/= arg 0) | |
933 (goto-char (or (octave-scan-blocks (point) inc 1) | |
934 (buffer-end arg))) | |
935 (setq arg (- arg inc))))) | |
936 | |
937 (defun octave-mark-block () | |
938 "Put point at the beginning of this Octave block, mark at the end. | |
939 The block marked is the one that contains point or follows point." | |
940 (interactive) | |
941 (let ((pos (point))) | |
942 (if (or (and (octave-in-block-p) | |
943 (skip-syntax-forward "w")) | |
944 (condition-case nil | |
945 (progn | |
946 (octave-down-block 1) | |
947 (octave-in-block-p)) | |
948 (error nil))) | |
949 (progn | |
950 (octave-up-block -1) | |
951 (push-mark (point)) | |
952 (octave-forward-block) | |
953 (exchange-point-and-mark)) | |
954 (goto-char pos) | |
955 (message "No block to mark found")))) | |
956 | |
957 (defun octave-close-block () | |
958 "Close the current Octave block on a separate line. | |
959 An error is signaled if no block to close is found." | |
960 (interactive) | |
961 (let (bb-keyword) | |
962 (condition-case nil | |
963 (progn | |
964 (save-excursion | |
965 (octave-backward-up-block 1) | |
966 (setq bb-keyword (buffer-substring-no-properties | |
967 (match-beginning 1) (match-end 1)))) | |
968 (if (save-excursion | |
969 (beginning-of-line) | |
970 (looking-at "^\\s-*$")) | |
971 (indent-according-to-mode) | |
972 (octave-reindent-then-newline-and-indent)) | |
973 (insert (car (reverse | |
974 (assoc bb-keyword | |
975 octave-block-match-alist)))) | |
976 (octave-reindent-then-newline-and-indent) | |
977 t) | |
978 (error (message "No block to close found"))))) | |
979 | |
980 (defun octave-blink-matching-block-open () | |
981 "Blink the matching Octave begin block keyword. | |
982 If point is right after an Octave else or end type block keyword, move | |
983 cursor momentarily to the corresponding begin keyword. | |
984 Signal an error if the keywords are incompatible." | |
985 (interactive) | |
986 (let (bb-keyword bb-arg eb-keyword pos eol) | |
987 (if (and (octave-not-in-string-or-comment-p) | |
988 (looking-at "\\>") | |
989 (save-excursion | |
990 (skip-syntax-backward "w") | |
991 (looking-at octave-block-else-or-end-regexp))) | |
992 (save-excursion | |
993 (cond | |
994 ((match-end 1) | |
995 (setq eb-keyword | |
996 (buffer-substring-no-properties | |
997 (match-beginning 1) (match-end 1))) | |
998 (octave-backward-up-block 1)) | |
999 ((match-end 2) | |
1000 (setq eb-keyword | |
1001 (buffer-substring-no-properties | |
1002 (match-beginning 2) (match-end 2))) | |
1003 (octave-backward-block))) | |
1004 (setq pos (match-end 0) | |
1005 bb-keyword | |
1006 (buffer-substring-no-properties | |
1007 (match-beginning 0) pos) | |
1008 pos (+ pos 1) | |
1009 eol (octave-point 'eol) | |
1010 bb-arg | |
1011 (save-excursion | |
1012 (save-restriction | |
1013 (goto-char pos) | |
1014 (while (and (skip-syntax-forward "^<" eol) | |
1015 (octave-in-string-p) | |
1016 (not (forward-char 1)))) | |
1017 (skip-syntax-backward " ") | |
1018 (buffer-substring-no-properties pos (point))))) | |
1019 (if (member eb-keyword | |
1020 (cdr (assoc bb-keyword octave-block-match-alist))) | |
1021 (progn | |
1022 (message "Matches `%s %s'" bb-keyword bb-arg) | |
1023 (if (pos-visible-in-window-p) | |
1024 (sit-for blink-matching-delay))) | |
1025 (error "Block keywords `%s' and `%s' do not match" | |
1026 bb-keyword eb-keyword)))))) | |
1027 | |
1028 (defun octave-beginning-of-defun (&optional arg) | |
1029 "Move backward to the beginning of an Octave function. | |
1030 With positive ARG, do it that many times. Negative argument -N means | |
1031 move forward to Nth following beginning of a function. | |
1032 Returns t unless search stops at the beginning or end of the buffer." | |
1033 (interactive "p") | |
1034 (let* ((arg (or arg 1)) | |
1035 (inc (if (> arg 0) 1 -1)) | |
1036 (found)) | |
1037 (and (not (eobp)) | |
1038 (not (and (> arg 0) (looking-at "\\<function\\>"))) | |
1039 (skip-syntax-forward "w")) | |
1040 (while (and (/= arg 0) | |
1041 (setq found | |
1042 (re-search-backward "\\<function\\>" nil 'move inc))) | |
1043 (if (octave-not-in-string-or-comment-p) | |
1044 (setq arg (- arg inc)))) | |
1045 (if found | |
1046 (progn | |
1047 (and (< inc 0) (goto-char (match-beginning 0))) | |
1048 t)))) | |
1049 | |
1050 (defun octave-end-of-defun (&optional arg) | |
1051 "Move forward to the end of an Octave function. | |
1052 With positive ARG, do it that many times. Negative argument -N means | |
1053 move back to Nth preceding end of a function. | |
1054 | |
1055 An end of a function occurs right after the end keyword matching the | |
1056 `function' keyword that starts the function." | |
1057 (interactive "p") | |
1058 (or arg (setq arg 1)) | |
1059 (and (< arg 0) (skip-syntax-backward "w")) | |
1060 (and (> arg 0) (skip-syntax-forward "w")) | |
1061 (if (octave-in-defun-p) | |
1062 (setq arg (- arg 1))) | |
1063 (if (= arg 0) (setq arg -1)) | |
1064 (if (octave-beginning-of-defun (- arg)) | |
1065 (octave-forward-block))) | |
1066 | |
1067 (defun octave-mark-defun () | |
1068 "Put point at the beginning of this Octave function, mark at its end. | |
1069 The function marked is the one containing point or following point." | |
1070 (interactive) | |
1071 (let ((pos (point))) | |
1072 (if (or (octave-in-defun-p) | |
1073 (and (octave-beginning-of-defun -1) | |
1074 (octave-in-defun-p))) | |
1075 (progn | |
1076 (skip-syntax-forward "w") | |
1077 (octave-beginning-of-defun) | |
1078 (push-mark (point)) | |
1079 (octave-end-of-defun) | |
1080 (exchange-point-and-mark)) | |
1081 (goto-char pos) | |
1082 (message "No function to mark found")))) | |
1083 | |
1084 | |
1085 ;;; Filling | |
1086 (defun octave-auto-fill () | |
20181
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1087 "Perform auto-fill in Octave mode. |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1088 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
|
1089 otherwise." |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1090 (let (fc give-up) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1091 (if (or (null (setq fc (current-fill-column))) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1092 (save-excursion |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1093 (beginning-of-line) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1094 (and auto-fill-inhibit-regexp |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1095 (looking-at auto-fill-inhibit-regexp)))) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1096 nil ; Can't do anything |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1097 (if (and (not (octave-in-comment-p)) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1098 (> (current-column) fc)) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1099 (setq fc (- fc (+ (length octave-continuation-string) 1)))) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1100 (while (and (not give-up) (> (current-column) fc)) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1101 (let* ((opoint (point)) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1102 (fpoint |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1103 (save-excursion |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1104 (move-to-column (+ fc 1)) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1105 (skip-chars-backward "^ \t\n") |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1106 ;; 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
|
1107 ;; the first word |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1108 (if (bolp) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1109 (re-search-forward "[ \t]" opoint t)) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1110 ;; 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
|
1111 ;; comment chars |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1112 (if (save-excursion |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1113 (skip-syntax-backward " <") |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1114 (bolp)) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1115 (re-search-forward "[ \t]" (octave-point 'eol) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1116 'move)) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1117 ;; 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
|
1118 ;; continuation string, don't break here. |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1119 (if (and (not (octave-in-comment-p)) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1120 (looking-at |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1121 (concat "\\s-*" |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1122 (regexp-quote |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1123 octave-continuation-string) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1124 "\\s-*$"))) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1125 (end-of-line)) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1126 (skip-chars-backward " \t") |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1127 (point)))) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1128 (if (save-excursion |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1129 (goto-char fpoint) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1130 (not (or (bolp) (eolp)))) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1131 (let ((prev-column (current-column))) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1132 (if (save-excursion |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1133 (skip-chars-backward " \t") |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1134 (= (point) fpoint)) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1135 (progn |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1136 (octave-maybe-insert-continuation-string) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1137 (indent-new-comment-line t)) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1138 (save-excursion |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1139 (goto-char fpoint) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1140 (octave-maybe-insert-continuation-string) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1141 (indent-new-comment-line t))) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1142 (if (>= (current-column) prev-column) |
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 (setq give-up t)))) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1145 (not give-up)))) |
16901 | 1146 |
1147 (defun octave-fill-paragraph (&optional arg) | |
1148 "Fill paragraph of Octave code, handling Octave comments." | |
1149 (interactive "P") | |
1150 (save-excursion | |
1151 (let ((end (progn (forward-paragraph) (point))) | |
1152 (beg (progn | |
1153 (forward-paragraph -1) | |
1154 (skip-chars-forward " \t\n") | |
1155 (beginning-of-line) | |
1156 (point))) | |
1157 (cfc (current-fill-column)) | |
1158 (ind (calculate-octave-indent)) | |
1159 comment-prefix) | |
1160 (save-restriction | |
1161 (goto-char beg) | |
1162 (narrow-to-region beg end) | |
1163 (if (listp ind) (setq ind (nth 1 ind))) | |
1164 (while (not (eobp)) | |
1165 (condition-case nil | |
1166 (octave-indent-line ind) | |
1167 (error nil)) | |
1168 (if (and (> ind 0) | |
1169 (not | |
1170 (save-excursion | |
1171 (beginning-of-line) | |
1172 (looking-at "^\\s-*\\($\\|\\s<+\\)")))) | |
1173 (setq ind 0)) | |
1174 (move-to-column cfc) | |
1175 ;; First check whether we need to combine non-empty comment lines | |
1176 (if (and (< (current-column) cfc) | |
1177 (octave-in-comment-p) | |
1178 (not (save-excursion | |
1179 (beginning-of-line) | |
1180 (looking-at "^\\s-*\\s<+\\s-*$")))) | |
1181 ;; This is a nonempty comment line which does not extend | |
1182 ;; past the fill column. If it is followed by an nonempty | |
1183 ;; comment line with the same comment prefix, try to | |
1184 ;; combine them, and repeat this until either we reach the | |
1185 ;; fill-column or there is nothing more to combine. | |
1186 (progn | |
1187 ;; Get the comment prefix | |
1188 (save-excursion | |
1189 (beginning-of-line) | |
1190 (while (and (re-search-forward "\\s<+") | |
1191 (not (octave-in-comment-p)))) | |
1192 (setq comment-prefix (match-string 0))) | |
1193 ;; And keep combining ... | |
1194 (while (and (< (current-column) cfc) | |
1195 (save-excursion | |
1196 (forward-line 1) | |
1197 (and (looking-at | |
1198 (concat "^\\s-*" | |
1199 comment-prefix | |
1200 "\\S<")) | |
1201 (not (looking-at | |
1202 (concat "^\\s-*" | |
1203 comment-prefix | |
1204 "\\s-*$")))))) | |
1205 (delete-char 1) | |
1206 (re-search-forward comment-prefix) | |
1207 (delete-region (match-beginning 0) (match-end 0)) | |
1208 (fixup-whitespace) | |
1209 (move-to-column cfc)))) | |
20181
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1210 ;; 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
|
1211 ;; some other time ... |
16901 | 1212 (skip-chars-forward "^ \t\n") |
1213 (delete-horizontal-space) | |
1214 (if (or (< (current-column) cfc) | |
1215 (and (= (current-column) cfc) (eolp))) | |
1216 (forward-line 1) | |
1217 (if (not (eolp)) (insert " ")) | |
20181
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1218 (or (octave-auto-fill) |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1219 (forward-line 1))))) |
16901 | 1220 t))) |
1221 | |
1222 | |
1223 ;;; Completions | |
1224 (defun octave-initialize-completions () | |
1225 "Create an alist for Octave completions." | |
1226 (if octave-completion-alist | |
1227 () | |
1228 (setq octave-completion-alist | |
1229 (mapcar '(lambda (var) (cons var var)) | |
1230 (append octave-reserved-words | |
1231 octave-text-functions | |
1232 octave-variables))))) | |
1233 | |
1234 (defun octave-complete-symbol () | |
1235 "Perform completion on Octave symbol preceding point. | |
1236 Compare that symbol against Octave's reserved words and builtin | |
1237 variables." | |
1238 ;; This code taken from lisp-complete-symbol | |
1239 (interactive) | |
1240 (let* ((end (point)) | |
1241 (beg (save-excursion (backward-sexp 1) (point))) | |
1242 (string (buffer-substring-no-properties beg end)) | |
1243 (completion (try-completion string octave-completion-alist))) | |
1244 (cond ((eq completion t)) ; ??? | |
1245 ((null completion) | |
1246 (message "Can't find completion for \"%s\"" string) | |
1247 (ding)) | |
1248 ((not (string= string completion)) | |
1249 (delete-region beg end) | |
1250 (insert completion)) | |
1251 (t | |
1252 (let ((list (all-completions string octave-completion-alist)) | |
1253 (conf (current-window-configuration))) | |
1254 ;; Taken from comint.el | |
1255 (message "Making completion list...") | |
1256 (with-output-to-temp-buffer "*Completions*" | |
1257 (display-completion-list list)) | |
1258 (message "Hit space to flush") | |
1259 (let (key first) | |
1260 (if (save-excursion | |
1261 (set-buffer (get-buffer "*Completions*")) | |
1262 (setq key (read-key-sequence nil) | |
1263 first (aref key 0)) | |
1264 (and (consp first) (consp (event-start first)) | |
1265 (eq (window-buffer (posn-window (event-start | |
1266 first))) | |
1267 (get-buffer "*Completions*")) | |
1268 (eq (key-binding key) 'mouse-choose-completion))) | |
1269 (progn | |
1270 (mouse-choose-completion first) | |
1271 (set-window-configuration conf)) | |
1272 (if (eq first ?\ ) | |
1273 (set-window-configuration conf) | |
1274 (setq unread-command-events | |
1275 (listify-key-sequence key)))))))))) | |
1276 | |
1277 | |
1278 ;;; Electric characters && friends | |
1279 (defun octave-reindent-then-newline-and-indent () | |
1280 "Reindent current Octave line, insert newline, and indent the new line. | |
1281 If Abbrev mode is on, expand abbrevs first." | |
1282 (interactive) | |
1283 (if abbrev-mode (expand-abbrev)) | |
1284 (if octave-blink-matching-block | |
1285 (octave-blink-matching-block-open)) | |
1286 (save-excursion | |
1287 (delete-region (point) (progn (skip-chars-backward " \t") (point))) | |
1288 (indent-according-to-mode)) | |
1289 (insert "\n") | |
1290 (indent-according-to-mode)) | |
1291 | |
1292 (defun octave-electric-semi () | |
1293 "Insert a semicolon in Octave mode. | |
20181
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1294 Maybe expand abbrevs and blink matching block open keywords. |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1295 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
|
1296 Insert a newline if `octave-auto-newline' is non-nil." |
16901 | 1297 (interactive) |
1298 (if (not (octave-not-in-string-or-comment-p)) | |
1299 (insert ";") | |
1300 (if abbrev-mode (expand-abbrev)) | |
1301 (if octave-blink-matching-block | |
1302 (octave-blink-matching-block-open)) | |
20181
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1303 (if octave-auto-indent |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1304 (indent-according-to-mode)) |
16901 | 1305 (insert ";") |
1306 (if octave-auto-newline | |
1307 (newline-and-indent)))) | |
1308 | |
1309 (defun octave-electric-space () | |
1310 "Insert a space in Octave mode. | |
20181
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1311 Maybe expand abbrevs and blink matching block open keywords. |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1312 Reindent the line of `octave-auto-indent' is non-nil." |
16901 | 1313 (interactive) |
1314 (setq last-command-char ? ) | |
1315 (if (not (octave-not-in-string-or-comment-p)) | |
1316 (progn | |
1317 (indent-according-to-mode) | |
1318 (self-insert-command 1)) | |
1319 (if abbrev-mode (expand-abbrev)) | |
1320 (if octave-blink-matching-block | |
1321 (octave-blink-matching-block-open)) | |
20181
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1322 (if (and octave-auto-indent |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1323 (save-excursion |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1324 (skip-syntax-backward " ") |
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1325 (not (bolp)))) |
16901 | 1326 (indent-according-to-mode)) |
1327 (self-insert-command 1))) | |
1328 | |
1329 (defun octave-abbrev-start () | |
1330 "Start entering an Octave abbreviation. | |
1331 If Abbrev mode is turned on, typing ` (grave accent) followed by ? or | |
1332 \\[help-command] lists all Octave abbrevs. Any other key combination is | |
1333 executed normally. | |
1334 Note that all Octave mode abbrevs start with a grave accent." | |
1335 (interactive) | |
1336 (if (not abbrev-mode) | |
1337 (self-insert-command 1) | |
1338 (let (c) | |
1339 (insert last-command-char) | |
1340 (if (or (eq (setq c (read-event)) ??) | |
1341 (eq c help-char)) | |
1342 (let ((abbrev-table-name-list '(octave-mode-abbrev-table))) | |
1343 (list-abbrevs)) | |
1344 (setq unread-command-events (list c)))))) | |
1345 | |
1346 (defun octave-insert-defun (name args vals) | |
1347 "Insert an Octave function skeleton. | |
1348 Prompt for the function's name, arguments and return values (to be | |
1349 entered without parens)." | |
1350 (interactive | |
1351 (list | |
1352 (read-from-minibuffer "Function name: " | |
1353 (substring (buffer-name) 0 -2)) | |
1354 (read-from-minibuffer "Arguments: ") | |
1355 (read-from-minibuffer "Return values: "))) | |
1356 (let ((string (format "%s %s (%s)" | |
1357 (cond | |
1358 ((string-equal vals "") | |
1359 vals) | |
1360 ((string-match "[ ,]" vals) | |
1361 (concat " [" vals "] =")) | |
1362 (t | |
1363 (concat " " vals " ="))) | |
1364 name | |
1365 args)) | |
1366 (prefix octave-block-comment-start)) | |
1367 (if (not (bobp)) (newline)) | |
1368 (insert "function" string) | |
1369 (indent-according-to-mode) | |
1370 (newline 2) | |
1371 (insert prefix "usage: " string) | |
1372 (reindent-then-newline-and-indent) | |
1373 (insert prefix) | |
1374 (reindent-then-newline-and-indent) | |
1375 (insert prefix) | |
1376 (indent-according-to-mode) | |
1377 (save-excursion | |
1378 (newline 2) | |
1379 (insert "endfunction") | |
1380 (indent-according-to-mode)))) | |
1381 | |
1382 | |
1383 ;;; Menu | |
1384 (defun octave-add-octave-menu () | |
1385 "Adds the `Octave' menu to the menu bar in Octave mode." | |
1386 (require 'easymenu) | |
1387 (easy-menu-define octave-mode-menu-map octave-mode-map | |
1388 "Menu keymap for Octave mode." octave-mode-menu) | |
1389 (easy-menu-add octave-mode-menu-map octave-mode-map)) | |
1390 | |
1391 | |
1392 ;;; Communication with the inferior Octave process | |
1393 (defun octave-kill-process () | |
1394 "Kill inferior Octave process and its buffer." | |
1395 (interactive) | |
1396 (if inferior-octave-process | |
1397 (progn | |
1398 (process-send-string inferior-octave-process "quit;\n") | |
1399 (accept-process-output inferior-octave-process))) | |
1400 (if inferior-octave-buffer | |
1401 (kill-buffer inferior-octave-buffer))) | |
1402 | |
1403 (defun octave-show-process-buffer () | |
1404 "Make sure that `inferior-octave-buffer' is displayed." | |
1405 (interactive) | |
1406 (if (get-buffer inferior-octave-buffer) | |
1407 (display-buffer inferior-octave-buffer) | |
1408 (message "No buffer named %s" inferior-octave-buffer))) | |
1409 | |
1410 (defun octave-hide-process-buffer () | |
1411 "Delete all windows that display `inferior-octave-buffer'." | |
1412 (interactive) | |
1413 (if (get-buffer inferior-octave-buffer) | |
1414 (delete-windows-on inferior-octave-buffer) | |
1415 (message "No buffer named %s" inferior-octave-buffer))) | |
1416 | |
1417 (defun octave-send-region (beg end) | |
1418 "Send current region to the inferior Octave process." | |
1419 (interactive "r") | |
1420 (inferior-octave t) | |
1421 (let ((proc inferior-octave-process) | |
1422 (string (buffer-substring-no-properties beg end)) | |
1423 line) | |
1424 (save-excursion | |
1425 (set-buffer inferior-octave-buffer) | |
1426 (setq inferior-octave-output-list nil) | |
1427 (while (not (string-equal string "")) | |
1428 (if (string-match "\n" string) | |
1429 (setq line (substring string 0 (match-beginning 0)) | |
1430 string (substring string (match-end 0))) | |
1431 (setq line string string "")) | |
1432 (setq inferior-octave-receive-in-progress t) | |
1433 (inferior-octave-send-list-and-digest (list (concat line "\n"))) | |
1434 (while inferior-octave-receive-in-progress | |
1435 (accept-process-output proc)) | |
1436 (insert-before-markers | |
1437 (mapconcat 'identity | |
1438 (append | |
1439 (if octave-send-echo-input (list line) (list "")) | |
1440 (mapcar 'inferior-octave-strip-ctrl-g | |
1441 inferior-octave-output-list) | |
1442 (list inferior-octave-output-string)) | |
1443 "\n"))))) | |
1444 (if octave-send-show-buffer | |
1445 (display-buffer inferior-octave-buffer))) | |
1446 | |
1447 (defun octave-send-block () | |
1448 "Send current Octave block to the inferior Octave process." | |
1449 (interactive) | |
1450 (save-excursion | |
1451 (octave-mark-block) | |
1452 (octave-send-region (point) (mark)))) | |
1453 | |
1454 (defun octave-send-defun () | |
1455 "Send current Octave function to the inferior Octave process." | |
1456 (interactive) | |
1457 (save-excursion | |
1458 (octave-mark-defun) | |
1459 (octave-send-region (point) (mark)))) | |
1460 | |
1461 (defun octave-send-line (&optional arg) | |
1462 "Send current Octave code line to the inferior Octave process. | |
1463 With positive prefix ARG, send that many lines. | |
1464 If `octave-send-line-auto-forward' is non-nil, go to the next unsent | |
1465 code line." | |
1466 (interactive "P") | |
1467 (or arg (setq arg 1)) | |
1468 (if (> arg 0) | |
1469 (let (beg end) | |
1470 (beginning-of-line) | |
1471 (setq beg (point)) | |
1472 (octave-next-code-line (- arg 1)) | |
1473 (end-of-line) | |
1474 (setq end (point)) | |
1475 (if octave-send-line-auto-forward | |
1476 (octave-next-code-line 1)) | |
1477 (octave-send-region beg end)))) | |
1478 | |
1479 (defun octave-eval-print-last-sexp () | |
1480 "Evaluate Octave sexp before point and print value into current buffer." | |
1481 (interactive) | |
1482 (inferior-octave t) | |
1483 (let ((standard-output (current-buffer)) | |
1484 (print-escape-newlines nil) | |
1485 (opoint (point))) | |
1486 (terpri) | |
1487 (prin1 | |
1488 (save-excursion | |
1489 (forward-sexp -1) | |
1490 (inferior-octave-send-list-and-digest | |
1491 (list (concat (buffer-substring-no-properties (point) opoint) | |
1492 "\n"))) | |
1493 (mapconcat 'identity inferior-octave-output-list "\n"))) | |
1494 (terpri))) | |
16905
a93836c8b52b
Merge in octave.el; don't require octave.el.
Richard M. Stallman <rms@gnu.org>
parents:
16902
diff
changeset
|
1495 |
a93836c8b52b
Merge in octave.el; don't require octave.el.
Richard M. Stallman <rms@gnu.org>
parents:
16902
diff
changeset
|
1496 ;;; Bug reporting |
a93836c8b52b
Merge in octave.el; don't require octave.el.
Richard M. Stallman <rms@gnu.org>
parents:
16902
diff
changeset
|
1497 (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
|
1498 "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
|
1499 (interactive) |
a93836c8b52b
Merge in octave.el; don't require octave.el.
Richard M. Stallman <rms@gnu.org>
parents:
16902
diff
changeset
|
1500 (require 'reporter) |
a93836c8b52b
Merge in octave.el; don't require octave.el.
Richard M. Stallman <rms@gnu.org>
parents:
16902
diff
changeset
|
1501 (and |
a93836c8b52b
Merge in octave.el; don't require octave.el.
Richard M. Stallman <rms@gnu.org>
parents:
16902
diff
changeset
|
1502 (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
|
1503 (reporter-submit-bug-report |
a93836c8b52b
Merge in octave.el; don't require octave.el.
Richard M. Stallman <rms@gnu.org>
parents:
16902
diff
changeset
|
1504 octave-maintainer-address |
a93836c8b52b
Merge in octave.el; don't require octave.el.
Richard M. Stallman <rms@gnu.org>
parents:
16902
diff
changeset
|
1505 (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
|
1506 (list |
20181
fe0f0a9bb43f
(octave-auto-indent): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
17533
diff
changeset
|
1507 'octave-auto-indent |
16905
a93836c8b52b
Merge in octave.el; don't require octave.el.
Richard M. Stallman <rms@gnu.org>
parents:
16902
diff
changeset
|
1508 'octave-auto-newline |
a93836c8b52b
Merge in octave.el; don't require octave.el.
Richard M. Stallman <rms@gnu.org>
parents:
16902
diff
changeset
|
1509 'octave-blink-matching-block |
a93836c8b52b
Merge in octave.el; don't require octave.el.
Richard M. Stallman <rms@gnu.org>
parents:
16902
diff
changeset
|
1510 'octave-block-offset |
a93836c8b52b
Merge in octave.el; don't require octave.el.
Richard M. Stallman <rms@gnu.org>
parents:
16902
diff
changeset
|
1511 'octave-comment-char |
a93836c8b52b
Merge in octave.el; don't require octave.el.
Richard M. Stallman <rms@gnu.org>
parents:
16902
diff
changeset
|
1512 'octave-continuation-offset |
a93836c8b52b
Merge in octave.el; don't require octave.el.
Richard M. Stallman <rms@gnu.org>
parents:
16902
diff
changeset
|
1513 'octave-continuation-string |
a93836c8b52b
Merge in octave.el; don't require octave.el.
Richard M. Stallman <rms@gnu.org>
parents:
16902
diff
changeset
|
1514 'octave-help-files |
a93836c8b52b
Merge in octave.el; don't require octave.el.
Richard M. Stallman <rms@gnu.org>
parents:
16902
diff
changeset
|
1515 'octave-mode-startup-message |
a93836c8b52b
Merge in octave.el; don't require octave.el.
Richard M. Stallman <rms@gnu.org>
parents:
16902
diff
changeset
|
1516 'octave-send-echo-input |
a93836c8b52b
Merge in octave.el; don't require octave.el.
Richard M. Stallman <rms@gnu.org>
parents:
16902
diff
changeset
|
1517 '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
|
1518 'octave-send-show-buffer)))) |
a93836c8b52b
Merge in octave.el; don't require octave.el.
Richard M. Stallman <rms@gnu.org>
parents:
16902
diff
changeset
|
1519 |
a93836c8b52b
Merge in octave.el; don't require octave.el.
Richard M. Stallman <rms@gnu.org>
parents:
16902
diff
changeset
|
1520 ;;; provide ourself |
a93836c8b52b
Merge in octave.el; don't require octave.el.
Richard M. Stallman <rms@gnu.org>
parents:
16902
diff
changeset
|
1521 |
16911
123d19079d9f
Delete explicit autoload calls.
Richard M. Stallman <rms@gnu.org>
parents:
16905
diff
changeset
|
1522 (provide 'octave-mod) |
16905
a93836c8b52b
Merge in octave.el; don't require octave.el.
Richard M. Stallman <rms@gnu.org>
parents:
16902
diff
changeset
|
1523 |
a93836c8b52b
Merge in octave.el; don't require octave.el.
Richard M. Stallman <rms@gnu.org>
parents:
16902
diff
changeset
|
1524 ;;; octave-mod.el ends here |