annotate lisp/progmodes/octave-inf.el @ 77115:7596f1771948

(desktop-save, desktop-create-buffer): Replace mapcar with dolist. (after-init-hook): Don't quote lambda. (desktop-first-buffer): Don't wrap it in eval-when-compile. (desktop-internal-v2s): Remove unused var `el'. (desktop-buffer-major-mode, desktop-buffer-locals): Move out of desktop-restore-file-buffer. (desktop-buffer-ok-count, desktop-buffer-fail-count): Move out of desktop-create-buffer.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Wed, 11 Apr 2007 02:28:26 +0000
parents e3694f1cb928
children dcfe1564f1a0 95d0cdf160ea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17517
8f952e921136 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 17150
diff changeset
1 ;;; octave-inf.el --- running Octave as an inferior Emacs process
16903
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
75347
e3694f1cb928 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 73500
diff changeset
3 ;; Copyright (C) 1997, 2001, 2002, 2003, 2004, 2005, 2006, 2007
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
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; Keywords: languages
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; This file is part of GNU Emacs.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; the Free Software Foundation; either version 2, or (at your option)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; any later version.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; GNU Emacs is distributed in the hope that it will be useful,
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; GNU General Public License for more details.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64085
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 63411
diff changeset
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18a818a2ee7c Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 63411
diff changeset
26 ;; Boston, MA 02110-1301, USA.
16903
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;;; Code:
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31
16904
2bc5f76917e0 Require octave-mod, not octave.
Richard M. Stallman <rms@gnu.org>
parents: 16903
diff changeset
32 (require 'octave-mod)
16903
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 (require 'comint)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34
20781
6f55b3849106 Customized.
Andreas Schwab <schwab@suse.de>
parents: 20401
diff changeset
35 (defgroup octave-inferior nil
6f55b3849106 Customized.
Andreas Schwab <schwab@suse.de>
parents: 20401
diff changeset
36 "Running Octave as an inferior Emacs process."
6f55b3849106 Customized.
Andreas Schwab <schwab@suse.de>
parents: 20401
diff changeset
37 :group 'octave)
16903
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38
20781
6f55b3849106 Customized.
Andreas Schwab <schwab@suse.de>
parents: 20401
diff changeset
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
6f55b3849106 Customized.
Andreas Schwab <schwab@suse.de>
parents: 20401
diff changeset
41 :type 'string
6f55b3849106 Customized.
Andreas Schwab <schwab@suse.de>
parents: 20401
diff changeset
42 :group 'octave-inferior)
6f55b3849106 Customized.
Andreas Schwab <schwab@suse.de>
parents: 20401
diff changeset
43
6f55b3849106 Customized.
Andreas Schwab <schwab@suse.de>
parents: 20401
diff changeset
44 (defcustom inferior-octave-prompt
52952
03afc05bc725 (inferior-octave-prompt): Recognize version number in prompt.
Lute Kamstra <lute@gnu.org>
parents: 52401
diff changeset
45 "\\(^octave\\(\\|.bin\\)\\(-[.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
6f55b3849106 Customized.
Andreas Schwab <schwab@suse.de>
parents: 20401
diff changeset
47 :type 'regexp
6f55b3849106 Customized.
Andreas Schwab <schwab@suse.de>
parents: 20401
diff changeset
48 :group 'octave-inferior)
16903
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49
20781
6f55b3849106 Customized.
Andreas Schwab <schwab@suse.de>
parents: 20401
diff changeset
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
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 The contents of this file are sent to the inferior Octave process on
20781
6f55b3849106 Customized.
Andreas Schwab <schwab@suse.de>
parents: 20401
diff changeset
53 startup."
6f55b3849106 Customized.
Andreas Schwab <schwab@suse.de>
parents: 20401
diff changeset
54 :type '(choice (const :tag "None" nil)
6f55b3849106 Customized.
Andreas Schwab <schwab@suse.de>
parents: 20401
diff changeset
55 file)
6f55b3849106 Customized.
Andreas Schwab <schwab@suse.de>
parents: 20401
diff changeset
56 :group 'octave-inferior)
16903
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 For example, for suppressing the startup message and using `traditional'
20781
6f55b3849106 Customized.
Andreas Schwab <schwab@suse.de>
parents: 20401
diff changeset
61 mode, set this to (\"-q\" \"--traditional\")."
6f55b3849106 Customized.
Andreas Schwab <schwab@suse.de>
parents: 20401
diff changeset
62 :type '(repeat string)
6f55b3849106 Customized.
Andreas Schwab <schwab@suse.de>
parents: 20401
diff changeset
63 :group 'octave-inferior)
16903
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 (define-key map "\t" 'comint-dynamic-complete)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 (define-key map "\M-?" 'comint-dynamic-list-filename-completions)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 (define-key map "\C-c\C-l" 'inferior-octave-dynamic-list-input-ring)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 (define-key map [menu-bar inout list-history]
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 '("List Input History" . inferior-octave-dynamic-list-input-ring))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 (let ((table (make-syntax-table)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 (modify-syntax-entry ?\` "w" table)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 (modify-syntax-entry ?\# "<" table)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84
20781
6f55b3849106 Customized.
Andreas Schwab <schwab@suse.de>
parents: 20401
diff changeset
85 (defcustom inferior-octave-mode-hook nil
6f55b3849106 Customized.
Andreas Schwab <schwab@suse.de>
parents: 20401
diff changeset
86 "*Hook to be run when Inferior Octave mode is started."
6f55b3849106 Customized.
Andreas Schwab <schwab@suse.de>
parents: 20401
diff changeset
87 :type 'hook
6f55b3849106 Customized.
Andreas Schwab <schwab@suse.de>
parents: 20401
diff changeset
88 :group 'octave-inferior)
16903
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 (defvar inferior-octave-font-lock-keywords
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 (list
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 (cons inferior-octave-prompt 'font-lock-type-face))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 ;; Could certainly do more font locking in inferior Octave ...
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 "Additional expressions to highlight in Inferior Octave mode.")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 (defvar inferior-octave-output-list nil)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 (defvar inferior-octave-output-string nil)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 (defvar inferior-octave-receive-in-progress nil)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 (defvar inferior-octave-startup-hook nil)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 (defvar inferior-octave-complete-impossible nil
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 "Non-nil means that `inferior-octave-complete' is impossible.")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 "List of functions called to perform completion for inferior Octave.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 This variable is used to initialize `comint-dynamic-complete-functions'
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 in the Inferior Octave buffer.")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 (defun inferior-octave-mode ()
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 "Major mode for interacting with an inferior Octave process.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 Runs Octave as a subprocess of Emacs, with Octave I/O through an Emacs
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 buffer.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 Entry to this mode successively runs the hooks `comint-mode-hook' and
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 `inferior-octave-mode-hook'."
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 (setq comint-prompt-regexp inferior-octave-prompt
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 major-mode 'inferior-octave-mode
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 mode-name "Inferior Octave"
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 mode-line-process '(":%s")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 local-abbrev-table octave-abbrev-table)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 (use-local-map inferior-octave-mode-map)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 (set-syntax-table inferior-octave-mode-syntax-table)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 38436
diff changeset
142 (make-local-variable 'comment-start)
16903
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 (setq comment-start octave-comment-start)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 (make-local-variable 'comment-end)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 (setq comment-end "")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 (make-local-variable 'comment-start-skip)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 (setq comment-start-skip octave-comment-start-skip)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 (make-local-variable 'font-lock-defaults)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 (setq font-lock-defaults '(inferior-octave-font-lock-keywords nil nil))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 (setq comint-input-ring-file-name
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 (or (getenv "OCTAVE_HISTFILE") "~/.octave_hist")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
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 comint-input-filter-functions '(inferior-octave-directory-tracker))
611496c32b32 Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68773
diff changeset
158 (set (make-local-variable 'comint-dynamic-complete-functions)
611496c32b32 Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68773
diff changeset
159 inferior-octave-dynamic-complete-functions)
16903
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 (comint-read-input-ring t)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161
62772
f2892faa87d4 * progmodes/ada-mode.el (ada-mode):
Lute Kamstra <lute@gnu.org>
parents: 52952
diff changeset
162 (run-mode-hooks 'inferior-octave-mode-hook))
16903
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 ;;;###autoload
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 (defun inferior-octave (&optional arg)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 "Run an inferior Octave process, I/O via `inferior-octave-buffer'.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 This buffer is put in Inferior Octave mode. See `inferior-octave-mode'.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 Unless ARG is non-nil, switches to this buffer.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 The elements of the list `inferior-octave-startup-args' are sent as
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 command line arguments to the inferior Octave process on startup.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 Additional commands to be executed on startup can be provided either in
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 the file specified by `inferior-octave-startup-file' or by the default
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 startup file, `~/.emacs-octave'."
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 (interactive "P")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 (let ((buffer inferior-octave-buffer))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 (get-buffer-create buffer)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 (if (comint-check-proc buffer)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 ()
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (save-excursion
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 (set-buffer buffer)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 (comint-mode)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 (inferior-octave-startup)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 (inferior-octave-mode)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 (if (not arg)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (pop-to-buffer buffer))))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 ;;;###autoload
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 (defalias 'run-octave 'inferior-octave)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 (defun inferior-octave-startup ()
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 "Start an inferior Octave process."
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (let ((proc (comint-exec-1
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (substring inferior-octave-buffer 1 -1)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 inferior-octave-buffer
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 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
199 (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
200 inferior-octave-startup-args))))
16903
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (set-process-filter proc 'inferior-octave-output-digest)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 (setq comint-ptyp process-connection-type
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 inferior-octave-process proc
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 inferior-octave-output-list nil
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 inferior-octave-output-string nil
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 inferior-octave-receive-in-progress t)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 ;; This may look complicated ... However, we need to make sure that
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 ;; we additional startup code only AFTER Octave is ready (otherwise,
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 ;; output may be mixed up). Hence, we need to digest the Octave
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 ;; output to see when it issues a prompt.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 (while inferior-octave-receive-in-progress
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 (accept-process-output inferior-octave-process))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (goto-char (point-max))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 (set-marker (process-mark proc) (point))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 (insert-before-markers
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 (concat
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 (if (not (bobp)) " \n")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 (if inferior-octave-output-list
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 (concat (mapconcat
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 'identity inferior-octave-output-list "\n")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 "\n"))))
67129
e0b37eeb2f0b (inferior-octave-startup): Force a non-empty string for secondary prompt PS2.
Eli Zaretskii <eliz@gnu.org>
parents: 65431
diff changeset
223
73500
d25ce2f322cb * progmodes/octave-inf.el (inferior-octave-has-built-in-variables):
Chong Yidong <cyd@stupidchicken.com>
parents: 71665
diff changeset
224 ;; 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
225 (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
226 (list "exist \"LOADPATH\"\n"))
d25ce2f322cb * progmodes/octave-inf.el (inferior-octave-has-built-in-variables):
Chong Yidong <cyd@stupidchicken.com>
parents: 71665
diff changeset
227 (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
228 (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
229
67129
e0b37eeb2f0b (inferior-octave-startup): Force a non-empty string for secondary prompt PS2.
Eli Zaretskii <eliz@gnu.org>
parents: 65431
diff changeset
230 ;; 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
231 ;; means trouble.
e0b37eeb2f0b (inferior-octave-startup): Force a non-empty string for secondary prompt PS2.
Eli Zaretskii <eliz@gnu.org>
parents: 65431
diff changeset
232 (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
233 (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
234 (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
235 (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
236 "PS2 = \"> \"\n"
d25ce2f322cb * progmodes/octave-inf.el (inferior-octave-has-built-in-variables):
Chong Yidong <cyd@stupidchicken.com>
parents: 71665
diff changeset
237 "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
238
16903
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 ;; O.k., now we are ready for the Inferior Octave startup commands.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 (let* (commands
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 (program (file-name-nondirectory inferior-octave-program))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 (file (or inferior-octave-startup-file
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 (concat "~/.emacs-" program))))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 (setq commands
73500
d25ce2f322cb * progmodes/octave-inf.el (inferior-octave-has-built-in-variables):
Chong Yidong <cyd@stupidchicken.com>
parents: 71665
diff changeset
245 (list "more off;\n"
16903
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 (if (not (string-equal
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 38436
diff changeset
247 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
248 (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
249 "PS1=\"\\\\s> \";\n"
d25ce2f322cb * progmodes/octave-inf.el (inferior-octave-has-built-in-variables):
Chong Yidong <cyd@stupidchicken.com>
parents: 71665
diff changeset
250 "PS1 (\"\\\\s> \");\n"))
16903
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 (if (file-exists-p file)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 (format "source (\"%s\");\n" file))))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 (inferior-octave-send-list-and-digest commands))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 (insert-before-markers
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 (concat
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 (if inferior-octave-output-list
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 (concat (mapconcat
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 'identity inferior-octave-output-list "\n")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 "\n"))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 inferior-octave-output-string))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 ;; Next, we check whether Octave supports `completion_matches' ...
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 (inferior-octave-send-list-and-digest
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 (list "exist \"completion_matches\"\n"))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 (setq inferior-octave-complete-impossible
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 (not (string-match "5$" (car inferior-octave-output-list))))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 ;; And finally, everything is back to normal.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 (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
269 (run-hooks 'inferior-octave-startup-hook)
effbe6e5cd50 (inferior-octave-startup): Resync current dir at the end.
Eli Zaretskii <eliz@gnu.org>
parents: 65152
diff changeset
270 (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 ;; 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
272 ;; won't have detrimental effects.
effbe6e5cd50 (inferior-octave-startup): Resync current dir at the end.
Eli Zaretskii <eliz@gnu.org>
parents: 65152
diff changeset
273 (inferior-octave-resync-dirs)))
16903
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 (defun inferior-octave-complete ()
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 "Perform completion on the Octave symbol preceding point.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 This is implemented using the Octave command `completion_matches' which
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 is NOT available with versions of Octave prior to 2.0."
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 (interactive)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 (let* ((end (point))
30646
bb2ebaf63949 (inferior-octave-complete): Use comint-line-beginning-position.
Miles Bader <miles@gnu.org>
parents: 25719
diff changeset
282 (command
bb2ebaf63949 (inferior-octave-complete): Use comint-line-beginning-position.
Miles Bader <miles@gnu.org>
parents: 25719
diff changeset
283 (save-excursion
bb2ebaf63949 (inferior-octave-complete): Use comint-line-beginning-position.
Miles Bader <miles@gnu.org>
parents: 25719
diff changeset
284 (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
285 (buffer-substring-no-properties (point) end)))
71665
611496c32b32 Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68773
diff changeset
286 (proc (get-buffer-process inferior-octave-buffer)))
16903
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 (cond (inferior-octave-complete-impossible
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 (error (concat
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 "Your Octave does not have `completion_matches'. "
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 "Please upgrade to version 2.X.")))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 ((string-equal command "")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 (message "Cannot complete an empty string"))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 (t
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 (inferior-octave-send-list-and-digest
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 (list (concat "completion_matches (\"" command "\");\n")))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 ;; Sort the list
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 (setq inferior-octave-output-list
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 (sort inferior-octave-output-list 'string-lessp))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 ;; Remove duplicates
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 (let* ((x inferior-octave-output-list)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 (y (cdr x)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 (while y
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 (if (string-equal (car x) (car y))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 (setcdr x (setq y (cdr y)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 (setq x y
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 y (cdr y)))))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 ;; And let comint handle the rest
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 (comint-dynamic-simple-complete
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 command inferior-octave-output-list)))))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 (defun inferior-octave-dynamic-list-input-ring ()
71665
611496c32b32 Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68773
diff changeset
312 "List the buffer's input history in a help buffer."
16903
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 ;; We cannot use `comint-dynamic-list-input-ring', because it replaces
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 ;; "completion" by "history reference" ...
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 (interactive)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 (if (or (not (ring-p comint-input-ring))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 (ring-empty-p comint-input-ring))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 (message "No history")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 (let ((history nil)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 (history-buffer " *Input History*")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 (index (1- (ring-length comint-input-ring)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 (conf (current-window-configuration)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 ;; We have to build up a list ourselves from the ring vector.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 (while (>= index 0)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 (setq history (cons (ring-ref comint-input-ring index) history)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 index (1- index)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 ;; Change "completion" to "history reference"
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 ;; to make the display accurate.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 (with-output-to-temp-buffer history-buffer
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 (display-completion-list history)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 (set-buffer history-buffer))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 (message "Hit space to flush")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 (let ((ch (read-event)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 (if (eq ch ?\ )
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 (set-window-configuration conf)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 (setq unread-command-events (list ch)))))))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 (defun inferior-octave-strip-ctrl-g (string)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 "Strip leading `^G' character.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 If STRING starts with a `^G', ring the bell and strip it."
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 (if (string-match "^\a" string)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 (progn
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 (ding)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 (setq string (substring string 1))))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 string)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 (defun inferior-octave-output-filter (proc string)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 "Standard output filter for the inferior Octave process.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 Ring Emacs bell if process output starts with an ASCII bell, and pass
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 the rest to `comint-output-filter'."
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 (comint-output-filter proc (inferior-octave-strip-ctrl-g string)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 (defun inferior-octave-output-digest (proc string)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 "Special output filter for the inferior Octave process.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 Save all output between newlines into `inferior-octave-output-list', and
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 the rest to `inferior-octave-output-string'."
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357 (setq string (concat inferior-octave-output-string string))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358 (while (string-match "\n" string)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 (setq inferior-octave-output-list
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 (append inferior-octave-output-list
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361 (list (substring string 0 (match-beginning 0))))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362 string (substring string (match-end 0))))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 (if (string-match inferior-octave-prompt string)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364 (setq inferior-octave-receive-in-progress nil))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 (setq inferior-octave-output-string string))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 (defun inferior-octave-send-list-and-digest (list)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 "Send LIST to the inferior Octave process and digest the output.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 The elements of LIST have to be strings and are sent one by one. All
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 output is passed to the filter `inferior-octave-output-digest'."
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 (let* ((proc inferior-octave-process)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 (filter (process-filter proc))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 string)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 (set-process-filter proc 'inferior-octave-output-digest)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375 (setq inferior-octave-output-list nil)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 (unwind-protect
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 (while (setq string (car list))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 (setq inferior-octave-output-string nil
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379 inferior-octave-receive-in-progress t)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380 (comint-send-string proc string)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381 (while inferior-octave-receive-in-progress
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382 (accept-process-output proc))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383 (setq list (cdr list)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384 (set-process-filter proc filter))))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386 (defun inferior-octave-directory-tracker (string)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387 "Tracks `cd' commands issued to the inferior Octave process.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388 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
389 (cond
ea5923fcc5b2 inferior-octave-directory-tracker: Change regexp so that it doesn't
Stephen Eglen <stephen@gnu.org>
parents: 23343
diff changeset
390 ((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
391 (cd "~"))
ea5923fcc5b2 inferior-octave-directory-tracker: Change regexp so that it doesn't
Stephen Eglen <stephen@gnu.org>
parents: 23343
diff changeset
392 ((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
393 (cd (substring string (match-beginning 1) (match-end 1))))))
16903
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 (defun inferior-octave-resync-dirs ()
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 "Resync the buffer's idea of the current directory.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397 This command queries the inferior Octave process about its current
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 directory and makes this the current buffer's default directory."
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 (interactive)
73500
d25ce2f322cb * progmodes/octave-inf.el (inferior-octave-has-built-in-variables):
Chong Yidong <cyd@stupidchicken.com>
parents: 71665
diff changeset
400 (inferior-octave-send-list-and-digest '("disp (pwd ())\n"))
16903
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401 (cd (car inferior-octave-output-list)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402
17150
a44a34757937 Provide octave-inf.
Karl Heuer <kwzh@gnu.org>
parents: 16906
diff changeset
403 ;;; provide ourself
a44a34757937 Provide octave-inf.
Karl Heuer <kwzh@gnu.org>
parents: 16906
diff changeset
404
a44a34757937 Provide octave-inf.
Karl Heuer <kwzh@gnu.org>
parents: 16906
diff changeset
405 (provide 'octave-inf)
a44a34757937 Provide octave-inf.
Karl Heuer <kwzh@gnu.org>
parents: 16906
diff changeset
406
71665
611496c32b32 Remove spurious * in docstrings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68773
diff changeset
407 ;; arch-tag: bdce0395-24d1-4bb4-bfba-6fb1eeb1a660
16906
e4ca41bdc7fe Whitespace change.
Richard M. Stallman <rms@gnu.org>
parents: 16904
diff changeset
408 ;;; octave-inf.el ends here