]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/octave-inf.el
(grep-default-command): Take empty string
[gnu-emacs] / lisp / progmodes / octave-inf.el
index 12b29550f578b01771602ffa07d33f9250d2d81b..265cf6c049b14389bfe30445667aaae08bf1be8e 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 Free Software Foundation, Inc.
+;; Copyright (C) 1997 Free Software Foundation, Inc.
 
 ;; Author: Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>
 ;; Author: John Eaton <jwe@bevo.che.wisc.edu>
 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 ;; Boston, MA 02111-1307, USA.
 
+;;; Commentary:
+
 ;;; Code:
 
 (require 'octave-mod)
 (require 'comint)
 
-(defvar inferior-octave-program "octave"
-  "*Program invoked by `inferior-octave'.")
+(defgroup octave-inferior nil
+  "Running Octave as an inferior Emacs process."
+  :group 'octave)
+
+(defcustom inferior-octave-program "octave"
+  "*Program invoked by `inferior-octave'."
+  :type 'string
+  :group 'octave-inferior)
 
-(defvar inferior-octave-prompt "\\(^octave\\(:[0-9]+\\)?\\|^\\)>+ "
-  "*Regexp to match prompts for the inferior Octave process.")
+(defcustom inferior-octave-prompt
+  "\\(^octave\\(\\|.bin\\)\\(-[.0-9]+\\)?\\(:[0-9]+\\)?\\|^debug\\|^\\)>+ "
+  "*Regexp to match prompts for the inferior Octave process."
+  :type 'regexp
+  :group 'octave-inferior)
 
-(defvar inferior-octave-startup-file nil
+(defcustom inferior-octave-startup-file nil
   "*Name of the inferior Octave startup file.
 The contents of this file are sent to the inferior Octave process on
-startup.")
+startup."
+  :type '(choice (const :tag "None" nil)
+                file)
+  :group 'octave-inferior)
 
-(defvar inferior-octave-startup-args nil
+(defcustom inferior-octave-startup-args nil
   "*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\").")
+mode, set this to (\"-q\" \"--traditional\")."
+  :type '(repeat string)
+  :group 'octave-inferior)
 
 (defvar inferior-octave-mode-map nil
   "Keymap used in Inferior Octave mode.")
@@ -68,8 +84,10 @@ mode, set this to (\"-q\" \"--traditional\").")
     (modify-syntax-entry ?\n ">" table)
     (setq inferior-octave-mode-syntax-table table)))
 
-(defvar 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."
+  :type 'hook
+  :group 'octave-inferior)
 
 (defvar inferior-octave-font-lock-keywords
   (list
@@ -77,6 +95,17 @@ mode, set this to (\"-q\" \"--traditional\").")
   ;; Could certainly do more font locking in inferior Octave ...
   "Additional expressions to highlight in Inferior Octave mode.")
 
+
+;;; Compatibility functions
+(if (not (fboundp 'comint-line-beginning-position))
+    ;; comint-line-beginning-position is defined in Emacs 21
+    (defun comint-line-beginning-position ()
+      "Returns the buffer position of the beginning of the line, after any prompt.
+The prompt is assumed to be any text at the beginning of the line matching
+the regular expression `comint-prompt-regexp', a buffer local variable."
+      (save-excursion (comint-bol nil) (point))))
+
+
 (defvar inferior-octave-output-list nil)
 (defvar inferior-octave-output-string nil)
 (defvar inferior-octave-receive-in-progress nil)
@@ -87,7 +116,7 @@ mode, set this to (\"-q\" \"--traditional\").")
   "Non-nil means that `inferior-octave-complete' is impossible.")
 
 (defvar inferior-octave-dynamic-complete-functions
-  '(inferior-octave-complete comint-dynamic-complete-filename)  
+  '(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.")
@@ -109,12 +138,12 @@ Entry to this mode successively runs the hooks `comint-mode-hook' and
   (use-local-map inferior-octave-mode-map)
   (set-syntax-table inferior-octave-mode-syntax-table)
 
-  (make-local-variable 'comment-start)  
+  (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)    
+  (setq comment-column 32)
   (make-local-variable 'comment-start-skip)
   (setq comment-start-skip octave-comment-start-skip)
 
@@ -166,7 +195,8 @@ startup file, `~/.emacs-octave'."
               (substring inferior-octave-buffer 1 -1)
               inferior-octave-buffer
               inferior-octave-program
-              inferior-octave-startup-args)))
+              (append (list "-i" "--no-line-editing")
+                      inferior-octave-startup-args))))
     (set-process-filter proc 'inferior-octave-output-digest)
     (setq comint-ptyp process-connection-type
          inferior-octave-process proc
@@ -197,7 +227,7 @@ startup file, `~/.emacs-octave'."
       (setq commands
            (list "page_screen_output = 0;\n"
                  (if (not (string-equal
-                           inferior-octave-output-string ">> ")) 
+                           inferior-octave-output-string ">> "))
                      "PS1=\"\\\\s> \";\n")
                  (if (file-exists-p file)
                      (format "source (\"%s\");\n" file))))
@@ -226,11 +256,10 @@ This is implemented using the Octave command `completion_matches' which
 is NOT available with versions of Octave prior to 2.0."
   (interactive)
   (let* ((end (point))
-        (command (save-excursion
-                   (skip-syntax-backward "w_")
-                   (and (looking-at comint-prompt-regexp)
-                        (goto-char (match-end 0)))
-                   (buffer-substring-no-properties (point) end)))
+        (command
+         (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)))
     (cond (inferior-octave-complete-impossible
@@ -335,9 +364,11 @@ output is passed to the filter `inferior-octave-output-digest'."
 (defun inferior-octave-directory-tracker (string)
   "Tracks `cd' commands issued to the inferior Octave process.
 Use \\[inferior-octave-resync-dirs] to resync if Emacs gets confused."
-  (if (string-match "[ \t]*cd[ \t]*\\([^ \t\n;]*\\)[ \t\n;]"
-                   string)
-      (cd (substring string (match-beginning 1) (match-end 1)))))
+  (cond
+   ((string-match "^[ \t]*cd[ \t;]*$" string)
+    (cd "~"))
+   ((string-match "^[ \t]*cd[ \t]+\\([^ \t\n;]*\\)[ \t\n;]*" string)
+    (cd (substring string (match-beginning 1) (match-end 1))))))
 
 (defun inferior-octave-resync-dirs ()
   "Resync the buffer's idea of the current directory.
@@ -351,4 +382,5 @@ directory and makes this the current buffer's default directory."
 
 (provide 'octave-inf)
 
+;;; arch-tag: bdce0395-24d1-4bb4-bfba-6fb1eeb1a660
 ;;; octave-inf.el ends here