emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Orgmode] Re: [babel] ledger tutorial on Worg


From: Sébastien Vauban
Subject: [Orgmode] Re: [babel] ledger tutorial on Worg
Date: Wed, 08 Sep 2010 10:21:56 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

Hi Eric,

"Eric Schulte" wrote:
> Sébastien Vauban <address@hidden> writes:
>> "Eric Schulte" wrote:
>>> Sébastien Vauban <address@hidden> writes:
>>>>
>>>> 1. I find it weird to have all the parameters of =:cmdline= not enclosed
>>>>    between quotes. What should be the best option, here? That was a
>>>>    subject, long ago, on Org-Babel: to quote or not to quote...
>>>
>>> I don't know that this was ever explicitly discussed, I believe that the
>>> no-quoting behavior may have simply fallen out of the initial
>>> implementation. I'd certainly like to hear other people's opinions on
>>> this, but I've personally enjoyed not having to place quotes in every
>>> instance.
>>
>> In december 2009, I wrote:
>>
>>     "I'm a bit confused (as you may have seen in my last posts) about when we
>>     do have to quote strings and when we do have to avoid doing it. Would you
>>     have a one-liner explanation about when we have to use quotes?"
>>
>> See http://www.mail-archive.com/address@hidden/msg20265.html for
>> contextual information.
>>
>> I remembered "you" (Dan or you) answered it somehow, but it must have been
>> (around that same period) in another thread. Though, I don't find pointers
>> anymore...
>>
>> Question is more: is it clear to mix parameters names (such as =:cmdline=) 
>> and
>> long values which are unquoted (such as =registry unknown credit-card= and
>> many much more options)?
>>
>> Shouldn't we properly begin and end where the given value is?
>
> Through extensive person use I've not run into any instances where the lack
> of quotes has actually caused a problem, or where there has been a valid
> combination of header arguments which could not be successfully parsed.
> Without such an example I don't find it motivating to require quotes.

I have no objection against this, as I have no definite view on what's better.
Adding quotes would mean begin able to escape them in case the options need
quotes, etc. etc. So, maybe it is better the way it currently is.

The fact simply is sometimes we must add quotes, sometimes not, and that's not
always intuitive (to me). Not only considering Org-Babel, but Org as a whole.
See this example of `columnview':

--8<---------------cut here---------------start------------->8---
#+BEGIN: columnview :hlines 1 :id "label"
#+END:
--8<---------------cut here---------------end--------------->8---

or of `org-collector':

--8<---------------cut here---------------start------------->8---
#+BEGIN: propview :id "december" :conds ((string= spendtype "food")) :cols 
(ITEM amount)
#+END:
--8<---------------cut here---------------end--------------->8---


>>>> 2. When the evaluation produces no output, but had well produced output
>>>>    before, shouldn't Babel have to delete the previously written results in
>>>>    the Org buffer?
>>>
>>> This is a good point. Currently Babel just quits if it receives a nil
>>> result, but I think you're right that we should replace existing results
>>> when a nil result has been returned. I'll add this as PROPOSED to the babel
>>> task list.
>>
>> I consider this kind of mandatory, for the sake of coherency, and to really
>> make use of Org-babel every time I want to run some shell commands (and 
>> change
>> them, eventually getting no results then).
>>
>
> I've just pushed up a change that implements this behavior.

I've just git pulled, and tested your change.

>From my point of view, it does not work yet. Take this example:

--8<---------------cut here---------------start------------->8---
* Journal data

#+srcname: ledger-journal
#+begin_src ledger
2008/01/03 * (SCORPIOS ) SEB VAUBAN
        Assets:Bank:Checking:799997400530                               550.00 
EUR
        Assets:Bank:Transferred

2008/01/01 * ( ) UNKNOWN-PAYEE
        Assets:Bank:Checking:799997400530                                21.91 
EUR
        Expenses:Unknown
#+end_src

* Registry

Give me the details...

#+srcname: ledger-registry
#+begin_src ledger :cmdline reg unknown :noweb yes :session
<<ledger-journal>>
#+end_src

#+results: ledger-registry
:           -21.91 EUR  Expenses:Unknown
--8<---------------cut here---------------end--------------->8---

With `:cmdline reg unknown', it produced the line with -21.91 EUR. Correct.

Now, if I write `:cmdline "reg" unknown', I expect no output from Ledger, and
thus the results block to be removed. That's not the case.

