Viktor Rosenfeld <listuse...@googlemail.com> wrote: > Hi, > > I can't get SBE blocks called from a table to work, if they use > functions like org-parse-time-string. > > Suppose I have the following table: > > | Start | Ende | | > |------------------+------------------+-| > | [2011-06-29 Wed] | [2012-02-29 Wed] | | > #+TBLFM: $3='(sbe "billable-month" (start $1) (end $2)) > > and the following source block: > > #+NAME: billable-month(start="[2011-06-29 Wed]", end="[2012-02-29 Wed]") > #+BEGIN_SRC emacs-lisp > (let* ((start-date start)) > (message "%s" start-date)) > #+END_SRC > > If I evaluate the table, the start date is put into the last column. > However, if I change the code to the following: > > #+NAME: billable-month(start="[2011-06-29 Wed]", end="[2012-02-29 Wed]") > #+BEGIN_SRC emacs-lisp > (let* ((start-date (org-parse-time-string start))) > (message "%s" (nth 4 start-date))) > #+END_SRC > > then the string #ERROR is inserted into the table. Evaluating the source > block directly yields the correct result. > > What's going on here? >
Finicky type matching: if you evaluate the second code block in the buffer with ESC ESC : (sbe "billable-month" (start "[2011-06-29 Wed]") (end "[2012-02-29 Wed]")) RET you get a backtrace similar to this: ,---- | Debugger entered--Lisp error: (wrong-type-argument stringp [2011-06-29 Wed]) | string-match("\\(\\([0-9]\\{4\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\)\\( +[^]+0-9> \n -]+\\)?\\( +\\([0-9]\\{1,2\\}\\):\\([0-9]\\{2\\}\\)\\)?\\)" [2011-06-29 Wed]) | (if (string-match org-ts-regexp0 s) (list 0 (if (or (match-beginning 8) (not nodefault)) (string-to-number (or (match-string 8 s) "0"))) (if (or (match-beginning 7) (not nodefault)) (string-to-number (or (match-string 7 s) "0"))) (string-to-number (match-string 4 s)) (string-to-number (match-string 3 s)) (string-to-number (match-string 2 s)) nil nil nil) (error "Not a standard Org-mode time string: %s" s)) | org-parse-time-string([2011-06-29 Wed]) | (let* ((start-date (org-parse-time-string start))) (format "%d" (nth 4 start-date))) | ... `---- Somewhere, the string becomes not a string. Try modifying the block to this: #+BEGIN_SRC emacs-lisp (let* ((start-date (org-parse-time-string (format "%s" start)))) (message "%s" (nth 4 start-date))) #+END_SRC Nick