* Table (used a "spreadsheet") org-sbe issues when the value is a string
@ 2016-06-22 12:37 Frederick Giasson
2016-06-22 23:06 ` Nicolas Goaziou
0 siblings, 1 reply; 7+ messages in thread
From: Frederick Giasson @ 2016-06-22 12:37 UTC (permalink / raw)
To: emacs-orgmode
Hi Everybody,
I am experiencing a few issues trying to update a cell value using
=org-sbe= when the value of a column is a string.
Here is an example that works when the value is a number:
====================
#+NAME: average-dataset-size
#+BEGIN_SRC clojure :var f="turtle" :exports none :results value
(identity f)
#+END_SRC
#+RESULTS: average-dataset-size
: turtle
| Format | Sizes distribution in MB | Average size in MB |
|--------+--------------------------+--------------------|
| 7 | | 7 |
#+TBLFM: $3='(org-sbe "average-dataset-size" (f $1))
====================
Now, if I put a string in the format column, I al getting the following:
====================
#+NAME: average-dataset-size
#+BEGIN_SRC clojure :var f="turtle" :exports none :results value
(identity f)
#+END_SRC
#+RESULTS: average-dataset-size
: turtle
| Format | Sizes distribution in MB | Average size in MB |
|--------+--------------------------+--------------------|
| turtle | | #ERROR |
#+TBLFM: $3='(org-sbe "average-dataset-size" (f $1))
====================
The debugging session I have is (which doesn't tell me with Result: is
#ERROR):
====================
Substitution history of formula
Orig: ?
$xyz-> '(org-sbe "average-dataset-size" (f $1))
@r$c-> '(org-sbe "average-dataset-size" (f $1))
$1-> '(org-sbe "average-dataset-size" (f "turtle"))
Result: #ERROR
Format: NONE
Final: #ERROR
====================
Note #1: (identity) is a function in Clojure that returns the same value
that is in input.
I am wondering if this is a bug, or something that I am missing in how
to use these features?
Thanks for helping,
Fred
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Table (used a "spreadsheet") org-sbe issues when the value is a string
2016-06-22 12:37 Table (used a "spreadsheet") org-sbe issues when the value is a string Frederick Giasson
@ 2016-06-22 23:06 ` Nicolas Goaziou
2017-09-06 15:32 ` Alex Bennée
0 siblings, 1 reply; 7+ messages in thread
From: Nicolas Goaziou @ 2016-06-22 23:06 UTC (permalink / raw)
To: Frederick Giasson; +Cc: emacs-orgmode
Hello,
Frederick Giasson <fred@fgiasson.com> writes:
> Now, if I put a string in the format column, I al getting the following:
>
> ====================
>
> #+NAME: average-dataset-size
> #+BEGIN_SRC clojure :var f="turtle" :exports none :results value
> (identity f) #+END_SRC
>
> #+RESULTS: average-dataset-size
> : turtle
>
>
> | Format | Sizes distribution in MB | Average size in MB |
> |--------+--------------------------+--------------------|
> | turtle | | #ERROR |
> #+TBLFM: $3='(org-sbe "average-dataset-size" (f $1))
>
> ====================
According to `org-sbe' docstring, it should be
#+TBLFM: $3='(org-sbe "average-dataset-size" (f $$1))
Documentation could be drastically improved in that area, the manual is
not even talking about `org-sbe'.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Table (used a "spreadsheet") org-sbe issues when the value is a string
2016-06-22 23:06 ` Nicolas Goaziou
@ 2017-09-06 15:32 ` Alex Bennée
2017-09-06 16:14 ` Nicolas Goaziou
0 siblings, 1 reply; 7+ messages in thread
From: Alex Bennée @ 2017-09-06 15:32 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: emacs-orgmode, Frederick Giasson
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
> Hello,
>
> Frederick Giasson <fred@fgiasson.com> writes:
>
>> Now, if I put a string in the format column, I al getting the following:
>>
>> ====================
>>
>> #+NAME: average-dataset-size
>> #+BEGIN_SRC clojure :var f="turtle" :exports none :results value
>> (identity f) #+END_SRC
>>
>> #+RESULTS: average-dataset-size
>> : turtle
>>
>>
>> | Format | Sizes distribution in MB | Average size in MB |
>> |--------+--------------------------+--------------------|
>> | turtle | | #ERROR |
>> #+TBLFM: $3='(org-sbe "average-dataset-size" (f $1))
>>
>> ====================
>
> According to `org-sbe' docstring, it should be
>
> #+TBLFM: $3='(org-sbe "average-dataset-size" (f $$1))
>
> Documentation could be drastically improved in that area, the manual is
> not even talking about `org-sbe'.
Even this doesn't seem to work. In my case:
#+name: scramble-string
#+begin_src emacs-lisp :var str="abcde"
(apply #'string
(reverse
(string-to-list str)))
#+end_src
#+RESULTS: scramble-string
: edcba
So far so good
#+call: scramble-string(str="whatever-foo")
#+RESULTS:
: oof-revetahw
So calling scramble-string works as expected...
#+tblname: reversed-strings
| abcde | #ERROR |
| flibble | #ERROR |
| dibble | #ERROR |
| xyzzy | #ERROR |
| another | #ERROR |
#+TBLFM: $2='(org-sbe scramble-string (str $$1))
Hmm no dice... the debugger lists:
Substitution history of formula
Orig: '(org-sbe scramble-string (str $$1))
$xyz-> '(org-sbe scramble-string (str $$1))
@r$c-> '(org-sbe scramble-string (str $$1))
$1-> '(org-sbe scramble-string (str $"abcde"))
Result: #ERROR
Format: NONE
Final: #ERROR
Even calling org-sbe directly from a source block:
#+name: call-scramble-string-via-sbe
#+begin_src emacs-lisp :var val="thing"
(org-sbe scramble-string (str val))
#+end_src
So is this just broken untested functionality or are there any working
examples from which we could reverse engineer the proper docstring?
--
Alex Bennée
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Table (used a "spreadsheet") org-sbe issues when the value is a string
2017-09-06 15:32 ` Alex Bennée
@ 2017-09-06 16:14 ` Nicolas Goaziou
2017-09-06 21:46 ` Alex Bennée
0 siblings, 1 reply; 7+ messages in thread
From: Nicolas Goaziou @ 2017-09-06 16:14 UTC (permalink / raw)
To: Alex Bennée; +Cc: emacs-orgmode, Frederick Giasson
Hello,
Alex Bennée <alex.bennee@linaro.org> writes:
> So calling scramble-string works as expected...
>
> #+tblname: reversed-strings
> | abcde | #ERROR |
>
> | flibble | #ERROR |
> | dibble | #ERROR |
> | xyzzy | #ERROR |
> | another | #ERROR |
>
> #+TBLFM: $2='(org-sbe scramble-string (str $$1))
I cannot reproduce it. I get:
#+name: reversed-strings
| abcde | edcba |
| flibble | elbbilf |
| dibble | elbbid |
| xyzzy | yzzyx |
| another | rehtona |
#+TBLFM: $2='(org-sbe scramble-string (str $$1))
> Even calling org-sbe directly from a source block:
>
> #+name: call-scramble-string-via-sbe
> #+begin_src emacs-lisp :var val="thing"
>
> (org-sbe scramble-string (str val))
> #+end_src
AFAIK, `org-sbe' is limited to tables.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Table (used a "spreadsheet") org-sbe issues when the value is a string
2017-09-06 16:14 ` Nicolas Goaziou
@ 2017-09-06 21:46 ` Alex Bennée
2017-09-07 15:21 ` Alex Bennée
0 siblings, 1 reply; 7+ messages in thread
From: Alex Bennée @ 2017-09-06 21:46 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: emacs-orgmode, Frederick Giasson
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
> Hello,
>
> Alex Bennée <alex.bennee@linaro.org> writes:
>
>> So calling scramble-string works as expected...
>>
>> #+tblname: reversed-strings
>> | abcde | #ERROR |
>>
>> | flibble | #ERROR |
>> | dibble | #ERROR |
>> | xyzzy | #ERROR |
>> | another | #ERROR |
>>
>> #+TBLFM: $2='(org-sbe scramble-string (str $$1))
>
> I cannot reproduce it. I get:
Hmm it turns out this interferes:
;; See http://emacs.stackexchange.com/questions/499/finding-and-executing-org-babel-snippets-programatically
(defun my-babel-hashed-confirm (lang body)
"Check against known hashes before prompting for confirmation.
See `org-confirm-babel-evaluate'."
(let ((check (list lang (md5 body))))
;; If not hashed, prompt
(if (not (member check my-org-babel-hashes))
;; Ask if you want to hash
(if (yes-or-no-p "Store hash for block? ")
;; Hash is added, proceed with evaluation
(progn
(add-to-list 'my-org-babel-hashes check)
'nil)
;; Return 't to prompt for evaluation
't)
(message "Valid hash auto-confirmed")
'nil)))
(setq org-confirm-babel-evaluate 'my-babel-hashed-confirm)
Resetting to org-confirm-babel-evaluate to nil and it works.
>
> #+name: reversed-strings
> | abcde | edcba |
> | flibble | elbbilf |
> | dibble | elbbid |
> | xyzzy | yzzyx |
> | another | rehtona |
> #+TBLFM: $2='(org-sbe scramble-string (str $$1))
>
>> Even calling org-sbe directly from a source block:
>>
>> #+name: call-scramble-string-via-sbe
>> #+begin_src emacs-lisp :var val="thing"
>>
>> (org-sbe scramble-string (str val))
>> #+end_src
>
> AFAIK, `org-sbe' is limited to tables.
I was trying to replicate the way TBLFM compiles the macro.
>
> Regards,
--
Alex Bennée
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Table (used a "spreadsheet") org-sbe issues when the value is a string
2017-09-06 21:46 ` Alex Bennée
@ 2017-09-07 15:21 ` Alex Bennée
2017-09-07 16:04 ` Nicolas Goaziou
0 siblings, 1 reply; 7+ messages in thread
From: Alex Bennée @ 2017-09-07 15:21 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: emacs-orgmode, Frederick Giasson
Alex Bennée <alex.bennee@linaro.org> writes:
> Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
>
>> Hello,
>>
>> Alex Bennée <alex.bennee@linaro.org> writes:
>>
>>> So calling scramble-string works as expected...
>>>
>>> #+tblname: reversed-strings
>>> | abcde | #ERROR |
>>>
>>> | flibble | #ERROR |
>>> | dibble | #ERROR |
>>> | xyzzy | #ERROR |
>>> | another | #ERROR |
>>>
>>> #+TBLFM: $2='(org-sbe scramble-string (str $$1))
>>
>> I cannot reproduce it. I get:
>
> Hmm it turns out this interferes:
>
> ;; See http://emacs.stackexchange.com/questions/499/finding-and-executing-org-babel-snippets-programatically
> (defun my-babel-hashed-confirm (lang body)
<snip>
>
> (setq org-confirm-babel-evaluate 'my-babel-hashed-confirm)
>
> Resetting to org-confirm-babel-evaluate to nil and it works.
So more correctly when org-confirm-babel-evaluate is set it breaks due
to info not containing a character position for the TBLFM code. I fixed
this by patching org-babel-check-confirm-evaluate:
modified lisp/ob-core.el
@@ -242,7 +242,8 @@ should be asked whether to allow evaluation."
(and export (equal eval "query-export"))
(if (functionp org-confirm-babel-evaluate)
(save-excursion
- (goto-char (nth 5 info))
+ (when (nth 5 info)
+ (goto-char (nth 5 info)))
(funcall org-confirm-babel-evaluate
;; language, code block body
(nth 0 info) (nth 1 info)))
I'm not sure the goto-char is legitimate anyway as the documentation for
org-confirm-babel-evaluate says nothing about point being set while it
executes.
--
Alex Bennée
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Table (used a "spreadsheet") org-sbe issues when the value is a string
2017-09-07 15:21 ` Alex Bennée
@ 2017-09-07 16:04 ` Nicolas Goaziou
0 siblings, 0 replies; 7+ messages in thread
From: Nicolas Goaziou @ 2017-09-07 16:04 UTC (permalink / raw)
To: Alex Bennée; +Cc: emacs-orgmode, Frederick Giasson
Alex Bennée <alex.bennee@linaro.org> writes:
> So more correctly when org-confirm-babel-evaluate is set it breaks due
> to info not containing a character position for the TBLFM code. I fixed
> this by patching org-babel-check-confirm-evaluate:
>
> modified lisp/ob-core.el
> @@ -242,7 +242,8 @@ should be asked whether to allow evaluation."
> (and export (equal eval "query-export"))
> (if (functionp org-confirm-babel-evaluate)
> (save-excursion
> - (goto-char (nth 5 info))
> + (when (nth 5 info)
> + (goto-char (nth 5 info)))
> (funcall org-confirm-babel-evaluate
> ;; language, code block body
> (nth 0 info) (nth 1 info)))
>
> I'm not sure the goto-char is legitimate anyway as the documentation for
> org-confirm-babel-evaluate says nothing about point being set while it
> executes.
I agree and removed `goto-char'. Thank you for the analysis and the
patch.
Regards,
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2017-09-07 16:04 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-22 12:37 Table (used a "spreadsheet") org-sbe issues when the value is a string Frederick Giasson
2016-06-22 23:06 ` Nicolas Goaziou
2017-09-06 15:32 ` Alex Bennée
2017-09-06 16:14 ` Nicolas Goaziou
2017-09-06 21:46 ` Alex Bennée
2017-09-07 15:21 ` Alex Bennée
2017-09-07 16:04 ` Nicolas Goaziou
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).