Other peculiarity, if I write `:cmdline reeg unknown', I get an exception:

--8<---------------cut here---------------start------------->8---
Debugger entered--Lisp error: (args-out-of-range "" -1 0)
  substring("" -1)
  (string-equal (substring result -1) "\n")
  (or (string-equal (substring result -1) "\n") (string-equal (substring result 
-1) "
"))
  (not (or (string-equal ... "\n") (string-equal ... "
")))
  (and (stringp result) (not (or ... ...)))
  (if (and (stringp result) (not ...)) (progn (setq result ...)))
  (when (and (stringp result) (not ...)) (setq result (concat result "\n")))
  (if (and result-params (member "silent" result-params)) (progn (message ...) 
result) (when (and ... ...) (setq result ...)) (save-excursion (let ... ... ... 
... ... ...)) (if (= ... 0) (if ... ... ...) (message "finished")))
  org-babel-insert-result("" ("output" "replace") ("ledger" "2008/01/03 * 
(SCORPIOS ) SEB VAUBAN\n        Assets:Bank:Checking:799997400530               
                550.00 EUR\n        Assets:Bank:Transferred\n\n2008/01/01 * ( ) 
UNKNOWN-PAYEE\n        Assets:Bank:Checking:799997400530                        
        21.91 EUR\n        Expenses:Unknown\n" ((:cache . "no") (:cmdline . 
"reeg unknown") (:comments . "") (:exports . "code") (:hlines . "no") (:noweb . 
"yes") (:results . "output replace") (:session) (:shebang . "") (:tangle . 
"no")) "" "ledger-registry" 0) nil 0 "ledger")
  (if (and (not arg) new-hash (equal new-hash old-hash)) (save-excursion 
(goto-char ...) (end-of-line 1) (forward-char 1) (setq result ...) (message 
...) result) (message "executing %s code block%s..." (capitalize lang) (if ... 
... "")) (setq result (funcall cmd body params)) (if (eq result-type ...) (setq 
result ...)) (org-babel-insert-result result result-params info new-hash indent 
lang) (run-hooks (quote org-babel-after-execute-hook)) result)
  (progn (fset (quote call-process-region) (function* ...)) (unless (fboundp 
cmd) (error "No org-babel-execute function for %s!" lang)) (if (and ... 
new-hash ...) (save-excursion ... ... ... ... ... result) (message "executing 
%s code block%s..." ... ...) (setq result ...) (if ... ...) 
(org-babel-insert-result result result-params info new-hash indent lang) 
(run-hooks ...) result))
  (unwind-protect (progn (fset ... ...) (unless ... ...) (if ... ... ... ... 
... ... ... result)) (if --cl-letf-bound-- (fset ... --cl-letf-save--) 
(fmakunbound ...)))
  (let* ((--cl-letf-bound-- ...) (--cl-letf-save-- ...)) (unwind-protect (progn 
... ... ...) (if --cl-letf-bound-- ... ...)))
  (letf ((... ...)) (unless (fboundp cmd) (error "No org-babel-execute function 
for %s!" lang)) (if (and ... new-hash ...) (save-excursion ... ... ... ... ... 
result) (message "executing %s code block%s..." ... ...) (setq result ...) (if 
... ...) (org-babel-insert-result result result-params info new-hash indent 
lang) (run-hooks ...) result))
  (letf* ((... ...)) (unless (fboundp cmd) (error "No org-babel-execute 
function for %s!" lang)) (if (and ... new-hash ...) (save-excursion ... ... ... 
... ... result) (message "executing %s code block%s..." ... ...) (setq result 
...) (if ... ...) (org-babel-insert-result result result-params info new-hash 
indent lang) (run-hooks ...) result))
  (flet ((call-process-region ... ...)) (unless (fboundp cmd) (error "No 
org-babel-execute function for %s!" lang)) (if (and ... new-hash ...) 
(save-excursion ... ... ... ... ... result) (message "executing %s code 
block%s..." ... ...) (setq result ...) (if ... ...) (org-babel-insert-result 
result result-params info new-hash indent lang) (run-hooks ...) result))
  (unwind-protect (flet (...) (unless ... ...) (if ... ... ... ... ... ... ... 
result)) (setq call-process-region (quote 
org-babel-call-process-region-original)))
  (let* ((lang ...) (params ...) (new-hash ...) (old-hash ...) (body ...) 
(result-params ...) (result-type ...) (cmd ...) (dir ...) (default-directory 
...) (org-babel-call-process-region-original ...) (indent ...) result) 
(unwind-protect (flet ... ... ...) (setq call-process-region ...)))
  (progn (let* (... ... ... ... ... ... ... ... ... ... ... ... result) 
(unwind-protect ... ...)))
  (if (org-babel-confirm-evaluate info) (progn (let* ... ...)))
  (when (org-babel-confirm-evaluate info) (let* (... ... ... ... ... ... ... 
... ... ... ... ... result) (unwind-protect ... ...)))
  (let ((info ...)) (when (org-babel-confirm-evaluate info) (let* ... ...)))
  org-babel-execute-src-block(nil ("ledger" "2008/01/03 * (SCORPIOS ) SEB 
VAUBAN\n        Assets:Bank:Checking:799997400530                               
550.00 EUR\n        Assets:Bank:Transferred\n\n2008/01/01 * ( ) UNKNOWN-PAYEE\n 
       Assets:Bank:Checking:799997400530                                21.91 
EUR\n        Expenses:Unknown\n" ((:cache . "no") (:cmdline . "reeg unknown") 
(:comments . "") (:exports . "code") (:hlines . "no") (:noweb . "yes") 
(:results . "output replace") (:session) (:shebang . "") (:tangle . "no")) "" 
"ledger-registry" 0))
  (progn (org-babel-execute-src-block current-prefix-arg info) t)
  (if info (progn (org-babel-execute-src-block current-prefix-arg info) t) nil)
  (let ((info ...)) (if info (progn ... t) nil))
  org-babel-execute-src-block-maybe()
  (or (org-babel-execute-src-block-maybe) (org-babel-lob-execute-maybe))
  org-babel-execute-maybe()
  call-interactively(org-babel-execute-maybe nil nil)
--8<---------------cut here---------------end--------------->8---


>> Thanks a lot for everything you did and do for us.
>
> My pleasure -- Eric

Still applicable... ;-)

Best regards,
  Seb

-- 
Sébastien Vauban




reply via email to

[Prev in Thread] Current Thread [Next in Thread]