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