annotate lisp/progmodes/octave-inf.el @ 18291:130a48e6cc13

(ffap-soft-value): Make this a function again; the macro version does intern-soft too early. Deleted XEmacs-specific code. (ffap-string-at-point-mode-alist): added "=" and "&" to the url syntax, as suggested by SJE. (ffap-read-file-or-url): fixed the HIST argument to completing-read (only visible in XEmacs?), as reported by Christoph Wedler <wedler@fmi.uni-passau.de>. (ffap-kpathsea-expand-path) New func, replaces ffap-add-subdirs, a first attempt at kpathsea emulation. Also convert "" to "." in path lists, for XEmacs. Suggestions from SJE. Added mouse-track support (but no binding), as suggested by MDB. Moved Emacs mouse bindings from "down-mouse" events to ordinary mouse events. (ffap-alist): added ffap-fortran-mode, as requested by MDB. Rewrote and merged XEmacs support, eliminating file ffap-xe.el. Modified ffap-other-frame to work in dedicated frames, fixing a bug reported by JENS. (ffap-menu-rescan): avoid modifying the buffer. Two bugs reported by Christoph Wedler <wedler@fmi.uni-passau.de>: (ffap-fixup-url): avoid autoloading through url-normalize-url. (ffap-read-file-or-url): for XEmacs, give extra HACK-HOMEDIR arg to `abbreviate-file-name'. (ffap-file-at-point): suppress errors from `ffap-alist'. (ffap-url-at-point): modified regexp to accept mail hostnames ending with a digit. Fixes bug report of SJE. (ffap-url-at-point): use higher level function (w3-view-this-url t) suggested by wmperry, instead of w3-zone-at/w3-zone-data or widget-at/widget-get. (ffap-url-at-point): modified to work with w3-version "WWW 2.3.64 1996/06/02 06:20:23" alpha, which uses the 'widget package rather than the old w3-zone-at. Bug was reported by JENS. Adopted comments and doc strings to Emacs coding conventions. Reorganized. Retired v18 support. (ffap-bindings): Offers a default installation. (ffap-string-at-point): Modified arguments. (ffap-gnus-hook): Updated for Gnus 5. (ffap-tex-init): Delayed initialization of `ffap-tex-path'. (ffap-dired): New entry in `ffap-alist'. (ffap-menu-rescan): May fontify the choices in buffer. (ffap-read-file-or-url): `PC-completion-as-file-name-predicate' used if available, to work with complete.el.
author Karl Heuer <kwzh@gnu.org>
date Wed, 18 Jun 1997 04:24:37 +0000
parents 8f952e921136
children 0457d32c5b05
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
17517
8f952e921136 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 17150
diff changeset
3 ;; Copyright (C) 1997 Free Software Foundation, Inc.
16903
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Author: Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Author: John Eaton <jwe@bevo.che.wisc.edu>
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; Maintainer: Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; Keywords: languages
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; 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
14 ;; the Free Software Foundation; either version 2, or (at your option)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; any later version.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; GNU General Public License for more details.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;; Boston, MA 02111-1307, USA.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;;; Code:
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28
16904
2bc5f76917e0 Require octave-mod, not octave.
Richard M. Stallman <rms@gnu.org>
parents: 16903
diff changeset
29 (require 'octave-mod)
16903
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 (require 'comint)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 (defvar inferior-octave-program "octave"
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 "*Program invoked by `inferior-octave'.")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 (defvar inferior-octave-prompt "\\(^octave\\(:[0-9]+\\)?\\|^\\)>+ "
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 "*Regexp to match prompts for the inferior Octave process.")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 (defvar inferior-octave-startup-file nil
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 "*Name of the inferior Octave startup file.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 The contents of this file are sent to the inferior Octave process on
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 startup.")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 (defvar inferior-octave-startup-args nil
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 "*List of command line arguments for the inferior Octave process.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 For example, for suppressing the startup message and using `traditional'
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 mode, set this to (\"-q\" \"--traditional\").")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 (defvar inferior-octave-mode-map nil
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 "Keymap used in Inferior Octave mode.")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 (if inferior-octave-mode-map
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ()
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 (let ((map (copy-keymap comint-mode-map)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 (define-key map "\t" 'comint-dynamic-complete)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 (define-key map "\M-?" 'comint-dynamic-list-filename-completions)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 (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
56 (define-key map [menu-bar inout list-history]
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 '("List Input History" . inferior-octave-dynamic-list-input-ring))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 (define-key map "\C-c\C-h" 'octave-help)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 (setq inferior-octave-mode-map map)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 (defvar inferior-octave-mode-syntax-table nil
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 "Syntax table in use in inferior-octave-mode buffers.")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 (if inferior-octave-mode-syntax-table
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 ()
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 (let ((table (make-syntax-table)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 (modify-syntax-entry ?\` "w" table)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 (modify-syntax-entry ?\# "<" table)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 (modify-syntax-entry ?\n ">" table)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 (setq inferior-octave-mode-syntax-table table)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 (defvar inferior-octave-mode-hook nil
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 "*Hook to be run when Inferior Octave mode is started.")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 (defvar inferior-octave-font-lock-keywords
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 (list
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 (cons inferior-octave-prompt 'font-lock-type-face))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 ;; Could certainly do more font locking in inferior Octave ...
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 "Additional expressions to highlight in Inferior Octave mode.")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 (defvar inferior-octave-output-list nil)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 (defvar inferior-octave-output-string nil)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 (defvar inferior-octave-receive-in-progress nil)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 (defvar inferior-octave-startup-hook nil)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 (defvar inferior-octave-complete-impossible nil
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 "Non-nil means that `inferior-octave-complete' is impossible.")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 (defvar inferior-octave-dynamic-complete-functions
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 '(inferior-octave-complete comint-dynamic-complete-filename)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 "List of functions called to perform completion for inferior Octave.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 This variable is used to initialize `comint-dynamic-complete-functions'
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 in the Inferior Octave buffer.")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 (defun inferior-octave-mode ()
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 "Major mode for interacting with an inferior Octave process.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 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
98 buffer.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 Entry to this mode successively runs the hooks `comint-mode-hook' and
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 `inferior-octave-mode-hook'."
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 (interactive)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 (comint-mode)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 (setq comint-prompt-regexp inferior-octave-prompt
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 major-mode 'inferior-octave-mode
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 mode-name "Inferior Octave"
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 mode-line-process '(":%s")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 local-abbrev-table octave-abbrev-table)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 (use-local-map inferior-octave-mode-map)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 (set-syntax-table inferior-octave-mode-syntax-table)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 (make-local-variable 'comment-start)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 (setq comment-start octave-comment-start)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 (make-local-variable 'comment-end)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 (setq comment-end "")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 (make-local-variable 'comment-column)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 (setq comment-column 32)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 (make-local-variable 'comment-start-skip)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 (setq comment-start-skip octave-comment-start-skip)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 (make-local-variable 'font-lock-defaults)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 (setq font-lock-defaults '(inferior-octave-font-lock-keywords nil nil))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 (setq comint-input-ring-file-name
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 (or (getenv "OCTAVE_HISTFILE") "~/.octave_hist")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 comint-input-ring-size (or (getenv "OCTAVE_HISTSIZE") 1024)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 comint-input-filter-functions '(inferior-octave-directory-tracker)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 comint-dynamic-complete-functions
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 inferior-octave-dynamic-complete-functions)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 (comint-read-input-ring t)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 (run-hooks 'inferior-octave-mode-hook))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 ;;;###autoload
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 (defun inferior-octave (&optional arg)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 "Run an inferior Octave process, I/O via `inferior-octave-buffer'.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 This buffer is put in Inferior Octave mode. See `inferior-octave-mode'.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 Unless ARG is non-nil, switches to this buffer.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 The elements of the list `inferior-octave-startup-args' are sent as
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 command line arguments to the inferior Octave process on startup.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 Additional commands to be executed on startup can be provided either in
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 the file specified by `inferior-octave-startup-file' or by the default
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 startup file, `~/.emacs-octave'."
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 (interactive "P")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 (let ((buffer inferior-octave-buffer))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 (get-buffer-create buffer)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 (if (comint-check-proc buffer)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 ()
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 (save-excursion
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 (set-buffer buffer)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 (comint-mode)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 (inferior-octave-startup)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 (inferior-octave-mode)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 (if (not arg)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 (pop-to-buffer buffer))))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 ;;;###autoload
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 (defalias 'run-octave 'inferior-octave)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 (defun inferior-octave-startup ()
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 "Start an inferior Octave process."
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 (let ((proc (comint-exec-1
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 (substring inferior-octave-buffer 1 -1)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 inferior-octave-buffer
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 inferior-octave-program
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 inferior-octave-startup-args)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 (set-process-filter proc 'inferior-octave-output-digest)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 (setq comint-ptyp process-connection-type
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 inferior-octave-process proc
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 inferior-octave-output-list nil
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 inferior-octave-output-string nil
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 inferior-octave-receive-in-progress t)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 ;; This may look complicated ... However, we need to make sure that
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 ;; we additional startup code only AFTER Octave is ready (otherwise,
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 ;; output may be mixed up). Hence, we need to digest the Octave
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 ;; output to see when it issues a prompt.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 (while inferior-octave-receive-in-progress
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (accept-process-output inferior-octave-process))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 (goto-char (point-max))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 (set-marker (process-mark proc) (point))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 (insert-before-markers
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 (concat
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 (if (not (bobp)) " \n")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (if inferior-octave-output-list
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 (concat (mapconcat
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 'identity inferior-octave-output-list "\n")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 "\n"))))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 ;; O.k., now we are ready for the Inferior Octave startup commands.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 (let* (commands
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 (program (file-name-nondirectory inferior-octave-program))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (file (or inferior-octave-startup-file
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (concat "~/.emacs-" program))))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (setq commands
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (list "page_screen_output = 0;\n"
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (if (not (string-equal
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 inferior-octave-output-string ">> "))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 "PS1=\"\\\\s> \";\n")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 (if (file-exists-p file)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (format "source (\"%s\");\n" file))))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 (inferior-octave-send-list-and-digest commands))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 (insert-before-markers
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 (concat
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (if inferior-octave-output-list
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 (concat (mapconcat
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 'identity inferior-octave-output-list "\n")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 "\n"))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 inferior-octave-output-string))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 ;; Next, we check whether Octave supports `completion_matches' ...
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 (inferior-octave-send-list-and-digest
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (list "exist \"completion_matches\"\n"))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 (setq inferior-octave-complete-impossible
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 (not (string-match "5$" (car inferior-octave-output-list))))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 ;; And finally, everything is back to normal.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 (set-process-filter proc 'inferior-octave-output-filter)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 (run-hooks 'inferior-octave-startup-hook)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 (defun inferior-octave-complete ()
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 "Perform completion on the Octave symbol preceding point.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 This is implemented using the Octave command `completion_matches' which
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 is NOT available with versions of Octave prior to 2.0."
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 (interactive)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 (let* ((end (point))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 (command (save-excursion
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 (skip-syntax-backward "w_")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 (and (looking-at comint-prompt-regexp)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 (goto-char (match-end 0)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 (buffer-substring-no-properties (point) end)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 (proc (get-buffer-process inferior-octave-buffer))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 (filter (process-filter proc)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 (cond (inferior-octave-complete-impossible
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 (error (concat
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 "Your Octave does not have `completion_matches'. "
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 "Please upgrade to version 2.X.")))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 ((string-equal command "")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 (message "Cannot complete an empty string"))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 (t
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 (inferior-octave-send-list-and-digest
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 (list (concat "completion_matches (\"" command "\");\n")))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 ;; Sort the list
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 (setq inferior-octave-output-list
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 (sort inferior-octave-output-list 'string-lessp))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 ;; Remove duplicates
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 (let* ((x inferior-octave-output-list)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 (y (cdr x)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 (while y
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 (if (string-equal (car x) (car y))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 (setcdr x (setq y (cdr y)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 (setq x y
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 y (cdr y)))))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 ;; And let comint handle the rest
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 (comint-dynamic-simple-complete
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 command inferior-octave-output-list)))))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 (defun inferior-octave-dynamic-list-input-ring ()
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 "List the buffer's input history in a help buffer"
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 ;; We cannot use `comint-dynamic-list-input-ring', because it replaces
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 ;; "completion" by "history reference" ...
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 (interactive)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 (if (or (not (ring-p comint-input-ring))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 (ring-empty-p comint-input-ring))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 (message "No history")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 (let ((history nil)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 (history-buffer " *Input History*")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 (index (1- (ring-length comint-input-ring)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 (conf (current-window-configuration)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 ;; We have to build up a list ourselves from the ring vector.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 (while (>= index 0)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 (setq history (cons (ring-ref comint-input-ring index) history)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 index (1- index)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 ;; Change "completion" to "history reference"
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 ;; to make the display accurate.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 (with-output-to-temp-buffer history-buffer
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 (display-completion-list history)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 (set-buffer history-buffer))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 (message "Hit space to flush")
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 (let ((ch (read-event)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 (if (eq ch ?\ )
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 (set-window-configuration conf)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 (setq unread-command-events (list ch)))))))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 (defun inferior-octave-strip-ctrl-g (string)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 "Strip leading `^G' character.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 If STRING starts with a `^G', ring the bell and strip it."
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 (if (string-match "^\a" string)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 (progn
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 (ding)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 (setq string (substring string 1))))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 string)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 (defun inferior-octave-output-filter (proc string)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 "Standard output filter for the inferior Octave process.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 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
299 the rest to `comint-output-filter'."
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 (comint-output-filter proc (inferior-octave-strip-ctrl-g string)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 (defun inferior-octave-output-digest (proc string)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 "Special output filter for the inferior Octave process.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 Save all output between newlines into `inferior-octave-output-list', and
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 the rest to `inferior-octave-output-string'."
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 (setq string (concat inferior-octave-output-string string))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 (while (string-match "\n" string)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 (setq inferior-octave-output-list
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 (append inferior-octave-output-list
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310 (list (substring string 0 (match-beginning 0))))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 string (substring string (match-end 0))))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 (if (string-match inferior-octave-prompt string)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 (setq inferior-octave-receive-in-progress nil))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 (setq inferior-octave-output-string string))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 (defun inferior-octave-send-list-and-digest (list)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 "Send LIST to the inferior Octave process and digest the output.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 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
319 output is passed to the filter `inferior-octave-output-digest'."
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 (let* ((proc inferior-octave-process)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 (filter (process-filter proc))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 string)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 (set-process-filter proc 'inferior-octave-output-digest)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 (setq inferior-octave-output-list nil)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 (unwind-protect
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 (while (setq string (car list))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 (setq inferior-octave-output-string nil
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 inferior-octave-receive-in-progress t)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 (comint-send-string proc string)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 (while inferior-octave-receive-in-progress
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 (accept-process-output proc))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 (setq list (cdr list)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 (set-process-filter proc filter))))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 (defun inferior-octave-directory-tracker (string)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 "Tracks `cd' commands issued to the inferior Octave process.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 Use \\[inferior-octave-resync-dirs] to resync if Emacs gets confused."
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 (if (string-match "[ \t]*cd[ \t]*\\([^ \t\n;]*\\)[ \t\n;]"
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 string)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 (cd (substring string (match-beginning 1) (match-end 1)))))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 (defun inferior-octave-resync-dirs ()
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 "Resync the buffer's idea of the current directory.
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 This command queries the inferior Octave process about its current
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 directory and makes this the current buffer's default directory."
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 (interactive)
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 (inferior-octave-send-list-and-digest '("pwd\n"))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 (cd (car inferior-octave-output-list)))
b1239a1ef6f2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349
17150
a44a34757937 Provide octave-inf.
Karl Heuer <kwzh@gnu.org>
parents: 16906
diff changeset
350 ;;; provide ourself
a44a34757937 Provide octave-inf.
Karl Heuer <kwzh@gnu.org>
parents: 16906
diff changeset
351
a44a34757937 Provide octave-inf.
Karl Heuer <kwzh@gnu.org>
parents: 16906
diff changeset
352 (provide 'octave-inf)
a44a34757937 Provide octave-inf.
Karl Heuer <kwzh@gnu.org>
parents: 16906
diff changeset
353
16906
e4ca41bdc7fe Whitespace change.
Richard M. Stallman <rms@gnu.org>
parents: 16904
diff changeset
354 ;;; octave-inf.el ends here