help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: client/server operation of octave?


From: Sean O'Rourke
Subject: Re: client/server operation of octave?
Date: Wed, 10 Jan 2007 05:59:04 -0800
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.92 (darwin)

Peter Cloetens <address@hidden> writes:
> This seems interesting. Would it be possible to provide some
> more details?

First, compile and install attachtty (google for webpage).  Then
start octave like

    detachtty $OCTAVE_SOCKET $(which octave) -q --no-line-editing

on the host on which you want to run Octave.  Then connect to
that octave by either using

    attachtty $OCTAVE_SOCKET

on the remote host, or setting `octave-remote-host' to
"$HOST:$OCTAVE_SOCKET" and aliasing the following to
`inferior-octave-startup' in Emacs:

    (defun my-inferior-octave-startup ()
      "Start an inferior Octave process."
      (let ((proc (comint-exec-1
               (substring inferior-octave-buffer 1 -1)
               inferior-octave-buffer
               (if octave-remote-host "/usr/local/bin/attachtty"
                       inferior-octave-program)
                   (if octave-remote-host
                       (list octave-remote-host)
                       (concatenate 'list
                                    inferior-octave-startup-args
                                    (list "-i" "--no-line-editing"))))))
        (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)
    
        ;; 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.
        (if octave-remote-host
            (sit-for 1)
            (while inferior-octave-receive-in-progress
              (accept-process-output inferior-octave-process)))
        (goto-char (point-max))
        (set-marker (process-mark proc) (point))
        (unless octave-remote-host
          (insert-before-markers
           (concat
            (if (not (bobp)) "\n")
            (if inferior-octave-output-list
                (concat (mapconcat
                         'identity inferior-octave-output-list "\n")
                        "\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 "page_screen_output = 0;\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))
          (insert-before-markers
           (concat
            (if inferior-octave-output-list
                (concat (mapconcat
                         'identity inferior-octave-output-list "\n")
                        "\n"))
            inferior-octave-output-string))
          ;; Next, we check whether Octave supports `completion_matches' ...
          (inferior-octave-send-list-and-digest
           (list "exist \"completion_matches\"\n"))
          (setq inferior-octave-complete-impossible
                (not (string-match "5$" (car inferior-octave-output-list)))))
    
        ;; And finally, everything is back to normal.
        (set-process-filter proc 'inferior-octave-output-filter)
        (run-hooks 'inferior-octave-startup-hook)))

I use this all the time to control Octave on a cluster, and it's
pretty nice.

/s


reply via email to

[Prev in Thread] Current Thread [Next in Thread]