Function: inferior-octave-startup
inferior-octave-startup is a byte-compiled function defined in
octave.el.gz.
Signature
(inferior-octave-startup)
Documentation
Start an inferior Octave process.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/octave.el.gz
(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
inferior-octave-startup-args
;; --no-gui is introduced in Octave > 3.7
(and (not (member "--no-gui" inferior-octave-startup-args))
(zerop (process-file inferior-octave-program
nil nil nil "--no-gui" "--help"))
'("--no-gui"))))))
(set-process-filter proc 'inferior-octave-output-digest)
(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,
;; output may be mixed up). Hence, we need to digest the Octave
;; output to see when it issues a prompt.
(while inferior-octave-receive-in-progress
(unless (inferior-octave-process-live-p)
;; Spit out the error messages.
(when inferior-octave-output-list
(princ (concat (mapconcat 'identity inferior-octave-output-list "\n")
"\n")
(process-mark inferior-octave-process)))
(error "Process `%s' died" inferior-octave-process))
(accept-process-output inferior-octave-process))
(goto-char (point-max))
(set-marker (process-mark proc) (point))
(insert-before-markers
(concat
(if (not (bobp)) "\n")
(if inferior-octave-output-list
(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"))
(when (string-match "\\(PS2\\|ans\\) = *$"
(car inferior-octave-output-list))
(inferior-octave-send-list-and-digest (list "PS2 ('> ');\n")))
(inferior-octave-send-list-and-digest
(list "disp (getenv ('OCTAVE_SRCDIR'))\n"))
(process-put proc 'octave-srcdir
(unless (equal (car inferior-octave-output-list) "")
(car inferior-octave-output-list)))
;; 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 ">> ")
;; See https://hg.savannah.gnu.org/hgweb/octave/rev/708173343c50
"PS1 ('octave> ');\n")
(when (and inferior-octave-startup-file
(file-exists-p inferior-octave-startup-file))
(format "source ('%s');\n" inferior-octave-startup-file))))
(when inferior-octave-output-list
(insert-before-markers
(mapconcat 'identity inferior-octave-output-list "\n")))
;; And finally, everything is back to normal.
(set-process-filter proc 'comint-output-filter)
;; Just in case, to be sure a cd in the startup file won't have
;; detrimental effects.
(with-demoted-errors "Octave resync error: %S"
(inferior-octave-resync-dirs))
;; Generate a proper prompt, which is critical to
;; `comint-history-isearch-backward-regexp'. Bug#14433.
(comint-send-string proc "\n")))