emacs-orgmode
[Top][All Lists]
Advanced

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

[O] Babel: a way to get the org-heading into source block


From: Benjamin Andresen
Subject: [O] Babel: a way to get the org-heading into source block
Date: Sun, 18 Sep 2016 19:16:58 +0200

Hello,

small intro in case there is a better way than I thought up: I've just
started using Ledger and wanted to use Babel to tangle the ledger file.

Every entry is its own heading:

* <2016-07-01 Fri> * Hollywood | Monthly rent
#+begin_src ledger :tangle yes
07-01 * Hollywood | Monthly rent
    Expenses:Rent                             500.00 USD
    Expenses:Rent:Parking spot                 50.00 USD
    Assets:BOA:Checking
#+end_src

I've written a function to basically do what I want:
(defun org-header-to-ledger (&optional point)
  (save-excursion
    (re-search-backward org-ts-regexp)
    (let* ((context (org-element-context))
           (year (org-element-property :year-start context))
           (month (org-element-property :month-start context))
           (day (org-element-property :day-start context))
           (title (cadr (split-string (org-element-property
                                       :title (org-element-property
                                               :parent context))
                                      (rx (or "]" ">"))))))
      (format "%04d-%02d-%02d%s" year month day title))))
;; (There are known bugs but for illustraton purposes this is suitable)

Now in babel I would basically want to not have repeated data, so my
entry should look like this:

* <2016-07-01 Fri> * Hollywood | Monthly rent
#+begin_src ledger :tangle yes
<<elisp:org-header-to-ledger>>
    Expenses:Rent                             500.00 USD
    Expenses:Rent:Parking spot                 50.00 USD
    Assets:BOA:Checking
#+end_src

The actual syntax is not that important, but something to that effect so
I only have to keep one headline up to date is what I'm looking for.

Is there a way to accomplish this right now? If there isn't, can you
point me to where I would add such functionality? AFAIK named src block
can already be inserted, I just don't know where in the source that is
found.

Thanks in advance and best regards,
Benny



reply via email to

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