;;; octave-inf.el --- running Octave as an inferior Emacs process
-;; Copyright (C) 1997, 2001, 2002, 2003, 2004, 2005, 2006
+;; Copyright (C) 1997, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
;; Free Software Foundation, Inc.
;; Author: Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
;; Author: John Eaton <jwe@bevo.che.wisc.edu>
;; Maintainer: Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
;; Keywords: languages
+;; Package: octave-mod
;; This file is part of GNU Emacs.
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
:group 'octave-inferior)
(defcustom inferior-octave-prompt
- "\\(^octave\\(\\|.bin\\)\\(-[.0-9]+\\)?\\(:[0-9]+\\)?\\|^debug\\|^\\)>+ "
+ "\\(^octave\\(\\|.bin\\|.exe\\)\\(-[.0-9]+\\)?\\(:[0-9]+\\)?\\|^debug\\|^\\)>+ "
"Regexp to match prompts for the inferior Octave process."
:type 'regexp
:group 'octave-inferior)
(defvar inferior-octave-complete-impossible nil
"Non-nil means that `inferior-octave-complete' is impossible.")
+(defvar inferior-octave-has-built-in-variables nil
+ "Non-nil means that Octave has built-in variables.")
+
(defvar inferior-octave-dynamic-complete-functions
'(inferior-octave-complete comint-dynamic-complete-filename)
"List of functions called to perform completion for inferior Octave.
This variable is used to initialize `comint-dynamic-complete-functions'
in the Inferior Octave buffer.")
-(defun inferior-octave-mode ()
+(define-derived-mode inferior-octave-mode comint-mode "Inferior Octave"
"Major mode for interacting with an inferior Octave process.
Runs Octave as a subprocess of Emacs, with Octave I/O through an Emacs
buffer.
Entry to this mode successively runs the hooks `comint-mode-hook' and
`inferior-octave-mode-hook'."
- (interactive)
- (delay-mode-hooks (comint-mode))
(setq comint-prompt-regexp inferior-octave-prompt
- major-mode 'inferior-octave-mode
- mode-name "Inferior Octave"
mode-line-process '(":%s")
local-abbrev-table octave-abbrev-table)
- (use-local-map inferior-octave-mode-map)
- (set-syntax-table inferior-octave-mode-syntax-table)
- (make-local-variable 'comment-start)
- (setq comment-start octave-comment-start)
- (make-local-variable 'comment-end)
- (setq comment-end "")
- (make-local-variable 'comment-column)
- (setq comment-column 32)
- (make-local-variable 'comment-start-skip)
- (setq comment-start-skip octave-comment-start-skip)
+ (set (make-local-variable 'comment-start) octave-comment-start)
+ (set (make-local-variable 'comment-end) "")
+ (set (make-local-variable 'comment-column) 32)
+ (set (make-local-variable 'comment-start-skip) octave-comment-start-skip)
- (make-local-variable 'font-lock-defaults)
- (setq font-lock-defaults '(inferior-octave-font-lock-keywords nil nil))
+ (set (make-local-variable 'font-lock-defaults)
+ '(inferior-octave-font-lock-keywords nil nil))
(setq comint-input-ring-file-name
(or (getenv "OCTAVE_HISTFILE") "~/.octave_hist")
- comint-input-ring-size (or (getenv "OCTAVE_HISTSIZE") 1024)
- comint-input-filter-functions '(inferior-octave-directory-tracker))
+ comint-input-ring-size (or (getenv "OCTAVE_HISTSIZE") 1024))
(set (make-local-variable 'comint-dynamic-complete-functions)
inferior-octave-dynamic-complete-functions)
- (comint-read-input-ring t)
-
- (run-mode-hooks 'inferior-octave-mode-hook))
+ (add-hook 'comint-input-filter-functions
+ 'inferior-octave-directory-tracker nil t)
+ (comint-read-input-ring t))
;;;###autoload
(defun inferior-octave (&optional arg)
(get-buffer-create buffer)
(if (comint-check-proc buffer)
()
- (save-excursion
- (set-buffer buffer)
+ (with-current-buffer buffer
(comint-mode)
(inferior-octave-startup)
(inferior-octave-mode)))
'identity inferior-octave-output-list "\n")
"\n"))))
+ ;; Find out whether Octave has built-in variables.
+ (inferior-octave-send-list-and-digest
+ (list "exist \"LOADPATH\"\n"))
+ (setq inferior-octave-has-built-in-variables
+ (string-match "101$" (car inferior-octave-output-list)))
+
;; An empty secondary prompt, as e.g. obtained by '--braindead',
;; means trouble.
(inferior-octave-send-list-and-digest (list "PS2\n"))
- (if (string-match "^PS2 = *$" (car inferior-octave-output-list))
- (inferior-octave-send-list-and-digest (list "PS2 = \"> \"\n")))
+ (if (string-match "\\(PS2\\|ans\\) = *$" (car inferior-octave-output-list))
+ (inferior-octave-send-list-and-digest
+ (list (if inferior-octave-has-built-in-variables
+ "PS2 = \"> \"\n"
+ "PS2 (\"> \");\n"))))
;; O.k., now we are ready for the Inferior Octave startup commands.
(let* (commands
(file (or inferior-octave-startup-file
(concat "~/.emacs-" program))))
(setq commands
- (list "page_screen_output = 0;\n"
+ (list "more off;\n"
(if (not (string-equal
inferior-octave-output-string ">> "))
- "PS1=\"\\\\s> \";\n")
+ (if inferior-octave-has-built-in-variables
+ "PS1=\"\\\\s> \";\n"
+ "PS1 (\"\\\\s> \");\n"))
(if (file-exists-p file)
(format "source (\"%s\");\n" file))))
(inferior-octave-send-list-and-digest commands))
This command queries the inferior Octave process about its current
directory and makes this the current buffer's default directory."
(interactive)
- (inferior-octave-send-list-and-digest '("pwd\n"))
+ (inferior-octave-send-list-and-digest '("disp (pwd ())\n"))
(cd (car inferior-octave-output-list)))
;;; provide ourself