emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Benjamin Andresen <benny@in-ulm.de>
To: Org Mode List <emacs-orgmode@gnu.org>
Subject: Babel: a way to get the org-heading into source block
Date: Sun, 18 Sep 2016 19:16:58 +0200	[thread overview]
Message-ID: <87k2e9yvt1.fsf@in-ulm.de> (raw)

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	other threads:[~2016-09-18 17:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87k2e9yvt1.fsf@in-ulm.de \
    --to=benny@in-ulm.de \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).