From mboxrd@z Thu Jan 1 00:00:00 1970 From: Viktor Rosenfeld Subject: Re: Functions in SBE blocks Date: Sun, 8 Jul 2012 02:55:30 +0200 Message-ID: <20120708005530.GA59773@kenny.fritz.box> References: <20120707185831.GA25982@client195-161.wlan.hu-berlin.de> <1372.1341691369@alphaville> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from eggs.gnu.org ([208.118.235.92]:44345) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Snfml-0002Le-DM for emacs-orgmode@gnu.org; Sat, 07 Jul 2012 20:55:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Snfmj-0000TZ-FH for emacs-orgmode@gnu.org; Sat, 07 Jul 2012 20:55:38 -0400 Received: from mail-bk0-f41.google.com ([209.85.214.41]:40971) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Snfmj-0000SI-5K for emacs-orgmode@gnu.org; Sat, 07 Jul 2012 20:55:37 -0400 Received: by bkcjc3 with SMTP id jc3so6748123bkc.0 for ; Sat, 07 Jul 2012 17:55:34 -0700 (PDT) Content-Disposition: inline In-Reply-To: <1372.1341691369@alphaville> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Hi Nick, Nick Dokos wrote: > Viktor Rosenfeld 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 Thanks, that does the trick. The double ESC evaluation is helpful, too. Cheers, Viktor