Skip to content

Instantly share code, notes, and snippets.

@mfrasca
Forked from anonymous/README
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mfrasca/330b268fa62b390ec2dc to your computer and use it in GitHub Desktop.
Save mfrasca/330b268fa62b390ec2dc to your computer and use it in GitHub Desktop.
testing interaction org-mode gnuplot-mode

what

this gist contains files to be used in emacs, to test the interaction between org-mode (more specifically, org-plot/gnuplot) and gnuplot-mode.

why

the goal is to have org-plot/gnuplot consistently update the gnuplot output buffer holding the svg graph generated by gnuplot. when this gist was created, this does not work consistently.

content

files in this gist:

  • table.org. an org file holding tabular data

usage

  • start emacs
  • configure gnuplot-mode to output to a dedicated buffer in svg format
  • open a buffer with the `table.org` table
  • execute `org-plot/gnuplot`
  • (here I would like to see the emacs screen split in two parts, one with the gnuplot output buffer.)
  • since the above does not happen, do it by hand.
  • change whatever you want to change in the table - for example deps:(4)
  • again execute `org-plot/gnuplot`
  • (here I would like to see the gnuplot output buffer updated)
  • repeating this last block, I observe rather erratic behaviour.

futilities

if the reader might be wondering, the data in the file are real measurements of well salinity, associated with water extraction from the same well, trying to establish any link between the two. the well is the “Concordia” well on Sint Eustatius.

(defun org-plot/gnuplot (&optional params)
"Plot table using gnuplot. Gnuplot options can be specified with PARAMS.
If not given options will be taken from the +PLOT
line directly before or after the table."
(interactive)
(message "entering org-plot/gnuplot" )
(require 'gnuplot)
(save-window-excursion
(message "will delete-other-windows" )
(delete-other-windows)
(message "did delete-other-windows" )
(when (get-buffer "*gnuplot*") ;; reset *gnuplot* if it already running
(message "will with-current-buffer" )
(with-current-buffer "*gnuplot*"
(goto-char (point-max))
(gnuplot-delchar-or-maybe-eof nil))
(message "did with-current-buffer" ))
(org-plot/goto-nearest-table)
;; set default options
(mapc
(lambda (pair)
(unless (plist-member params (car pair))
(setf params (plist-put params (car pair) (cdr pair)))))
org-plot/gnuplot-default-options)
;; collect table and table information
(let* ((data-file (make-temp-file "org-plot"))
(table (org-table-to-lisp))
(num-cols (length (if (eq (first table) 'hline) (second table)
(first table)))))
(while (equal 'hline (first table)) (setf table (cdr table)))
(when (equal (second table) 'hline)
(setf params (plist-put params :labels (first table))) ;; headers to labels
(setf table (delq 'hline (cdr table)))) ;; clean non-data from table
;; collect options
(message "before collect options" )
(save-excursion (while (and (equal 0 (forward-line -1))
(looking-at "[[:space:]]*#\\+"))
(setf params (org-plot/collect-options params))))
;; dump table to datafile (very different for grid)
(message "before dump table to datafile" )
(case (plist-get params :plot-type)
('2d (org-plot/gnuplot-to-data table data-file params))
('3d (org-plot/gnuplot-to-data table data-file params))
('grid (let ((y-labels (org-plot/gnuplot-to-grid-data
table data-file params)))
(when y-labels (plist-put params :ylabels y-labels)))))
(run-with-idle-timer 0.1 nil (lambda () (delete-file data-file)))
;; check for timestamp ind column
(message "before check for timestamp ind column" )
(let ((ind (- (plist-get params :ind) 1)))
(when (and (>= ind 0) (equal '2d (plist-get params :plot-type)))
(if (= (length
(delq 0 (mapcar
(lambda (el)
(if (string-match org-ts-regexp3 el)
0 1))
(mapcar (lambda (row) (nth ind row)) table)))) 0)
(plist-put params :timeind t)
;; check for text ind column
(if (or (string= (plist-get params :with) "hist")
(> (length
(delq 0 (mapcar
(lambda (el)
(if (string-match org-table-number-regexp el)
0 1))
(mapcar (lambda (row) (nth ind row)) table)))) 0))
(plist-put params :textind t)))))
(message "before write script" )
;; write script
(with-temp-buffer
(if (plist-get params :script) ;; user script
(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)))
(insert "\n")
(message "at-end: %s" params)
;; graph table
(gnuplot-mode)
(gnuplot-send-buffer-to-gnuplot))
;; cleanup
(bury-buffer (get-buffer "*gnuplot*")))))
DateDaysmS/cmDegGallonsm³/d
2014-09-26#ERROR3.032.539473100
2014-09-293.02.9633.7397719037.702695
2014-10-012.02.9633.7399847040.276774
2014-10-032.02.9533.7403107061.702201
2014-10-063.03.0733.7408693070.484355
2014-10-071.02.96410003049.588885
2014-10-081.02.97411959074.042641
2014-10-091.02.99414009077.600928
2014-10-101.02.63414459017.034350
2014-10-111.03.06416696084.679646
2014-10-121.03418564070.711479
2014-10-131.03.01420629078.168739
2014-10-141.02.96422605074.799723
2014-10-151.02.99424591075.178264
2014-10-161.03.0732.8425333028.087750
2014-10-171.03.1333.7427123067.758859
2014-10-181.03.0433.242730206.7758859
2014-10-191.03.1233.4427864021.274010
2014-10-201.03.0932.742812609.9177771
2014-10-211.03.0833.8429149038.724756
2014-10-221.02.9933.1430518051.822278
2014-10-231.03.133.0431143023.658819
2014-10-241.03.0933.3431800024.870151
2014-10-251.03.0633.5432348020.744053
2014-10-261.03.1533.2433314036.567071
2014-10-271.02.9933.6434124030.661830
2014-10-281.03.1132.2434935030.699684
2014-10-291.03.0632.9435656027.292814
2014-10-301.03.0633.0436276023.469549
2014-10-311.03.1433.1436828020.895469
2014-11-011.03.0933.2437404021.803968
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment