Selaa lähdekoodia

org-plot: Allow prepending a user script

Carsten Dominik 16 vuotta sitten
vanhempi
commit
9ec9d79adc
1 muutettua tiedostoa jossa 15 lisäystä ja 9 poistoa
  1. 15 9
      lisp/org-plot.el

+ 15 - 9
lisp/org-plot.el

@@ -181,9 +181,11 @@ and dependant variables."
 	    (setf back-edge "") (setf front-edge "")))))
     row-vals))
 
-(defun org-plot/gnuplot-script (data-file num-cols params)
+(defun org-plot/gnuplot-script (data-file num-cols params &optional preface)
   "Write a gnuplot script to DATA-FILE respecting the options set in PARAMS.
-NUM-COLS controls the number of columns plotted in a 2-d plot."
+NUM-COLS controls the number of columns plotted in a 2-d plot.
+Optional argument PREFACE returns only option parameters in a
+manner suitable for prepending to a user-specified script."
   (let* ((type (plist-get params :plot-type))
 	 (with (if (equal type 'grid)
 		   'pm3d
@@ -238,7 +240,8 @@ NUM-COLS controls the number of columns plotted in a 2-d plot."
 	(add-to-script (concat "set timefmt \""
 			       (or timefmt ;; timefmt passed to gnuplot
 				   "%Y-%m-%d-%H:%M:%S") "\"")))
-      (case type ;; plot command
+      (unless preface
+        (case type ;; plot command
 	('2d (dotimes (col num-cols)
 	       (unless (and (equal type '2d)
 			    (or (and ind (equal (+ 1 col) ind))
@@ -259,8 +262,8 @@ NUM-COLS controls the number of columns plotted in a 2-d plot."
 	('grid
 	 (setq plot-lines (list (format "'%s' with %s title ''"
 					data-file with)))))
-      (add-to-script
-       (concat plot-cmd " " (mapconcat 'identity (reverse plot-lines) ",\\\n    ")))
+        (add-to-script
+         (concat plot-cmd " " (mapconcat 'identity (reverse plot-lines) ",\\\n    "))))
       script)))
 
 ;;-----------------------------------------------------------------------------
@@ -328,10 +331,13 @@ line directly before or after the table."
       ;; write script
       (with-temp-buffer
 	(if (plist-get params :script) ;; user script
-	    (progn (insert-file-contents (plist-get params :script))
-		   (goto-char (point-min))
-		   (while (re-search-forward "$datafile" nil t)
-		     (replace-match data-file nil nil)))
+	    (progn (insert
+                    (org-plot/gnuplot-script data-file num-cols params t))
+                   (insert "\n")
+                   (insert-file-contents (plist-get params :script))
+                   (goto-char (point-min))
+                   (while (re-search-forward "$datafile" nil t)
+                     (replace-match data-file nil nil)))
 	  (insert
 	   (org-plot/gnuplot-script data-file num-cols params)))
 	;; graph table