On 2021-04-29 19:04, Jonathan Goldman wrote:

Yes I want to create a modification to Emacs Lisp code to specify a
specific file to load. In my case I have one file called
"journal.beancount" that loads "accounts.beancount" and then all the
transactions which are organized by real-world accounts. So ideally
all I need to do is load "accounts.beancount" and then when I'm
editing any specific transactions file I have access to type-ahead
for any of the accounts found in accounts.beancount.

I'm not yet comfortable with Emacs Lisp. I'll try to figure it out
but if anyone knows how to do this modification easily that would
save me a lot of time and perhaps be generally useful as I think
there are others who split up their beancount data among multiple
files.

There are likely many different ways to do this (some advice around
one of the beancount functions, patching in a simple variable to tell
beancount where to look for accounts, etc.) but what I did (some time
ago) was just to leverage some of the existing beancount.el code to
collect a list of accounts, and then do a very simple completing-read
interface with the accounts list as candidates, in order to insert
account name at point.

Upsides of doing it this way is that it works in every buffer.  Comes
in handy some times.

Note that ostrta- is just my namespace prefix for this package, you
can change that to my- or whatever you like.  In fact you can change
the names of the functions to something else that suits you, if you
prefer.  Just make sure that you change all of them the same (as one
function references the other one).

#+begin_src emacs-lisp

  ;; Define variables

  (defvar ostrta-beancount-account-list nil
    "List of all accounts in `ostrta-beancount-file'.

  Refresh list with function
  `ostrta-beancount-account-list-refresh'.")


  (defvar ostrta-beancount-file nil
    "Full path to beancount file.")


  ;; Define functions

  (defun ostrta-beancount-account-insert-at-point ()
    "Just like it sounds."
    (interactive)
    (when (null ostrta-beancount-account-list)
      (ostrta-beancount-account-list-refresh))
    (let ((account (completing-read
                    "Account: "
                    ostrta-beancount-account-list)))
      (insert account)))


  (defun ostrta-beancount-account-list-refresh ()
    "Update `ostrta-beancount-account-list'.

  Collect a (unique, sorted) list of account names from
  `ostrta-beancount-file'."
    (interactive)
    (require 'beancount)
    (find-file-noselect ostrta-beancount-file)
    (save-current-buffer
      (set-buffer (file-name-nondirectory ostrta-beancount-file))
      (setq ostrta-beancount-account-list
            (sort (beancount-collect beancount-account-regexp 0)
                  #'string<))))


  ;; Set variable

  (setq ostrta-beancount-file "/path/to/your/file.beancount")

#+end_src

Just put that in your init file.  Restart Emacs and you should be off
to the races.  Oh yes, you can invoke the command by doing M-x then
start typing name of command (e.g., "beancount account insert").  But
you might want to bind it to some key.  Let me know if you need some
help with that.

If you want to poke around and start learning Elisp, C-h f and C-h v
are your friends.  With point on a function or variable name
(respectively) invoke those commands to see what does what.  I use
them constantly.

Let us know how you are getting on, or if you need some more help.
Good luck.

Cheers,
TRS-80

--
You received this message because you are subscribed to the Google Groups 
"Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to beancount+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beancount/c79cf7f743225d0e466b21276d1bb5ce%40isnotmyreal.name.

Reply via email to