]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/octave-inf.el
Merge from emacs--rel--22
[gnu-emacs] / lisp / progmodes / octave-inf.el
index b6e6e4fc45631b644ebc3eead8fa502f1c7be7d7..b46510b5ac9d1186fa59f2700e53863d948209ba 100644 (file)
@@ -1,6 +1,6 @@
 ;;; octave-inf.el --- running Octave as an inferior Emacs process
 
 ;;; 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
 ;; Free Software Foundation, Inc.
 
 ;; Author: Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
 ;; Free Software Foundation, Inc.
 
 ;; Author: Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
   :group 'octave)
 
 (defcustom inferior-octave-program "octave"
   :group 'octave)
 
 (defcustom inferior-octave-program "octave"
-  "*Program invoked by `inferior-octave'."
+  "Program invoked by `inferior-octave'."
   :type 'string
   :group 'octave-inferior)
 
 (defcustom inferior-octave-prompt
   :type 'string
   :group 'octave-inferior)
 
 (defcustom inferior-octave-prompt
-  "\\(^octave\\(\\|.bin\\)\\(-[.0-9]+\\)?\\(:[0-9]+\\)?\\|^debug\\|^\\)>+ "
-  "*Regexp to match prompts for the inferior Octave process."
+  "\\(^octave\\(\\|.bin\\|.exe\\)\\(-[.0-9]+\\)?\\(:[0-9]+\\)?\\|^debug\\|^\\)>+ "
+  "Regexp to match prompts for the inferior Octave process."
   :type 'regexp
   :group 'octave-inferior)
 
 (defcustom inferior-octave-startup-file nil
   :type 'regexp
   :group 'octave-inferior)
 
 (defcustom inferior-octave-startup-file nil
-  "*Name of the inferior Octave startup file.
+  "Name of the inferior Octave startup file.
 The contents of this file are sent to the inferior Octave process on
 startup."
   :type '(choice (const :tag "None" nil)
 The contents of this file are sent to the inferior Octave process on
 startup."
   :type '(choice (const :tag "None" nil)
@@ -56,34 +56,31 @@ startup."
   :group 'octave-inferior)
 
 (defcustom inferior-octave-startup-args nil
   :group 'octave-inferior)
 
 (defcustom inferior-octave-startup-args nil
-  "*List of command line arguments for the inferior Octave process.
+  "List of command line arguments for the inferior Octave process.
 For example, for suppressing the startup message and using `traditional'
 mode, set this to (\"-q\" \"--traditional\")."
   :type '(repeat string)
   :group 'octave-inferior)
 
 For example, for suppressing the startup message and using `traditional'
 mode, set this to (\"-q\" \"--traditional\")."
   :type '(repeat string)
   :group 'octave-inferior)
 
-(defvar inferior-octave-mode-map nil
-  "Keymap used in Inferior Octave mode.")
-(if inferior-octave-mode-map
-    ()
-  (let ((map (copy-keymap comint-mode-map)))
+(defvar inferior-octave-mode-map
+  (let ((map (make-sparse-keymap)))
+    (set-keymap-parent map comint-mode-map)
     (define-key map "\t" 'comint-dynamic-complete)
     (define-key map "\M-?" 'comint-dynamic-list-filename-completions)
     (define-key map "\C-c\C-l" 'inferior-octave-dynamic-list-input-ring)
     (define-key map [menu-bar inout list-history]
       '("List Input History" . inferior-octave-dynamic-list-input-ring))
     (define-key map "\C-c\C-h" 'octave-help)
     (define-key map "\t" 'comint-dynamic-complete)
     (define-key map "\M-?" 'comint-dynamic-list-filename-completions)
     (define-key map "\C-c\C-l" 'inferior-octave-dynamic-list-input-ring)
     (define-key map [menu-bar inout list-history]
       '("List Input History" . inferior-octave-dynamic-list-input-ring))
     (define-key map "\C-c\C-h" 'octave-help)
-    (setq inferior-octave-mode-map map)))
+    map)
+  "Keymap used in Inferior Octave mode.")
 
 
-(defvar inferior-octave-mode-syntax-table nil
-  "Syntax table in use in inferior-octave-mode buffers.")
-(if inferior-octave-mode-syntax-table
-    ()
+(defvar inferior-octave-mode-syntax-table
   (let ((table (make-syntax-table)))
     (modify-syntax-entry ?\` "w" table)
     (modify-syntax-entry ?\# "<" table)
     (modify-syntax-entry ?\n ">" table)
   (let ((table (make-syntax-table)))
     (modify-syntax-entry ?\` "w" table)
     (modify-syntax-entry ?\# "<" table)
     (modify-syntax-entry ?\n ">" table)
-    (setq inferior-octave-mode-syntax-table table)))
+    table)
+  "Syntax table in use in inferior-octave-mode buffers.")
 
 (defcustom inferior-octave-mode-hook nil
   "*Hook to be run when Inferior Octave mode is started."
 
 (defcustom inferior-octave-mode-hook nil
   "*Hook to be run when Inferior Octave mode is started."
@@ -116,6 +113,9 @@ the regular expression `comint-prompt-regexp', a buffer local variable."
 (defvar inferior-octave-complete-impossible nil
   "Non-nil means that `inferior-octave-complete' is impossible.")
 
 (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.
 (defvar inferior-octave-dynamic-complete-functions
   '(inferior-octave-complete comint-dynamic-complete-filename)
   "List of functions called to perform completion for inferior Octave.
@@ -154,9 +154,9 @@ Entry to this mode successively runs the hooks `comint-mode-hook' and
   (setq comint-input-ring-file-name
        (or (getenv "OCTAVE_HISTFILE") "~/.octave_hist")
        comint-input-ring-size (or (getenv "OCTAVE_HISTSIZE") 1024)
   (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-dynamic-complete-functions
-       inferior-octave-dynamic-complete-functions)
+       comint-input-filter-functions '(inferior-octave-directory-tracker))
+  (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))
   (comint-read-input-ring t)
 
   (run-mode-hooks 'inferior-octave-mode-hook))
@@ -221,11 +221,20 @@ startup file, `~/.emacs-octave'."
                   'identity inferior-octave-output-list "\n")
                  "\n"))))
 
                   '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"))
     ;; 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
 
     ;; O.k., now we are ready for the Inferior Octave startup commands.
     (let* (commands
@@ -233,10 +242,12 @@ startup file, `~/.emacs-octave'."
           (file (or inferior-octave-startup-file
                          (concat "~/.emacs-" program))))
       (setq 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 ">> "))
                  (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))
                  (if (file-exists-p file)
                      (format "source (\"%s\");\n" file))))
       (inferior-octave-send-list-and-digest commands))
@@ -272,8 +283,7 @@ is NOT available with versions of Octave prior to 2.0."
          (save-excursion
            (skip-syntax-backward "w_" (comint-line-beginning-position))
            (buffer-substring-no-properties (point) end)))
          (save-excursion
            (skip-syntax-backward "w_" (comint-line-beginning-position))
            (buffer-substring-no-properties (point) end)))
-        (proc (get-buffer-process inferior-octave-buffer))
-        (filter (process-filter proc)))
+        (proc (get-buffer-process inferior-octave-buffer)))
     (cond (inferior-octave-complete-impossible
           (error (concat
                   "Your Octave does not have `completion_matches'.  "
     (cond (inferior-octave-complete-impossible
           (error (concat
                   "Your Octave does not have `completion_matches'.  "
@@ -299,7 +309,7 @@ is NOT available with versions of Octave prior to 2.0."
            command inferior-octave-output-list)))))
 
 (defun inferior-octave-dynamic-list-input-ring ()
            command inferior-octave-output-list)))))
 
 (defun inferior-octave-dynamic-list-input-ring ()
-  "List the buffer's input history in a help buffer"
+  "List the buffer's input history in a help buffer."
   ;; We cannot use `comint-dynamic-list-input-ring', because it replaces
   ;; "completion" by "history reference" ...
   (interactive)
   ;; We cannot use `comint-dynamic-list-input-ring', because it replaces
   ;; "completion" by "history reference" ...
   (interactive)
@@ -387,12 +397,12 @@ Use \\[inferior-octave-resync-dirs] to resync if Emacs gets confused."
 This command queries the inferior Octave process about its current
 directory and makes this the current buffer's default directory."
   (interactive)
 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
 
 (provide 'octave-inf)
 
   (cd (car inferior-octave-output-list)))
 
 ;;; provide ourself
 
 (provide 'octave-inf)
 
-;;; arch-tag: bdce0395-24d1-4bb4-bfba-6fb1eeb1a660
+;; arch-tag: bdce0395-24d1-4bb4-bfba-6fb1eeb1a660
 ;;; octave-inf.el ends here
 ;;; octave-inf.el ends here