emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Babel: a way to get the org-heading into source block
@ 2016-09-18 17:16 Benjamin Andresen
  0 siblings, 0 replies; only message in thread
From: Benjamin Andresen @ 2016-09-18 17:16 UTC (permalink / raw)
  To: Org Mode List

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-09-18 17:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-18 17:16 Babel: a way to get the org-heading into source block Benjamin Andresen

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).