mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-08-25 13:02:51 +00:00
table assignment now working for ruby and python
This commit is contained in:
parent
5805507dc3
commit
c814a9f3e8
|
@ -1,8 +1,8 @@
|
||||||
;;; init.el --- loads litorgy
|
;;; init.el --- loads litorgy
|
||||||
|
|
||||||
;; Copyright (C) 2009 Eric Schulte, Dan Davison, Austin F. Frank
|
;; Copyright (C) 2009 Eric Schulte
|
||||||
|
|
||||||
;; Author: Eric Schulte, Dan Davison, Austin F. Frank
|
;; Author: Eric Schulte
|
||||||
;; Keywords: literate programming, reproducible research
|
;; Keywords: literate programming, reproducible research
|
||||||
;; Homepage: http://orgmode.org
|
;; Homepage: http://orgmode.org
|
||||||
;; Version: 0.01
|
;; Version: 0.01
|
||||||
|
@ -34,8 +34,8 @@
|
||||||
(require 'litorgy-reference)
|
(require 'litorgy-reference)
|
||||||
|
|
||||||
;; language specific files
|
;; language specific files
|
||||||
|
(require 'litorgy-script)
|
||||||
(require 'litorgy-R)
|
(require 'litorgy-R)
|
||||||
(require 'litorgy-lisp)
|
(require 'litorgy-lisp)
|
||||||
(require 'litorgy-script)
|
|
||||||
|
|
||||||
;;; init.el ends here
|
;;; init.el ends here
|
||||||
|
|
|
@ -37,8 +37,9 @@
|
||||||
(setq litorgy-interpreters (cons cmd litorgy-interpreters))
|
(setq litorgy-interpreters (cons cmd litorgy-interpreters))
|
||||||
(eval
|
(eval
|
||||||
`(defun ,(intern (concat "litorgy-execute:" cmd)) (body params)
|
`(defun ,(intern (concat "litorgy-execute:" cmd)) (body params)
|
||||||
(concat "Evaluate a block of " ,cmd " script with litorgy.
|
,(concat "Evaluate a block of " cmd " script with litorgy. This function is
|
||||||
This function is called by `litorgy-execute-src-block'.")
|
called by `litorgy-execute-src-block'. This function is an
|
||||||
|
automatically generated wrapper for `litorgy-script-execute'.")
|
||||||
(litorgy-script-execute ,cmd body params))))
|
(litorgy-script-execute ,cmd body params))))
|
||||||
cmds))
|
cmds))
|
||||||
|
|
||||||
|
@ -51,12 +52,33 @@ executed through litorgy."
|
||||||
(defun litorgy-script-execute (cmd body params)
|
(defun litorgy-script-execute (cmd body params)
|
||||||
"Run CMD on BODY obeying any options set with PARAMS.
|
"Run CMD on BODY obeying any options set with PARAMS.
|
||||||
TODO: currently the params part is not implemented"
|
TODO: currently the params part is not implemented"
|
||||||
(message (format "executing source block with %s..." cmd))
|
(message (format "executing %s code block..." cmd))
|
||||||
(with-temp-buffer
|
(let ((vars (litorgy-reference-variables params)))
|
||||||
(insert body)
|
(save-window-excursion
|
||||||
(shell-command-on-region (point-min) (point-max) cmd nil 'replace)
|
(with-temp-buffer
|
||||||
(message "finished executing source block")
|
;; define any variables
|
||||||
(buffer-string)))
|
(mapcar
|
||||||
|
(lambda (pair)
|
||||||
|
(case (intern cmd)
|
||||||
|
((sh bash zsh) ;; TODO support table assignment in shell scripts
|
||||||
|
(error (format "table assignment is not supported for %s" cmd)))
|
||||||
|
((ruby python)
|
||||||
|
(insert (format "%s=%s\n"
|
||||||
|
(car pair)
|
||||||
|
(litorgy-table-to-ruby/python (cdr pair)))))
|
||||||
|
))
|
||||||
|
vars)
|
||||||
|
(insert body)
|
||||||
|
(shell-command-on-region (point-min) (point-max) cmd nil 'replace)
|
||||||
|
(message "finished executing source block")
|
||||||
|
(buffer-string)))))
|
||||||
|
|
||||||
|
(defun litorgy-table-to-ruby/python (table)
|
||||||
|
"Convert an elisp table (nested lists) into a string of ruby
|
||||||
|
source code specifying a table (nested arrays)."
|
||||||
|
(if (listp table)
|
||||||
|
(concat "[" (mapconcat #'litorgy-table-to-ruby/python table ", ") "]")
|
||||||
|
(format "%S" table)))
|
||||||
|
|
||||||
(provide 'litorgy-script)
|
(provide 'litorgy-script)
|
||||||
;;; litorgy-script.el ends here
|
;;; litorgy-script.el ends here
|
||||||
|
|
19
rorg.org
19
rorg.org
|
@ -751,6 +751,7 @@ out...
|
||||||
(apply #'mapcar* #'list table))
|
(apply #'mapcar* #'list table))
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
#+TBLNAME: sandbox
|
||||||
| 1 | 2 | 3 |
|
| 1 | 2 | 3 |
|
||||||
| 4 | schulte | 6 |
|
| 4 | schulte | 6 |
|
||||||
|
|
||||||
|
@ -758,6 +759,24 @@ out...
|
||||||
(transpose table)
|
(transpose table)
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
|
#+begin_src emacs-lisp :var table=sandbox :replace t
|
||||||
|
(transpose table)
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
#+begin_src ruby :var table=sandbox :replace t
|
||||||
|
puts table.first.join(" - ")
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
: 1 - 2 - 3
|
||||||
|
|
||||||
|
#+begin_src python :var table=sandbox :replace t
|
||||||
|
print table[0]
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
: [1, 2, 3]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
* COMMENT Commentary
|
* COMMENT Commentary
|
||||||
I'm seeing this as like commit notes, and a place for less formal
|
I'm seeing this as like commit notes, and a place for less formal
|
||||||
|
|
Loading…
Reference in a new issue