Sort your Ledger journal with Emacs
               ===================================

  Last edited: $Date: 2022/01/02 21:17:01 $

                 Ledger for plain text accounting
                 --------------------------------

  Ledger  (https://www.ledger-cli.org/)   is   an   open  source
  powerful, double-entry accounting system that you access  from
  the command line.

  It   is   the original   form    of   plain    text  accounting
  (https://plaintextaccounting.org/).

  The advantages of plain text accounting are:

  - plain text format, so you can use your favorite editor
  - makes it easy to create scripts to minimize the amount of work
  - excellent for usage with a version control system
  - completely transparent to the user, no "black box" doing
    incomprehensible things
  - light weight application
  - open source, so no vendor lock in
  - works fine on BSD and Linux

  See       also       the       [Wikipedia       page        on
  Ledger (https://en.wikipedia.org/wiki/Ledger_%28software%29).

  Even  if  you  have  no  legal  obligation  to  register  your
  financial  transactions  in  an  accounting  system,  you  can
  benefit from using Legder.

  It  is  easy  to setup, doesn't take much time to maintain and
  gives you a very good insight in  what  you  have  spent  your
  money on.

                         Version control
                         ---------------

  For  version  control  I  have  developed  the  habit to use a
  combination of RCS
  (https://en.wikipedia.org/wiki/Revision_Control_System)
  and Git.

  RCS is an old revision control  system,  that  works  only  on
  local  files.   I  use  this as a safety-net. During my work I
  frequently commit the changes in  the  journal  in  RCS.  This
  gives  me  a  number  of save-points, I can revert to, in case
  this might be necessary.

  When everything is OK, I commit the changes to Git. This  way,
  my  Git  repository  is  not  clobbered  with  small  changes,
  correction of errors and so on.

  I use this method for almost anything I  write,  including  my
  ledger journal.

  Emacs  cooperates  very well with RCS. The default key binding
  for this is `C-x v v` (vc-next-action).  Hit  this  to  rotate
  through  check  in  and check out. Log entries are stored with
  `C-c C-c` (vc-finish-logentry).

  In case you want to rename a file that is under the control of
  RCS, use M-x vc-rename-file.

                           Ledger-mode
                           -----------

  At  the  start of the new year it is time to close to books on
  the previous year.

  To minimize the amount of work I start with downloading a  CSV
  file with the bank-account transactions.

  A  simple  Perl-script  creates a ledger journal from this CSV
  file.

  A shell script creates ledger journal entries from my outgoing
  invoices.  These  invoices are in Postscript, the shell script
  combines a mixture of grep, awk and ed.

  After a concatenate of the  invoice  journal  entries  to  the
  bank-account  transaction journal entries, the only thing left
  to do, is to sort the ledger journal in chronological order.

  For this, the Emacs ledger-mode works great!

  I have named my journal 2021.ledger.

  In Emacs I have set the variable ledger-default-date-format to
  "%Y-%m-%d",  which  results  in  YYYY-MM-DD as the date of the
  records.

  This is the workflow:

  - open 2021.ledger in Emacs
  - Emacs recognizes the format and activates ledger-mode
  - `C-x h` (mark-whole-buffer) marks the entire buffer as 
    active region
  - `C-c C-s` sorts the journal entries in chronological order

  [Ledger-mode](https://github.com/ledger/ledger-mode)  can   do
  much more, I use only a fraction of its possibilities.

  See   also   the   ledger-mode    page    at    ledger-cli.org
  (https://www.ledger-cli.org/3.0/doc/ledger-mode.html).