Kaynağa Gözat

pulled the gnuplot variable processing out into it's own function

Eric Schulte 16 yıl önce
ebeveyn
işleme
01c6bd2b33
2 değiştirilmiş dosya ile 36 ekleme ve 29 silme
  1. 24 28
      lisp/langs/org-babel-gnuplot.el
  2. 12 1
      org-babel.org

+ 24 - 28
lisp/langs/org-babel-gnuplot.el

@@ -47,32 +47,41 @@
 
 (defvar org-babel-gnuplot-timestamp-fmt nil)
 
+(defun org-babel-gnuplot-process-vars (params)
+  "Extract variables from PARAMS and process the variables
+dumping all vectors into files returning an association list of
+variable names and the value to be used in the gnuplot code."
+  (mapcar
+   (lambda (pair)
+     (cons
+      (car pair) ;; variable name
+      (if (listp (cdr pair)) ;; variable value
+          (org-babel-gnuplot-table-to-data
+           (cdr pair) (make-temp-file "org-babel-gnuplot") params)
+        (cdr pair))))
+   (org-babel-ref-variables params)))
+
 (defun org-babel-execute:gnuplot (body params)
   "Execute a block of Gnuplot code with org-babel.  This function is
 called by `org-babel-execute-src-block'."
   (message "executing Gnuplot source code block")
-  (let* ((vars (org-babel-ref-variables params))
+  (let* ((vars (org-babel-gnuplot-process-vars params))
          (result-params (split-string (or (cdr (assoc :results params)) "")))
          (out-file (cdr (assoc :file params)))
          (cmdline (cdr (assoc :cmdline params)))
          (in-file (make-temp-file "org-babel-ditaa"))
 	 (title (plist-get params :title))
          (lines (plist-get params :line))
-	 (sets (plist-get params :set))         
+	 (sets (plist-get params :set))
 	 (x-labels (plist-get params :xlabels))
 	 (y-labels (plist-get params :ylabels))
 	 (time-ind (plist-get params :timeind)))
     ;; insert variables into code body
     (mapc
      (lambda (pair)
-       (message "resolving %S" pair) ;; debugging
        (setq body
              (replace-regexp-in-string
-              (regexp-quote (format "%s" (car pair)))
-              (if (listp (cdr pair))
-                  (org-babel-gnuplot-table-to-data
-                   (cdr pair) (make-temp-file "org-babel-gnuplot") params)
-                (cdr pair)) body)))
+              (regexp-quote (format "%s" (car pair))) (cdr pair) body)))
      vars)
     ;; append header argument settings to body
     (when title (add-to-script (format "set title '%s'" title))) ;; title
@@ -106,30 +115,17 @@ called by `org-babel-execute-src-block'."
 (defun org-babel-prep-session:gnuplot (session params)
   "Prepare SESSION according to the header arguments specified in PARAMS."
   (let* ((session (org-babel-gnuplot-initiate-session session))
-         (vars (org-babel-ref-variables params))
-         (var-lines (mapcar ;; define any variables
-                     (lambda (pair)
-                       (format "%s=%s"
-                               (car pair)
-                               (org-babel-ruby-var-to-ruby (cdr pair))))
-                     vars)))
-    ;; (message "vars=%S" vars) ;; debugging
-    (org-babel-comint-in-buffer session
-      (sit-for .5) (goto-char (point-max))
-      (mapc (lambda (var)
-              (insert var) (comint-send-input nil t)
-              (org-babel-comint-wait-for-output session)
-              (sit-for .1) (goto-char (point-max))) var-lines))))
+         (vars (org-babel-ref-variables params)))
+    
+    ))
 
 (defun org-babel-gnuplot-initiate-session (&optional session)
   "If there is not a current inferior-process-buffer in SESSION
-then create.  Return the initialized session."
+then create.  Return the initialized session.  The current
+`gnuplot-mode' doesn't provide support for multiple sessions."
   (unless (string= session "none")
-    (let ((session-buffer (save-window-excursion (run-ruby nil session) (current-buffer))))
-      (if (org-babel-comint-buffer-livep session-buffer)
-          session-buffer
-        (sit-for .5)
-        (org-babel-ruby-initiate-session session)))))
+    (save-window-excursion (gnuplot-send-string-to-gnuplot "" "line")
+                           (current-buffer))))
 
 (defun org-babel-gnuplot-quote-timestamp-field (s)
   "Convert field S from timestamp to Unix time and export to gnuplot."

+ 12 - 1
org-babel.org

@@ -2095,7 +2095,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 [3/7]
+*** STARTED gnuplot [3/8]
 (see [[* file result types][file result types]])
 
 #+PLOT: title:"Citas" ind:1 deps:(3) type:2d with:histograms set:"yrange [0:]"
@@ -2122,6 +2122,8 @@ set title "Implementing Gnuplot"
 plot "data" using 1:2 with lines
 #+end_src
 
+
+
 **** DONE add variables
      - scalar variables should be replaced in the body of the gnuplot code
      - vector variables should be exported to tab-separated files, and
@@ -2148,6 +2150,15 @@ into custom gnuplot header arguments
 
 **** TODO header argument specifying 3D data
 **** TODO gnuplot sessions
+Working on this, not sure how to rename a gnuplot session.
+
+**** TODO gnuplot LoB functionality
+
+maybe some of this helper driven plotting functionality should be
+packaged into Library of Babel functions.
+
+- [[http://www.nabble.com/How-to-use-table-header-as-title-inside-for-loops--td22414504.html][table-header-as-columns]]
+
 *** TODO dot
 (see [[* file result types][file result types]])