Beancount + Yasnippet + Org capture template

262 views
Skip to first unread message

man...@gmail.com

unread,
Jul 6, 2017, 4:29:14 PM7/6/17
to Beancount
Hi,

I'm trying to simplify entering information, and am looking into yasnippets and Org capture templates. I would like to combine the two, but don't think that I can use beancount-insert-account from within a snippet buffer, because that is not the beancount buffer. Currently, I have a capture template that places the cursor in a weekdatetree ready to expand a yasnippet like this:

Or capture template:

   ("f" "Finace" plain (file+weektree "~/Documents/Org/beancount.org")
    "bc_" :jump-to-captured t)

Should place me in the beancount.org file at the bottom with "bc_"<--cursor here, where "bc_" is a snippet.

I then press TAB and the snippet expands. I'm having some trouble with this part, and perhaps this question is better asked to yasnippet gurus, but I thought I would try here first to see if others have efficient workflows other than what I am trying to do. The snippet is:

# -*- mode: snippet; require-final-newline: nil -*-
# name: beancount
# key: bc_
# expand-env: ((yas-indent-line 'fixed) (yas-wrap-around-region 'nil))
# binding: direct-keybinding
# --
`(format-time-string "%Y-%m-%d")` * "$1"
  ${2:$$(call-interactively 'beancount-insert-account)}    $3 USD
  ${4:$$(call-interactively 'beancount-insert-account)}   -$3 USD


The problem is that beancount-insert-account does not seem to be behaving properly. It prompts me for an account ~4 times for each call, and if I just hit enter, instead of selecting the first account (Assets:Cash:CHF), produces an entry that looks like this:

** 2017-W27
*** 2017-07-06 Thursday
2017-07-06 * "test entry"
  Assets:Cash:CHF:Cash:CHFAssets:Cash:CHF:Cash:CHF:Cash:CHF:Cash:CHF    42 USD
  <cursor here again misbehaving>   -42 USD

Questions:
+ How do I get beancount-insert-account to behave properly in this context. It seems to be a yasnippet issue because C-c ' works fine normally.
+ Does anyone have any advice how to improve efficiency here? Combine the capture + yasnippet? Have Yasnippet know when to prompt for >2 accounts?
+ I imagine capturing tasks into the datetree and refiling them to the correct Org subtree hierarchy as separate tasks, but it could be automated. I think this step needs to be done in the Org capture step, when refiling is efficient.
+ Any other thoughts on this workflow?

Thanks for considering this. Neat software. This is just my second day using it, but it seems like a good tool.

   -k.

man...@gmail.com

unread,
Jul 9, 2017, 9:13:55 AM7/9/17
to Beancount, man...@gmail.com
With help from the yasnippet community, I've figured out a good yasnippet for inserting transactions. Place this in ~/.emacs.d/snippets/org-mode/bc and trigger on bc_ when yasnippet is loaded.

# -*- mode: snippet; require-final-newline: nil -*-
# name: beancount
# key: bc_
# expand-env: ((yas-indent-line 'fixed) (yas-wrap-around-region 'nil))
# type: snippet
# binding: direct-keybinding
# --
`(format-time-string "%Y-%m-%d")` * "${1:Description}"
  ${2:Account$$(yas-choose-value beancount-accounts)}    ${3:AMT} ${4:CUR$(yas-choose-value '("USD" "DKK"))}
  ${5:Account$$(yas-choose-value beancount-accounts)}   -$3 $4

bc_$0
Reply all
Reply to author
Forward
0 new messages