From octave-sources-request at bevo dot che dot wisc dot edu Mon Dec 13 04:16:40 1999 Subject: octave-var.el: load numbers from an Emacs buffer into Octave From: Stephen Eglen To: octave-sources at bevo dot che dot wisc dot edu Date: Mon, 13 Dec 1999 10:16:32 GMT ;; octave-var.el --- Load numbers from an Emacs buffer into an octave variable. ;; ;; Example: ;; Let's say that you have an Emacs buffer containing the following text: ;; ;; 1 3 4 ;; 2 5 6 ;; ;; and you want this array stored in an octave variable, x. You could ;; of course cut out the relevant region, save the region in a ;; temporary file and then use aload() to load the data into octave. ;; This elisp function does exactly that, saving you the trouble of ;; making the temporary file. ;; ;; Simply put the mark at the start of the array (at the 1), point at ;; the end of the array (after 6) and then call M-x octave-var. You ;; are prompted for the name of the octave variable to store the array ;; in. The data is then loaded into the inferior octave process. ;; ;; Small bug - make sure your inferior octave process is running first, ;; otherwise it doesn't work (not sure why yet). (defun octave-var (beg end) "Load the current region of numbers into an octave variable. Prompts for a variable name. If none is given, it uses a default variable name e (for Emacs)." (interactive "r") (let ( (tmp-file "/tmp/octvar00") cmd var) (write-region beg end tmp-file) ;; Decide on the variable name to use in Octave. (setq var (read-string "variable name (default e): ")) (if (equal var "") (setq var "e")) ;; Create the aload command to send to octave. ;; x = aload("/tmp/oc-1"); (setq cmd (concat var " = aload(\"" tmp-file "\");")) ;; Send the command to the octave process. (with-temp-buffer (insert cmd) (octave-send-region (point-min) (point-max)) ) ))