blob: bfd8d360efe66af689b0a969067fdca49f46c5cb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
;;; ldg-register.el --- Helper code for use with the "ledger" command-line tool
;; Copyright (C) 2003-2013 John Wiegley (johnw AT gnu DOT org)
;; This file is not part of GNU Emacs.
;; This is free software; you can redistribute it and/or modify it under
;; the terms of the GNU General Public License as published by the Free
;; Software Foundation; either version 2, or (at your option) any later
;; version.
;;
;; This is distributed in the hope that it will be useful, but WITHOUT
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
;; for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
;; MA 02111-1307, USA.
(require 'ldg-post)
(require 'ldg-state)
(defgroup ledger-register nil
""
:group 'ledger)
(defcustom ledger-register-date-format "%m/%d/%y"
"*The date format used for ledger register reports."
:type 'string
:group 'ledger-register)
(defcustom ledger-register-line-format "%s %-30.30s %-25.25s %15s\n"
"*The date format used for ledger register reports."
:type 'string
:group 'ledger-register)
(defface ledger-register-pending-face
'((((background light)) (:weight bold))
(((background dark)) (:weight bold)))
"Face used to highlight pending entries in a register report."
:group 'ledger-register)
(defun ledger-register-render (data-buffer posts)
(dolist (post posts)
(let ((index 1))
(dolist (xact (nthcdr 5 post))
(let ((beg (point))
(where
(with-current-buffer data-buffer
(cons
(nth 0 post)
(if ledger-clear-whole-transactions
(save-excursion
(goto-line (nth 1 post))
(point-marker))
(save-excursion
(goto-line (nth 0 xact))
(point-marker)))))))
(insert (format ledger-register-line-format
(format-time-string ledger-register-date-format
(nth 2 post))
(nth 4 post) (nth 1 xact) (nth 2 xact)))
(if (nth 3 xact)
(set-text-properties beg (1- (point))
(list 'face 'ledger-register-pending-face
'where where))
(set-text-properties beg (1- (point))
(list 'where where))))
(setq index (1+ index)))))
(goto-char (point-min)))
(defun ledger-register-generate (&optional data-buffer &rest args)
(let ((buf (or data-buffer (current-buffer))))
(with-current-buffer (get-buffer-create "*ledger-register*")
(let ((pos (point))
(inhibit-read-only t))
(erase-buffer)
(ledger-register-render buf (apply #'ledger-exec-read buf args))
(goto-char pos))
(set-buffer-modified-p nil)
(toggle-read-only t)
(display-buffer (current-buffer) t))))
(provide 'ldg-register)
|