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