DONE ensure that table ranges work

This commit is contained in:
Eric Schulte 2009-05-24 10:35:13 -07:00
parent b8ecf9596b
commit f2c334b30d
2 changed files with 54 additions and 13 deletions

View File

@ -80,30 +80,33 @@ emacs-lisp representation of the value of the variable."
assignment is a literal value or is a reference to some external
resource. If REF is literal then return it's value, otherwise
return nil."
(let ((out (string-to-number ref)))
(if (or (not (equal out 0)) (string-match "^[ \f\t\n\r\v]*0\\.?0?[ \f\t\n\r\v]*$" ref))
out ;; number
(if (string-match "\"\\(.+\\)\"" ref) (read ref) ;; string
nil)))) ;; reference
(let ((out (litorgy-read ref)))
(if (equal out ref)
(if (string-match "\"\\(.+\\)\"" ref)
(read ref))
out)))
(defun litorgy-ref-resolve-reference (ref)
"Resolve the reference and return it's value"
(save-excursion
(let ((case-fold-search t)
type args new-ref result)
type args new-refere new-referent result)
;; assign any arguments to pass to source block
(when (string-match "\\(.+\\)\(\\(.*\\)\)" ref)
(save-match-data
(if (> (length (match-string 2)) 0)
(when (string-match "^\\(.+?\\)\(\\(.*\\)\)$" ref)
(setq new-refere (match-string 1 ref))
(setq new-referent (match-string 2 ref))
;; (message (format "first second %S -- %S" new-refere new-referent)) ;; debugging
(when (> (length new-refere) 0)
(if (> (length new-referent) 0)
(setq args (mapcar (lambda (ref) (cons :var ref))
(split-string (match-string 2 ref) ",[ \f\t\n\r\v]*")))))
(setq ref (match-string 1 ref)))
(split-string new-referent ",[ \f\t\n\r\v]*"))))
(setq ref new-refere)))
(when (string-match "\\(.+\\):\\(.+\\)" ref)
(find-file (match-string 1 ref))
(setf ref (match-string 2 ref)))
(goto-char (point-min))
(unless (let ((result_regexp (concat "^#\\+\\(TBL\\|RES\\)NAME:[ \t]*"
(regexp-quote ref) "[ \t]*$"))
(regexp-quote ref) "[ \t]*$"))
(regexp (concat "^#\\+SRCNAME:[ \t]*"
(regexp-quote ref) "[ \t]*$")))
(or (re-search-forward result_regexp nil t)

View File

@ -3,7 +3,7 @@
#+SEQ_TODO: TODO PROPOSED | DONE DEFERRED REJECTED
#+STARTUP: oddeven
* Tasks [19/27]
* Tasks [20/28]
** TODO resolve references to other buffers
This would allow source blocks to call upon tables, source-blocks,
@ -271,6 +271,44 @@ to the command if BUFF is not given.)
posterity. Same for a shell session either in a *shell* buffer, or
pasted from another terminal emulator. And python of course.
** DONE ensure that table ranges work
when a table range is passed to litorgy as an argument, it should be
interpreted as a vector.
| 1 | 2 | simple |
| 2 | 3 | Fixnum:1 |
| 3 | 4 | Array:123456 |
| 4 | 5 | |
| 5 | 6 | |
| 6 | 7 | |
#+TBLFM: @1$3='(sbe simple-sbe-example (n 4))::@2$3='(sbe task-table-range (n @1$1..@6$1))::@3$3='(sbe task-table-range (n (@1$1..@6$1)))
#+srcname: simple-sbe-example
#+begin_src emacs-lisp
"simple"
#+end_src
#+srcname: task-table-range
#+begin_src ruby :var n=simple-sbe-example
"#{n.class}:#{n}"
#+end_src
#+srcname: simple-results
#+begin_src emacs-lisp :var n=task-table-range(n=(1 2 3))
n
#+end_src
#+resname: simple-results
: Array:123
#+srcname: task-arr-referent
#+begin_src ruby :var ar=(1 2 3)
ar.size
#+end_src
#+resname: task-arr-referent
: 3
** DONE global variable indicating default to vector output
how about an alist... =litorgy-default-header-args= this may already
exist... just execute the following and all source blocks will default