From 0d634d3a3c2ad4e0a741b3e42a1784e6f2d797dc Mon Sep 17 00:00:00 2001 From: Leo Liu Date: Fri, 3 May 2013 05:34:53 +0800 Subject: [PATCH] * progmodes/octave.el (inferior-octave-startup-file): Change default. (inferior-octave): Remove calling comint-mode and return the buffer. (inferior-octave-startup): Cosmetic changes. --- lisp/ChangeLog | 6 +++ lisp/progmodes/octave.el | 84 +++++++++++++++++++--------------------- 2 files changed, 46 insertions(+), 44 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 79fd3820074..695f66c272c 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,9 @@ +2013-05-02 Leo Liu + + * progmodes/octave.el (inferior-octave-startup-file): Change default. + (inferior-octave): Remove calling comint-mode and return the buffer. + (inferior-octave-startup): Cosmetic changes. + 2013-05-02 Leo Liu * progmodes/octave.el (octave-syntax-propertize-function): Include diff --git a/lisp/progmodes/octave.el b/lisp/progmodes/octave.el index 3252b16cbad..56f2805d48e 100644 --- a/lisp/progmodes/octave.el +++ b/lisp/progmodes/octave.el @@ -553,13 +553,15 @@ See `comint-prompt-read-only' for details." :group 'octave :version "24.4") -(defcustom inferior-octave-startup-file nil +(defcustom inferior-octave-startup-file + (convert-standard-filename + (concat "~/.emacs-" (file-name-nondirectory inferior-octave-program))) "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) - file) - :group 'octave) + :type '(choice (const :tag "None" nil) file) + :group 'octave + :version "24.4") (defcustom inferior-octave-startup-args nil "List of command line arguments for the inferior Octave process. @@ -650,16 +652,14 @@ Additional commands to be executed on startup can be provided either in the file specified by `inferior-octave-startup-file' or by the default startup file, `~/.emacs-octave'." (interactive "P") - (let ((buffer inferior-octave-buffer)) - (get-buffer-create buffer) - (if (comint-check-proc buffer) - () + (let ((buffer (get-buffer-create inferior-octave-buffer))) + (unless (comint-check-proc buffer) (with-current-buffer buffer - (comint-mode) - (inferior-octave-startup) - (inferior-octave-mode))) - (if (not arg) - (pop-to-buffer buffer)))) + (inferior-octave-startup) + (inferior-octave-mode))) + (unless arg + (pop-to-buffer buffer)) + buffer)) ;;;###autoload (defalias 'run-octave 'inferior-octave) @@ -667,17 +667,16 @@ startup file, `~/.emacs-octave'." (defun inferior-octave-startup () "Start an inferior Octave process." (let ((proc (comint-exec-1 - (substring inferior-octave-buffer 1 -1) - inferior-octave-buffer - inferior-octave-program - (append (list "-i" "--no-line-editing") - inferior-octave-startup-args)))) + (substring inferior-octave-buffer 1 -1) + inferior-octave-buffer + inferior-octave-program + (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 - inferior-octave-output-list nil - inferior-octave-output-string nil - inferior-octave-receive-in-progress t) + (setq inferior-octave-process proc + inferior-octave-output-list nil + inferior-octave-output-string nil + inferior-octave-receive-in-progress t) ;; This may look complicated ... However, we need to make sure that ;; we additional startup code only AFTER Octave is ready (otherwise, @@ -691,35 +690,32 @@ startup file, `~/.emacs-octave'." (concat (if (not (bobp)) " \n") (if inferior-octave-output-list - (concat (mapconcat - 'identity inferior-octave-output-list "\n") - "\n")))) + (concat (mapconcat + 'identity inferior-octave-output-list "\n") + "\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\\|ans\\) = *$" (car inferior-octave-output-list)) - (inferior-octave-send-list-and-digest (list "PS2 (\"> \");\n"))) + (when (string-match "\\(PS2\\|ans\\) = *$" + (car inferior-octave-output-list)) + (inferior-octave-send-list-and-digest (list "PS2 (\"> \");\n"))) - ;; O.k., now we are ready for the Inferior Octave startup commands. - (let* (commands - (program (file-name-nondirectory inferior-octave-program)) - (file (or inferior-octave-startup-file - (concat "~/.emacs-" program)))) - (setq commands - (list "more off;\n" - (if (not (string-equal - inferior-octave-output-string ">> ")) - "PS1 (\"\\\\s> \");\n") - (if (file-exists-p file) - (format "source (\"%s\");\n" file)))) - (inferior-octave-send-list-and-digest commands)) + ;; O.K., now we are ready for the Inferior Octave startup commands. + (inferior-octave-send-list-and-digest + (list "more off;\n" + (unless (equal inferior-octave-output-string ">> ") + "PS1 (\"\\\\s> \");\n") + (when (and inferior-octave-startup-file + (file-exists-p inferior-octave-startup-file)) + (format "source (\"%s\");\n" inferior-octave-startup-file)))) + ;; XXX: the first prompt is incorrectly highlighted (insert-before-markers (concat (if inferior-octave-output-list - (concat (mapconcat - 'identity inferior-octave-output-list "\n") - "\n")) + (concat (mapconcat + 'identity inferior-octave-output-list "\n") + "\n")) inferior-octave-output-string)) ;; And finally, everything is back to normal.