annotate emacs/octave-inf.el @ 6469:a848b846cb3a ss-2-9-10

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