Mercurial > emacs
annotate lisp/progmodes/octave-inf.el @ 98117:3c5d54685977
*** empty log message ***
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Wed, 10 Sep 2008 02:31:58 +0000 |
parents | 52b7a8c22af5 |
children | a9dc0e7c3f2b |
rev | line source |
---|---|
17517 | 1 ;;; octave-inf.el --- running Octave as an inferior Emacs process |
16903 | 2 |
79717 | 3 ;; Copyright (C) 1997, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 |
64699
629afbe74e61
Update copyright for release of 22.1 for progmodes directory.
Nick Roberts <nickrob@snap.net.nz>
parents:
64085
diff
changeset
|
4 ;; Free Software Foundation, Inc. |
16903 | 5 |
65152
7a3342784b7e
Change Author and Maintainer address.
Eli Zaretskii <eliz@gnu.org>
parents:
64699
diff
changeset
|
6 ;; Author: Kurt Hornik <Kurt.Hornik@wu-wien.ac.at> |
16903 | 7 ;; Author: John Eaton <jwe@bevo.che.wisc.edu> |
65152
7a3342784b7e
Change Author and Maintainer address.
Eli Zaretskii <eliz@gnu.org>
parents:
64699
diff
changeset
|
8 ;; Maintainer: Kurt Hornik <Kurt.Hornik@wu-wien.ac.at> |
16903 | 9 ;; Keywords: languages |
10 | |
11 ;; This file is part of GNU Emacs. | |
12 | |
94673
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79717
diff
changeset
|
13 ;; GNU Emacs is free software: you can redistribute it and/or modify |
16903 | 14 ;; it under the terms of the GNU General Public License as published by |
94673
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79717
diff
changeset
|
15 ;; the Free Software Foundation, either version 3 of the License, or |
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79717
diff
changeset
|
16 ;; (at your option) any later version. |
16903 | 17 |
18 ;; GNU Emacs is distributed in the hope that it will be useful, | |
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 ;; GNU General Public License for more details. | |
22 | |
23 ;; You should have received a copy of the GNU General Public License | |
94673
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79717
diff
changeset
|
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
16903 | 25 |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
30902
diff
changeset
|
26 ;;; Commentary: |
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
30902
diff
changeset
|
27 |
16903 | 28 ;;; Code: |
29 | |
16904
2bc5f76917e0
Require octave-mod, not octave.
Richard M. Stallman <rms@gnu.org>
parents:
16903
diff
changeset
|
30 (require 'octave-mod) |
16903 | 31 (require 'comint) |
32 | |
20781 | 33 (defgroup octave-inferior nil |
34 "Running Octave as an inferior Emacs process." | |
35 :group 'octave) | |
16903 | 36 |
20781 | 37 (defcustom inferior-octave-program "octave" |
71665
611496c32b32
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
38 "Program invoked by `inferior-octave'." |
20781 | 39 :type 'string |
40 :group 'octave-inferior) | |
41 | |
42 (defcustom inferior-octave-prompt | |
78198
dcfe1564f1a0
(inferior-octave-prompt): Accept .exe.
Richard M. Stallman <rms@gnu.org>
parents:
75347
diff
changeset
|
43 "\\(^octave\\(\\|.bin\\|.exe\\)\\(-[.0-9]+\\)?\\(:[0-9]+\\)?\\|^debug\\|^\\)>+ " |
71665
611496c32b32
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
44 "Regexp to match prompts for the inferior Octave process." |
20781 | 45 :type 'regexp |
46 :group 'octave-inferior) | |
16903 | 47 |
20781 | 48 (defcustom inferior-octave-startup-file nil |
71665
611496c32b32
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
49 "Name of the inferior Octave startup file. |
16903 | 50 The contents of this file are sent to the inferior Octave process on |
20781 | 51 startup." |
52 :type '(choice (const :tag "None" nil) | |
53 file) | |
54 :group 'octave-inferior) | |
16903 | 55 |
25719
f440228994ba
(inferior-octave-startup): Ensure -i and --no-line-editing are passed
Stephen Eglen <stephen@gnu.org>
parents:
25568
diff
changeset
|
56 (defcustom inferior-octave-startup-args nil |
71665
611496c32b32
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
57 "List of command line arguments for the inferior Octave process. |
16903 | 58 For example, for suppressing the startup message and using `traditional' |
20781 | 59 mode, set this to (\"-q\" \"--traditional\")." |
60 :type '(repeat string) | |
61 :group 'octave-inferior) | |
16903 | 62 |
71665
611496c32b32
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
63 (defvar inferior-octave-mode-map |
611496c32b32
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
64 (let ((map (make-sparse-keymap))) |
611496c32b32
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
65 (set-keymap-parent map comint-mode-map) |
16903 | 66 (define-key map "\t" 'comint-dynamic-complete) |
67 (define-key map "\M-?" 'comint-dynamic-list-filename-completions) | |
68 (define-key map "\C-c\C-l" 'inferior-octave-dynamic-list-input-ring) | |
69 (define-key map [menu-bar inout list-history] | |
70 '("List Input History" . inferior-octave-dynamic-list-input-ring)) | |
71 (define-key map "\C-c\C-h" 'octave-help) | |
71665
611496c32b32
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
72 map) |
611496c32b32
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
73 "Keymap used in Inferior Octave mode.") |
16903 | 74 |
71665
611496c32b32
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
75 (defvar inferior-octave-mode-syntax-table |
16903 | 76 (let ((table (make-syntax-table))) |
77 (modify-syntax-entry ?\` "w" table) | |
78 (modify-syntax-entry ?\# "<" table) | |
79 (modify-syntax-entry ?\n ">" table) | |
71665
611496c32b32
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
80 table) |
611496c32b32
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
81 "Syntax table in use in inferior-octave-mode buffers.") |
16903 | 82 |
20781 | 83 (defcustom inferior-octave-mode-hook nil |
84 "*Hook to be run when Inferior Octave mode is started." | |
85 :type 'hook | |
86 :group 'octave-inferior) | |
16903 | 87 |
88 (defvar inferior-octave-font-lock-keywords | |
89 (list | |
90 (cons inferior-octave-prompt 'font-lock-type-face)) | |
91 ;; Could certainly do more font locking in inferior Octave ... | |
92 "Additional expressions to highlight in Inferior Octave mode.") | |
93 | |
30902
ffe3b5100238
Add compatibility definition of comint-line-beginning-position.
Miles Bader <miles@gnu.org>
parents:
30646
diff
changeset
|
94 |
ffe3b5100238
Add compatibility definition of comint-line-beginning-position.
Miles Bader <miles@gnu.org>
parents:
30646
diff
changeset
|
95 ;;; Compatibility functions |
ffe3b5100238
Add compatibility definition of comint-line-beginning-position.
Miles Bader <miles@gnu.org>
parents:
30646
diff
changeset
|
96 (if (not (fboundp 'comint-line-beginning-position)) |
ffe3b5100238
Add compatibility definition of comint-line-beginning-position.
Miles Bader <miles@gnu.org>
parents:
30646
diff
changeset
|
97 ;; comint-line-beginning-position is defined in Emacs 21 |
ffe3b5100238
Add compatibility definition of comint-line-beginning-position.
Miles Bader <miles@gnu.org>
parents:
30646
diff
changeset
|
98 (defun comint-line-beginning-position () |
ffe3b5100238
Add compatibility definition of comint-line-beginning-position.
Miles Bader <miles@gnu.org>
parents:
30646
diff
changeset
|
99 "Returns the buffer position of the beginning of the line, after any prompt. |
ffe3b5100238
Add compatibility definition of comint-line-beginning-position.
Miles Bader <miles@gnu.org>
parents:
30646
diff
changeset
|
100 The prompt is assumed to be any text at the beginning of the line matching |
ffe3b5100238
Add compatibility definition of comint-line-beginning-position.
Miles Bader <miles@gnu.org>
parents:
30646
diff
changeset
|
101 the regular expression `comint-prompt-regexp', a buffer local variable." |
ffe3b5100238
Add compatibility definition of comint-line-beginning-position.
Miles Bader <miles@gnu.org>
parents:
30646
diff
changeset
|
102 (save-excursion (comint-bol nil) (point)))) |
ffe3b5100238
Add compatibility definition of comint-line-beginning-position.
Miles Bader <miles@gnu.org>
parents:
30646
diff
changeset
|
103 |
ffe3b5100238
Add compatibility definition of comint-line-beginning-position.
Miles Bader <miles@gnu.org>
parents:
30646
diff
changeset
|
104 |
16903 | 105 (defvar inferior-octave-output-list nil) |
106 (defvar inferior-octave-output-string nil) | |
107 (defvar inferior-octave-receive-in-progress nil) | |
108 | |
109 (defvar inferior-octave-startup-hook nil) | |
110 | |
111 (defvar inferior-octave-complete-impossible nil | |
112 "Non-nil means that `inferior-octave-complete' is impossible.") | |
113 | |
73500
d25ce2f322cb
* progmodes/octave-inf.el (inferior-octave-has-built-in-variables):
Chong Yidong <cyd@stupidchicken.com>
parents:
71665
diff
changeset
|
114 (defvar inferior-octave-has-built-in-variables nil |
d25ce2f322cb
* progmodes/octave-inf.el (inferior-octave-has-built-in-variables):
Chong Yidong <cyd@stupidchicken.com>
parents:
71665
diff
changeset
|
115 "Non-nil means that Octave has built-in variables.") |
d25ce2f322cb
* progmodes/octave-inf.el (inferior-octave-has-built-in-variables):
Chong Yidong <cyd@stupidchicken.com>
parents:
71665
diff
changeset
|
116 |
16903 | 117 (defvar inferior-octave-dynamic-complete-functions |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38436
diff
changeset
|
118 '(inferior-octave-complete comint-dynamic-complete-filename) |
16903 | 119 "List of functions called to perform completion for inferior Octave. |
120 This variable is used to initialize `comint-dynamic-complete-functions' | |
121 in the Inferior Octave buffer.") | |
122 | |
123 (defun inferior-octave-mode () | |
124 "Major mode for interacting with an inferior Octave process. | |
125 Runs Octave as a subprocess of Emacs, with Octave I/O through an Emacs | |
126 buffer. | |
127 | |
128 Entry to this mode successively runs the hooks `comint-mode-hook' and | |
129 `inferior-octave-mode-hook'." | |
130 (interactive) | |
63411
1244410f3457
(inferior-octave-mode): Use delay-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
62772
diff
changeset
|
131 (delay-mode-hooks (comint-mode)) |
16903 | 132 (setq comint-prompt-regexp inferior-octave-prompt |
133 major-mode 'inferior-octave-mode | |
134 mode-name "Inferior Octave" | |
135 mode-line-process '(":%s") | |
136 local-abbrev-table octave-abbrev-table) | |
137 (use-local-map inferior-octave-mode-map) | |
138 (set-syntax-table inferior-octave-mode-syntax-table) | |
139 | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38436
diff
changeset
|
140 (make-local-variable 'comment-start) |
16903 | 141 (setq comment-start octave-comment-start) |
142 (make-local-variable 'comment-end) | |
143 (setq comment-end "") | |
144 (make-local-variable 'comment-column) | |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38436
diff
changeset
|
145 (setq comment-column 32) |
16903 | 146 (make-local-variable 'comment-start-skip) |
147 (setq comment-start-skip octave-comment-start-skip) | |
148 | |
149 (make-local-variable 'font-lock-defaults) | |
150 (setq font-lock-defaults '(inferior-octave-font-lock-keywords nil nil)) | |
151 | |
152 (setq comint-input-ring-file-name | |
153 (or (getenv "OCTAVE_HISTFILE") "~/.octave_hist") | |
78880
0d16f8f68da5
(inferior-octave-mode): Use add-hook to
Francesco Potortì <pot@gnu.org>
parents:
78234
diff
changeset
|
154 comint-input-ring-size (or (getenv "OCTAVE_HISTSIZE") 1024)) |
71665
611496c32b32
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
155 (set (make-local-variable 'comint-dynamic-complete-functions) |
611496c32b32
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
156 inferior-octave-dynamic-complete-functions) |
78880
0d16f8f68da5
(inferior-octave-mode): Use add-hook to
Francesco Potortì <pot@gnu.org>
parents:
78234
diff
changeset
|
157 (add-hook 'comint-input-filter-functions |
0d16f8f68da5
(inferior-octave-mode): Use add-hook to
Francesco Potortì <pot@gnu.org>
parents:
78234
diff
changeset
|
158 'inferior-octave-directory-tracker nil t) |
16903 | 159 (comint-read-input-ring t) |
160 | |
62772
f2892faa87d4
* progmodes/ada-mode.el (ada-mode):
Lute Kamstra <lute@gnu.org>
parents:
52952
diff
changeset
|
161 (run-mode-hooks 'inferior-octave-mode-hook)) |
16903 | 162 |
163 ;;;###autoload | |
164 (defun inferior-octave (&optional arg) | |
165 "Run an inferior Octave process, I/O via `inferior-octave-buffer'. | |
166 This buffer is put in Inferior Octave mode. See `inferior-octave-mode'. | |
167 | |
168 Unless ARG is non-nil, switches to this buffer. | |
169 | |
170 The elements of the list `inferior-octave-startup-args' are sent as | |
171 command line arguments to the inferior Octave process on startup. | |
172 | |
173 Additional commands to be executed on startup can be provided either in | |
174 the file specified by `inferior-octave-startup-file' or by the default | |
175 startup file, `~/.emacs-octave'." | |
176 (interactive "P") | |
177 (let ((buffer inferior-octave-buffer)) | |
178 (get-buffer-create buffer) | |
179 (if (comint-check-proc buffer) | |
180 () | |
181 (save-excursion | |
182 (set-buffer buffer) | |
183 (comint-mode) | |
184 (inferior-octave-startup) | |
185 (inferior-octave-mode))) | |
186 (if (not arg) | |
187 (pop-to-buffer buffer)))) | |
188 | |
189 ;;;###autoload | |
190 (defalias 'run-octave 'inferior-octave) | |
191 | |
192 (defun inferior-octave-startup () | |
193 "Start an inferior Octave process." | |
194 (let ((proc (comint-exec-1 | |
195 (substring inferior-octave-buffer 1 -1) | |
196 inferior-octave-buffer | |
197 inferior-octave-program | |
25719
f440228994ba
(inferior-octave-startup): Ensure -i and --no-line-editing are passed
Stephen Eglen <stephen@gnu.org>
parents:
25568
diff
changeset
|
198 (append (list "-i" "--no-line-editing") |
f440228994ba
(inferior-octave-startup): Ensure -i and --no-line-editing are passed
Stephen Eglen <stephen@gnu.org>
parents:
25568
diff
changeset
|
199 inferior-octave-startup-args)))) |
16903 | 200 (set-process-filter proc 'inferior-octave-output-digest) |
201 (setq comint-ptyp process-connection-type | |
202 inferior-octave-process proc | |
203 inferior-octave-output-list nil | |
204 inferior-octave-output-string nil | |
205 inferior-octave-receive-in-progress t) | |
206 | |
207 ;; This may look complicated ... However, we need to make sure that | |
208 ;; we additional startup code only AFTER Octave is ready (otherwise, | |
209 ;; output may be mixed up). Hence, we need to digest the Octave | |
210 ;; output to see when it issues a prompt. | |
211 (while inferior-octave-receive-in-progress | |
212 (accept-process-output inferior-octave-process)) | |
213 (goto-char (point-max)) | |
214 (set-marker (process-mark proc) (point)) | |
215 (insert-before-markers | |
216 (concat | |
217 (if (not (bobp)) "\n") | |
218 (if inferior-octave-output-list | |
219 (concat (mapconcat | |
220 'identity inferior-octave-output-list "\n") | |
221 "\n")))) | |
67129
e0b37eeb2f0b
(inferior-octave-startup): Force a non-empty string for secondary prompt PS2.
Eli Zaretskii <eliz@gnu.org>
parents:
65431
diff
changeset
|
222 |
73500
d25ce2f322cb
* progmodes/octave-inf.el (inferior-octave-has-built-in-variables):
Chong Yidong <cyd@stupidchicken.com>
parents:
71665
diff
changeset
|
223 ;; Find out whether Octave has built-in variables. |
d25ce2f322cb
* progmodes/octave-inf.el (inferior-octave-has-built-in-variables):
Chong Yidong <cyd@stupidchicken.com>
parents:
71665
diff
changeset
|
224 (inferior-octave-send-list-and-digest |
d25ce2f322cb
* progmodes/octave-inf.el (inferior-octave-has-built-in-variables):
Chong Yidong <cyd@stupidchicken.com>
parents:
71665
diff
changeset
|
225 (list "exist \"LOADPATH\"\n")) |
d25ce2f322cb
* progmodes/octave-inf.el (inferior-octave-has-built-in-variables):
Chong Yidong <cyd@stupidchicken.com>
parents:
71665
diff
changeset
|
226 (setq inferior-octave-has-built-in-variables |
d25ce2f322cb
* progmodes/octave-inf.el (inferior-octave-has-built-in-variables):
Chong Yidong <cyd@stupidchicken.com>
parents:
71665
diff
changeset
|
227 (string-match "101$" (car inferior-octave-output-list))) |
d25ce2f322cb
* progmodes/octave-inf.el (inferior-octave-has-built-in-variables):
Chong Yidong <cyd@stupidchicken.com>
parents:
71665
diff
changeset
|
228 |
67129
e0b37eeb2f0b
(inferior-octave-startup): Force a non-empty string for secondary prompt PS2.
Eli Zaretskii <eliz@gnu.org>
parents:
65431
diff
changeset
|
229 ;; An empty secondary prompt, as e.g. obtained by '--braindead', |
e0b37eeb2f0b
(inferior-octave-startup): Force a non-empty string for secondary prompt PS2.
Eli Zaretskii <eliz@gnu.org>
parents:
65431
diff
changeset
|
230 ;; means trouble. |
e0b37eeb2f0b
(inferior-octave-startup): Force a non-empty string for secondary prompt PS2.
Eli Zaretskii <eliz@gnu.org>
parents:
65431
diff
changeset
|
231 (inferior-octave-send-list-and-digest (list "PS2\n")) |
73500
d25ce2f322cb
* progmodes/octave-inf.el (inferior-octave-has-built-in-variables):
Chong Yidong <cyd@stupidchicken.com>
parents:
71665
diff
changeset
|
232 (if (string-match "\\(PS2\\|ans\\) = *$" (car inferior-octave-output-list)) |
d25ce2f322cb
* progmodes/octave-inf.el (inferior-octave-has-built-in-variables):
Chong Yidong <cyd@stupidchicken.com>
parents:
71665
diff
changeset
|
233 (inferior-octave-send-list-and-digest |
d25ce2f322cb
* progmodes/octave-inf.el (inferior-octave-has-built-in-variables):
Chong Yidong <cyd@stupidchicken.com>
parents:
71665
diff
changeset
|
234 (list (if inferior-octave-has-built-in-variables |
d25ce2f322cb
* progmodes/octave-inf.el (inferior-octave-has-built-in-variables):
Chong Yidong <cyd@stupidchicken.com>
parents:
71665
diff
changeset
|
235 "PS2 = \"> \"\n" |
d25ce2f322cb
* progmodes/octave-inf.el (inferior-octave-has-built-in-variables):
Chong Yidong <cyd@stupidchicken.com>
parents:
71665
diff
changeset
|
236 "PS2 (\"> \");\n")))) |
67129
e0b37eeb2f0b
(inferior-octave-startup): Force a non-empty string for secondary prompt PS2.
Eli Zaretskii <eliz@gnu.org>
parents:
65431
diff
changeset
|
237 |
16903 | 238 ;; O.k., now we are ready for the Inferior Octave startup commands. |
239 (let* (commands | |
240 (program (file-name-nondirectory inferior-octave-program)) | |
241 (file (or inferior-octave-startup-file | |
242 (concat "~/.emacs-" program)))) | |
243 (setq commands | |
73500
d25ce2f322cb
* progmodes/octave-inf.el (inferior-octave-has-built-in-variables):
Chong Yidong <cyd@stupidchicken.com>
parents:
71665
diff
changeset
|
244 (list "more off;\n" |
16903 | 245 (if (not (string-equal |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
38436
diff
changeset
|
246 inferior-octave-output-string ">> ")) |
73500
d25ce2f322cb
* progmodes/octave-inf.el (inferior-octave-has-built-in-variables):
Chong Yidong <cyd@stupidchicken.com>
parents:
71665
diff
changeset
|
247 (if inferior-octave-has-built-in-variables |
d25ce2f322cb
* progmodes/octave-inf.el (inferior-octave-has-built-in-variables):
Chong Yidong <cyd@stupidchicken.com>
parents:
71665
diff
changeset
|
248 "PS1=\"\\\\s> \";\n" |
d25ce2f322cb
* progmodes/octave-inf.el (inferior-octave-has-built-in-variables):
Chong Yidong <cyd@stupidchicken.com>
parents:
71665
diff
changeset
|
249 "PS1 (\"\\\\s> \");\n")) |
16903 | 250 (if (file-exists-p file) |
251 (format "source (\"%s\");\n" file)))) | |
252 (inferior-octave-send-list-and-digest commands)) | |
253 (insert-before-markers | |
254 (concat | |
255 (if inferior-octave-output-list | |
256 (concat (mapconcat | |
257 'identity inferior-octave-output-list "\n") | |
258 "\n")) | |
259 inferior-octave-output-string)) | |
260 ;; Next, we check whether Octave supports `completion_matches' ... | |
261 (inferior-octave-send-list-and-digest | |
262 (list "exist \"completion_matches\"\n")) | |
263 (setq inferior-octave-complete-impossible | |
264 (not (string-match "5$" (car inferior-octave-output-list)))) | |
265 | |
266 ;; And finally, everything is back to normal. | |
267 (set-process-filter proc 'inferior-octave-output-filter) | |
65431
effbe6e5cd50
(inferior-octave-startup): Resync current dir at the end.
Eli Zaretskii <eliz@gnu.org>
parents:
65152
diff
changeset
|
268 (run-hooks 'inferior-octave-startup-hook) |
effbe6e5cd50
(inferior-octave-startup): Resync current dir at the end.
Eli Zaretskii <eliz@gnu.org>
parents:
65152
diff
changeset
|
269 (run-hooks 'inferior-octave-startup-hook) |
effbe6e5cd50
(inferior-octave-startup): Resync current dir at the end.
Eli Zaretskii <eliz@gnu.org>
parents:
65152
diff
changeset
|
270 ;; Just in case, to be sure a cd in the startup file |
effbe6e5cd50
(inferior-octave-startup): Resync current dir at the end.
Eli Zaretskii <eliz@gnu.org>
parents:
65152
diff
changeset
|
271 ;; won't have detrimental effects. |
effbe6e5cd50
(inferior-octave-startup): Resync current dir at the end.
Eli Zaretskii <eliz@gnu.org>
parents:
65152
diff
changeset
|
272 (inferior-octave-resync-dirs))) |
16903 | 273 |
274 | |
275 (defun inferior-octave-complete () | |
276 "Perform completion on the Octave symbol preceding point. | |
277 This is implemented using the Octave command `completion_matches' which | |
278 is NOT available with versions of Octave prior to 2.0." | |
279 (interactive) | |
280 (let* ((end (point)) | |
30646
bb2ebaf63949
(inferior-octave-complete): Use comint-line-beginning-position.
Miles Bader <miles@gnu.org>
parents:
25719
diff
changeset
|
281 (command |
bb2ebaf63949
(inferior-octave-complete): Use comint-line-beginning-position.
Miles Bader <miles@gnu.org>
parents:
25719
diff
changeset
|
282 (save-excursion |
bb2ebaf63949
(inferior-octave-complete): Use comint-line-beginning-position.
Miles Bader <miles@gnu.org>
parents:
25719
diff
changeset
|
283 (skip-syntax-backward "w_" (comint-line-beginning-position)) |
bb2ebaf63949
(inferior-octave-complete): Use comint-line-beginning-position.
Miles Bader <miles@gnu.org>
parents:
25719
diff
changeset
|
284 (buffer-substring-no-properties (point) end))) |
71665
611496c32b32
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
285 (proc (get-buffer-process inferior-octave-buffer))) |
16903 | 286 (cond (inferior-octave-complete-impossible |
287 (error (concat | |
288 "Your Octave does not have `completion_matches'. " | |
289 "Please upgrade to version 2.X."))) | |
290 ((string-equal command "") | |
291 (message "Cannot complete an empty string")) | |
292 (t | |
293 (inferior-octave-send-list-and-digest | |
294 (list (concat "completion_matches (\"" command "\");\n"))) | |
295 ;; Sort the list | |
296 (setq inferior-octave-output-list | |
297 (sort inferior-octave-output-list 'string-lessp)) | |
298 ;; Remove duplicates | |
299 (let* ((x inferior-octave-output-list) | |
300 (y (cdr x))) | |
301 (while y | |
302 (if (string-equal (car x) (car y)) | |
303 (setcdr x (setq y (cdr y))) | |
304 (setq x y | |
305 y (cdr y))))) | |
306 ;; And let comint handle the rest | |
307 (comint-dynamic-simple-complete | |
308 command inferior-octave-output-list))))) | |
309 | |
310 (defun inferior-octave-dynamic-list-input-ring () | |
71665
611496c32b32
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
311 "List the buffer's input history in a help buffer." |
16903 | 312 ;; We cannot use `comint-dynamic-list-input-ring', because it replaces |
313 ;; "completion" by "history reference" ... | |
314 (interactive) | |
315 (if (or (not (ring-p comint-input-ring)) | |
316 (ring-empty-p comint-input-ring)) | |
317 (message "No history") | |
318 (let ((history nil) | |
319 (history-buffer " *Input History*") | |
320 (index (1- (ring-length comint-input-ring))) | |
321 (conf (current-window-configuration))) | |
322 ;; We have to build up a list ourselves from the ring vector. | |
323 (while (>= index 0) | |
324 (setq history (cons (ring-ref comint-input-ring index) history) | |
325 index (1- index))) | |
326 ;; Change "completion" to "history reference" | |
327 ;; to make the display accurate. | |
328 (with-output-to-temp-buffer history-buffer | |
329 (display-completion-list history) | |
330 (set-buffer history-buffer)) | |
331 (message "Hit space to flush") | |
332 (let ((ch (read-event))) | |
333 (if (eq ch ?\ ) | |
334 (set-window-configuration conf) | |
335 (setq unread-command-events (list ch))))))) | |
336 | |
337 (defun inferior-octave-strip-ctrl-g (string) | |
338 "Strip leading `^G' character. | |
339 If STRING starts with a `^G', ring the bell and strip it." | |
340 (if (string-match "^\a" string) | |
341 (progn | |
342 (ding) | |
343 (setq string (substring string 1)))) | |
344 string) | |
345 | |
346 (defun inferior-octave-output-filter (proc string) | |
347 "Standard output filter for the inferior Octave process. | |
348 Ring Emacs bell if process output starts with an ASCII bell, and pass | |
349 the rest to `comint-output-filter'." | |
350 (comint-output-filter proc (inferior-octave-strip-ctrl-g string))) | |
351 | |
352 (defun inferior-octave-output-digest (proc string) | |
353 "Special output filter for the inferior Octave process. | |
354 Save all output between newlines into `inferior-octave-output-list', and | |
355 the rest to `inferior-octave-output-string'." | |
356 (setq string (concat inferior-octave-output-string string)) | |
357 (while (string-match "\n" string) | |
358 (setq inferior-octave-output-list | |
359 (append inferior-octave-output-list | |
360 (list (substring string 0 (match-beginning 0)))) | |
361 string (substring string (match-end 0)))) | |
362 (if (string-match inferior-octave-prompt string) | |
363 (setq inferior-octave-receive-in-progress nil)) | |
364 (setq inferior-octave-output-string string)) | |
365 | |
366 (defun inferior-octave-send-list-and-digest (list) | |
367 "Send LIST to the inferior Octave process and digest the output. | |
368 The elements of LIST have to be strings and are sent one by one. All | |
369 output is passed to the filter `inferior-octave-output-digest'." | |
370 (let* ((proc inferior-octave-process) | |
371 (filter (process-filter proc)) | |
372 string) | |
373 (set-process-filter proc 'inferior-octave-output-digest) | |
374 (setq inferior-octave-output-list nil) | |
375 (unwind-protect | |
376 (while (setq string (car list)) | |
377 (setq inferior-octave-output-string nil | |
378 inferior-octave-receive-in-progress t) | |
379 (comint-send-string proc string) | |
380 (while inferior-octave-receive-in-progress | |
381 (accept-process-output proc)) | |
382 (setq list (cdr list))) | |
383 (set-process-filter proc filter)))) | |
384 | |
385 (defun inferior-octave-directory-tracker (string) | |
386 "Tracks `cd' commands issued to the inferior Octave process. | |
387 Use \\[inferior-octave-resync-dirs] to resync if Emacs gets confused." | |
24930
ea5923fcc5b2
inferior-octave-directory-tracker: Change regexp so that it doesn't
Stephen Eglen <stephen@gnu.org>
parents:
23343
diff
changeset
|
388 (cond |
ea5923fcc5b2
inferior-octave-directory-tracker: Change regexp so that it doesn't
Stephen Eglen <stephen@gnu.org>
parents:
23343
diff
changeset
|
389 ((string-match "^[ \t]*cd[ \t;]*$" string) |
ea5923fcc5b2
inferior-octave-directory-tracker: Change regexp so that it doesn't
Stephen Eglen <stephen@gnu.org>
parents:
23343
diff
changeset
|
390 (cd "~")) |
ea5923fcc5b2
inferior-octave-directory-tracker: Change regexp so that it doesn't
Stephen Eglen <stephen@gnu.org>
parents:
23343
diff
changeset
|
391 ((string-match "^[ \t]*cd[ \t]+\\([^ \t\n;]*\\)[ \t\n;]*" string) |
ea5923fcc5b2
inferior-octave-directory-tracker: Change regexp so that it doesn't
Stephen Eglen <stephen@gnu.org>
parents:
23343
diff
changeset
|
392 (cd (substring string (match-beginning 1) (match-end 1)))))) |
16903 | 393 |
394 (defun inferior-octave-resync-dirs () | |
395 "Resync the buffer's idea of the current directory. | |
396 This command queries the inferior Octave process about its current | |
397 directory and makes this the current buffer's default directory." | |
398 (interactive) | |
73500
d25ce2f322cb
* progmodes/octave-inf.el (inferior-octave-has-built-in-variables):
Chong Yidong <cyd@stupidchicken.com>
parents:
71665
diff
changeset
|
399 (inferior-octave-send-list-and-digest '("disp (pwd ())\n")) |
16903 | 400 (cd (car inferior-octave-output-list))) |
401 | |
17150 | 402 ;;; provide ourself |
403 | |
404 (provide 'octave-inf) | |
405 | |
71665
611496c32b32
Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68773
diff
changeset
|
406 ;; arch-tag: bdce0395-24d1-4bb4-bfba-6fb1eeb1a660 |
16906 | 407 ;;; octave-inf.el ends here |