瀏覽代碼

org-babel-execute:gnuplot no longer pops up a gnuplot window

also some whitespace-only indentation changes in org-babel.el
Eric Schulte 15 年之前
父節點
當前提交
6ce74742b8
共有 2 個文件被更改,包括 65 次插入64 次删除
  1. 59 58
      contrib/babel/lisp/langs/org-babel-gnuplot.el
  2. 6 6
      contrib/babel/lisp/org-babel.el

+ 59 - 58
contrib/babel/lisp/langs/org-babel-gnuplot.el

@@ -72,64 +72,65 @@ variable names and the value to be used in the gnuplot code."
   "Execute a block of Gnuplot code with org-babel.  This function is
 called by `org-babel-execute-src-block' via multiple-value-bind."
   (message "executing Gnuplot source code block")
-  (let* ((vars (org-babel-gnuplot-process-vars params))
-         (out-file (cdr (assoc :file params)))
-         (term (or (cdr (assoc :term params))
-                   (when out-file (file-name-extension out-file))))
-         (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))
-	 (x-labels (plist-get params :xlabels))
-	 (y-labels (plist-get params :ylabels))
-	 (timefmt (plist-get params :timefmt))
-         (time-ind (or (plist-get params :timeind)
-                       (when timefmt 1))))
-    (flet ((add-to-body (text)
-                        (setq body (concat text "\n" body))))
-      ;; append header argument settings to body
-      (when title (add-to-body (format "set title '%s'" title))) ;; title
-      (when lines (mapc (lambda (el) (add-to-body el)) lines)) ;; line
-      (when sets
-        (mapc (lambda (el) (add-to-body (format "set %s" el))) sets))
-      (when x-labels
-        (add-to-body
-         (format "set xtics (%s)"
-                 (mapconcat (lambda (pair)
-                              (format "\"%s\" %d" (cdr pair) (car pair)))
-                            x-labels ", "))))
-      (when y-labels
-        (add-to-body
-         (format "set ytics (%s)"
-                 (mapconcat (lambda (pair)
-                              (format "\"%s\" %d" (cdr pair) (car pair)))
-                            y-labels ", "))))
-      (when time-ind
-        (add-to-body "set xdata time")
-        (add-to-body (concat "set timefmt \""
-                             (or timefmt
-                                 "%Y-%m-%d-%H:%M:%S") "\"")))
-      (when out-file (add-to-body (format "set output \"%s\"" out-file)))
-      (when term (add-to-body (format "set term %s" term)))
-      ;; insert variables into code body: this should happen last
-      ;; placing the variables at the *top* of the code in case their
-      ;; values are used later
-      (add-to-body (mapconcat
-                    (lambda (pair) (format "%s = \"%s\"" (car pair) (cdr pair)))
-                    vars "\n"))
-      ;; evaluate the code body with 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)))
+  (save-window-excursion
+    (let* ((vars (org-babel-gnuplot-process-vars params))
+           (out-file (cdr (assoc :file params)))
+           (term (or (cdr (assoc :term params))
+                     (when out-file (file-name-extension out-file))))
+           (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))
+           (x-labels (plist-get params :xlabels))
+           (y-labels (plist-get params :ylabels))
+           (timefmt (plist-get params :timefmt))
+           (time-ind (or (plist-get params :timeind)
+                         (when timefmt 1))))
+      (flet ((add-to-body (text)
+                          (setq body (concat text "\n" body))))
+        ;; append header argument settings to body
+        (when title (add-to-body (format "set title '%s'" title))) ;; title
+        (when lines (mapc (lambda (el) (add-to-body el)) lines)) ;; line
+        (when sets
+          (mapc (lambda (el) (add-to-body (format "set %s" el))) sets))
+        (when x-labels
+          (add-to-body
+           (format "set xtics (%s)"
+                   (mapconcat (lambda (pair)
+                                (format "\"%s\" %d" (cdr pair) (car pair)))
+                              x-labels ", "))))
+        (when y-labels
+          (add-to-body
+           (format "set ytics (%s)"
+                   (mapconcat (lambda (pair)
+                                (format "\"%s\" %d" (cdr pair) (car pair)))
+                              y-labels ", "))))
+        (when time-ind
+          (add-to-body "set xdata time")
+          (add-to-body (concat "set timefmt \""
+                               (or timefmt
+                                   "%Y-%m-%d-%H:%M:%S") "\"")))
+        (when out-file (add-to-body (format "set output \"%s\"" out-file)))
+        (when term (add-to-body (format "set term %s" term)))
+        ;; insert variables into code body: this should happen last
+        ;; placing the variables at the *top* of the code in case their
+        ;; values are used later
+        (add-to-body (mapconcat
+                      (lambda (pair) (format "%s = \"%s\"" (car pair) (cdr pair)))
+                      vars "\n"))
+        ;; evaluate the code body with 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)
   "Prepare SESSION according to the header arguments specified in PARAMS."

+ 6 - 6
contrib/babel/lisp/org-babel.el

@@ -164,10 +164,10 @@ the header arguments specified at the source code block."
          (lang (first info))
          (body (second info))
          (params (org-babel-merge-params
-		  (third info) (org-babel-get-src-block-function-args) params))
-	 (processed-params (org-babel-process-params params))
-	 (result-params (third processed-params))
-	 (result-type (fourth processed-params))
+                  (third info) (org-babel-get-src-block-function-args) params))
+         (processed-params (org-babel-process-params params))
+         (result-params (third processed-params))
+         (result-type (fourth processed-params))
          (cmd (intern (concat "org-babel-execute:" lang)))
          result)
     ;; (message "params=%S" params) ;; debugging statement
@@ -175,9 +175,9 @@ the header arguments specified at the source code block."
       (error "Language is not in `org-babel-interpreters': %s" lang))
     (when arg (setq result-params (cons "silent" result-params)))
     (setq result (multiple-value-bind (session vars result-params result-type) processed-params
-		   (funcall cmd body params)))
+                   (funcall cmd body params)))
     (if (eq result-type 'value)
-	(setq result (org-babel-process-value-result result result-params)))
+        (setq result (org-babel-process-value-result result result-params)))
     (org-babel-insert-result result result-params)
     (case result-type (output nil) (value result))))