Browse Source

DONE gnuplot sessions

Eric Schulte 16 years ago
parent
commit
85dc35656d
2 changed files with 27 additions and 8 deletions
  1. 12 6
      lisp/langs/org-babel-gnuplot.el
  2. 15 2
      org-babel.org

+ 12 - 6
lisp/langs/org-babel-gnuplot.el

@@ -42,7 +42,8 @@
 
 (add-to-list 'org-babel-tangle-langs '("gnuplot" "gnuplot"))
 
-(defvar org-babel-default-header-args:gnuplot '((:results . "file") (:exports . "results"))
+(defvar org-babel-default-header-args:gnuplot
+  '((:results . "file") (:exports . "results") (:session . nil))
   "Default arguments to use when evaluating a gnuplot source block.")
 
 (defvar org-babel-gnuplot-timestamp-fmt nil)
@@ -112,10 +113,16 @@ called by `org-babel-execute-src-block' via multiple-value-bind."
                     (lambda (pair) (format "%s = \"%s\"" (car pair) (cdr pair)))
                     vars "\n"))
       ;; evaluate the code body with gnuplot
-      (with-temp-buffer
-        (insert (concat body "\n"))
-        (gnuplot-mode)
-        (gnuplot-send-buffer-to-gnuplot))
+      (if (string= session "none")
+          (let ((script-file (make-temp-file "org-babel-gnuplot-script")))
+            (with-temp-file script-file
+              (insert (concat body "\n")))
+            (message "gnuplot \"%s\"" script-file)
+            (message (shell-command-to-string (format "gnuplot \"%s\"" script-file))))
+        (with-temp-buffer
+          (insert (concat body "\n"))
+          (gnuplot-mode)
+          (gnuplot-send-buffer-to-gnuplot)))
       out-file)))
 
 (defun org-babel-prep-session:gnuplot (session params)
@@ -156,7 +163,6 @@ then create.  Return the initialized session.  The current
   "Export TABLE to DATA-FILE in a format readable by gnuplot.
 Pass PARAMS through to `orgtbl-to-generic' when exporting TABLE."
   (with-temp-file data-file
-    (message "table = %S" table)
     (make-local-variable 'org-babel-gnuplot-timestamp-fmt)
     (setq org-babel-gnuplot-timestamp-fmt (or
                                            (plist-get params :timefmt)

+ 15 - 2
org-babel.org

@@ -2266,7 +2266,7 @@ This could probably be added to [[file:lisp/org-babel-script.el][org-babel-scrip
 #+resname: implementing-ditaa
 [[file:blue.png][blue.png]]
 
-*** STARTED gnuplot [6/8]
+*** STARTED gnuplot [7/8]
 (see [[* file result types][file result types]])
 
 #+PLOT: title:"Citas" ind:1 deps:(3) type:2d with:histograms set:"yrange [0:]"
@@ -2355,10 +2355,23 @@ These should all be in place by now.
 
 #+end_src
 
-**** STARTED gnuplot sessions
+**** DONE gnuplot sessions
 Working on this, we won't support multiple sessions as `gnuplot-mode'
 isn't setup for such things.
 
+Also we can't display results with the default :none session, so for
+gnuplot we really want the default behavior to be :default, and to
+only run a :none session when explicitly specified.
+
+#+srcname: implementing-gnuplot-sessions
+#+begin_src gnuplot :var data=gnuplot-data :session none :file session.png
+set title "Implementing Gnuplot Sessions"
+plot data using 1:2 with lines
+#+end_src
+
+#+resname:
+[[file:session.png][session.png]]
+
 **** TODO gnuplot LoB functionality
 
 maybe some of this helper driven plotting functionality should be