Merge commit 'af0da737fc4ef8f9ccebd3d43519610b8a8fcaa1' into next

Conflicts:
	lisp/ledger-reconcile.el
This commit is contained in:
Craig Earls 2015-02-25 22:01:33 -07:00
commit 1f803d6294
65 changed files with 1344 additions and 2235 deletions

View file

@ -1,30 +1,36 @@
((nil . ((tab-width . 2)
(sentence-end-double-space . t)
(bug-reference-url-format
. "http://bugs.ledger-cli.org/show_bug.cgi?id=%s")))
(c-mode . ((c-file-style . "ledger")
(c-style-alist
("ledger"
(indent-tabs-mode)
(c-basic-offset . 2)
(c-comment-only-line-offset 0 . 0)
(c-hanging-braces-alist
(substatement-open before after)
(arglist-cont-nonempty))
(c-offsets-alist
(statement-block-intro . +)
(knr-argdecl-intro . 5)
(substatement-open . 0)
(substatement-label . 0)
(label . 0)
(case-label . 0)
(statement-case-open . 0)
(statement-cont . +)
(arglist-intro . +)
(arglist-close . +)
(inline-open . 0)
(brace-list-open . 0)
(topmost-intro-cont first c-lineup-topmost-intro-cont
c-lineup-gnu-DEFUN-intro-cont))
(c-special-indent-hook . c-gnu-impose-minimum)
(c-block-comment-prefix . ""))))))
;;; Directory Local Variables
;;; For more information see (info "(emacs) Directory Variables")
((nil
(tab-width . 2)
(sentence-end-double-space . t)
(bug-reference-url-format . "http://bugs.ledger-cli.org/show_bug.cgi?id=%s"))
(c-mode
(c-file-style . "ledger")
(c-style-alist
("ledger"
(indent-tabs-mode)
(c-basic-offset . 2)
(c-comment-only-line-offset 0 . 0)
(c-hanging-braces-alist
(substatement-open before after)
(arglist-cont-nonempty))
(c-offsets-alist
(statement-block-intro . +)
(knr-argdecl-intro . 5)
(substatement-open . 0)
(substatement-label . 0)
(label . 0)
(case-label . 0)
(statement-case-open . 0)
(statement-cont . +)
(arglist-intro . +)
(arglist-close . +)
(inline-open . 0)
(brace-list-open . 0)
(topmost-intro-cont first c-lineup-topmost-intro-cont c-lineup-gnu-DEFUN-intro-cont))
(c-special-indent-hook . c-gnu-impose-minimum)
(c-block-comment-prefix . ""))))
(emacs-lisp-mode
(indent-tabs-mode)))

3
.gitignore vendored
View file

@ -43,17 +43,20 @@ doc/*.html
doc/*.info
doc/*.info-*
doc/*.ky
doc/*.kys
doc/*.log
doc/*.pdf
doc/*.pg
doc/*.toc
doc/*.tp
doc/*.vr
doc/*.vrs
doc/.dirstamp
doc/html/
doc/latex/
doc/refman.pdf
doc/report/
doc/version.texi
elisp-comp
install-sh
intl/

29
acprep
View file

@ -616,8 +616,8 @@ class PrepareBuild(CommandLineApp):
self.execute(*packages)
if exists('/etc/redhat-release'):
release = open('/etc/redhat-release')
if release.readline().startswith('CentOS'):
release = open('/etc/redhat-release').readline()
if release.startswith('CentOS'):
self.log.info('Looks like you are using YUM on CentOS')
packages = [
'sudo', 'yum', 'install',
@ -644,6 +644,31 @@ class PrepareBuild(CommandLineApp):
]
self.log.info('Executing: ' + ' '.join(packages))
self.execute(*packages)
elif release.startswith('Fedora release 20'):
self.log.info('Looks like you are using YUM on Fedora 20')
packages = [
'sudo', 'yum', 'install',
'boost-devel',
'bzip2-devel',
'cmake',
'doxygen',
'gcc',
'gcc-c++',
'gettext',
'gettext-devel',
'gmp-devel',
'lcov',
'libedit-devel',
'mpfr-devel',
'ninja-build',
'python-devel',
'sloccount',
'texinfo',
'zlib-devel'
]
self.log.info('Executing: ' + ' '.join(packages))
self.execute(*packages)
elif system.startswith('CYGWIN'):
self.log.info('Looks like you are using Cygwin')
self.log.info('Please install the dependencies manually.')

View file

@ -1,5 +1,5 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Ledger
;; Ledger
;; Maybe later add this to the expense repo once it settles
(add-to-list 'load-path "/home/adamsrl/.emacs.d/addons/ledger")
@ -104,19 +104,19 @@
(defun ledger-expense-shortcut ()
"Updates the ER and Project metadata with the current values of the shortcut variables."
(interactive)
(when (eq major-mode 'ledger-mode)
(if (or (eql *ledger-expense-shortcut-ER* "")
(eql *ledger-expense-shortcut-Proj* ""))
(message "Run ledger-expense-shortcut-setup first.")
(save-excursion
(search-forward "; ER:")
(kill-line nil)
(insert " " *ledger-expense-shortcut-ER*))
(save-excursion
(search-forward "; PROJECT:")
(kill-line nil)
(insert " " *ledger-expense-shortcut-Proj*)))))
(interactive)
(when (eq major-mode 'ledger-mode)
(if (or (eql *ledger-expense-shortcut-ER* "")
(eql *ledger-expense-shortcut-Proj* ""))
(message "Run ledger-expense-shortcut-setup first.")
(save-excursion
(search-forward "; ER:")
(kill-line nil)
(insert " " *ledger-expense-shortcut-ER*))
(save-excursion
(search-forward "; PROJECT:")
(kill-line nil)
(insert " " *ledger-expense-shortcut-Proj*)))))
(defun ledger-expense-split ()
"Splits the current transaction between internal and projects."
@ -158,33 +158,33 @@
(defun ledger-expense-personal ()
"Makes the expense an personal one, eliminating metadata and receipts."
(interactive)
(when (eq major-mode 'ledger-mode) ; I made this local now, should only trigger in ldg-mode
(save-excursion
(end-of-line)
(re-search-backward "^[0-9]\\{4\\}/")
(let ((begin (point))
(end (save-excursion (re-search-forward "^$"))))
(when (re-search-forward "^ Dest:Projects" end t)
(replace-match " Other:Personal"))
(goto-char begin)
(save-excursion
(when (re-search-forward "^ +; ER:" end t)
(beginning-of-line)
(kill-line 1)))
(save-excursion
(when (re-search-forward "^ +; PROJECT:" end t)
(beginning-of-line)
(kill-line 1)))
(save-excursion
(when (re-search-forward "^ +; CATEGORY:" end t)
(beginning-of-line)
(kill-line 1)))
(save-excursion
(when (re-search-forward "^ +; RECEIPT:" end t)
(beginning-of-line)
(kill-line 1)))
(ledger-toggle-current-entry)))))
(interactive)
(when (eq major-mode 'ledger-mode) ; I made this local now, should only trigger in ldg-mode
(save-excursion
(end-of-line)
(re-search-backward "^[0-9]\\{4\\}/")
(let ((begin (point))
(end (save-excursion (re-search-forward "^$"))))
(when (re-search-forward "^ Dest:Projects" end t)
(replace-match " Other:Personal"))
(goto-char begin)
(save-excursion
(when (re-search-forward "^ +; ER:" end t)
(beginning-of-line)
(kill-line 1)))
(save-excursion
(when (re-search-forward "^ +; PROJECT:" end t)
(beginning-of-line)
(kill-line 1)))
(save-excursion
(when (re-search-forward "^ +; CATEGORY:" end t)
(beginning-of-line)
(kill-line 1)))
(save-excursion
(when (re-search-forward "^ +; RECEIPT:" end t)
(beginning-of-line)
(kill-line 1)))
(ledger-toggle-current-entry)))))
(defun ledger-expense-show-receipt ()
"Uses the Receipt buffer to show the receipt of the txn we're on."

View file

@ -202,13 +202,13 @@
(defun ledger-receipt-skip ()
"Move the current image to the Skip directory because its not relevant."
(rename-file (concat ledger-matching-sourcedir "/"
ledger-matching-image-name)
(concat ledger-matching-sourcedir "/Skip/"
ledger-matching-image-name))
(rename-file (concat ledger-matching-sourcedir "/"
ledger-matching-image-name)
(concat ledger-matching-sourcedir "/Skip/"
ledger-matching-image-name))
;; Update the receipt screen at the same offset
(ledger-matching-update-current-image))
;; Update the receipt screen at the same offset
(ledger-matching-update-current-image))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Items below are speed entry macros, and should eventually migrate to their own file.
@ -242,19 +242,19 @@
(defun ledger-expense-shortcut ()
"Updates the ER and Project metadata with the current values of the shortcut variables."
(interactive)
(when (eq major-mode 'ledger-mode)
(if (or (eql *ledger-expense-shortcut-ER* "")
(eql *ledger-expense-shortcut-Proj* ""))
(message "Run ledger-expense-shortcut-setup first.")
(save-excursion
(search-forward "; ER:")
(kill-line nil)
(insert " " *ledger-expense-shortcut-ER*))
(save-excursion
(search-forward "; PROJECT:")
(kill-line nil)
(insert " " *ledger-expense-shortcut-Proj*)))))
(interactive)
(when (eq major-mode 'ledger-mode)
(if (or (eql *ledger-expense-shortcut-ER* "")
(eql *ledger-expense-shortcut-Proj* ""))
(message "Run ledger-expense-shortcut-setup first.")
(save-excursion
(search-forward "; ER:")
(kill-line nil)
(insert " " *ledger-expense-shortcut-ER*))
(save-excursion
(search-forward "; PROJECT:")
(kill-line nil)
(insert " " *ledger-expense-shortcut-Proj*)))))
(defun ledger-expense-split ()
"Splits the current transaction between internal and projects."
@ -296,33 +296,33 @@
(defun ledger-expense-personal ()
"Makes the expense an personal one, eliminating metadata and receipts."
(interactive)
(when (eq major-mode 'ledger-mode) ; I made this local now, should only trigger in ldg-mode
(save-excursion
(end-of-line)
(re-search-backward "^[0-9]\\{4\\}/")
(let ((begin (point))
(end (save-excursion (re-search-forward "^$"))))
(when (re-search-forward "^ Dest:Projects" end t)
(replace-match " Other:Personal"))
(goto-char begin)
(save-excursion
(when (re-search-forward "^ +; ER:" end t)
(beginning-of-line)
(kill-line 1)))
(save-excursion
(when (re-search-forward "^ +; PROJECT:" end t)
(beginning-of-line)
(kill-line 1)))
(save-excursion
(when (re-search-forward "^ +; CATEGORY:" end t)
(beginning-of-line)
(kill-line 1)))
(save-excursion
(when (re-search-forward "^ +; RECEIPT:" end t)
(beginning-of-line)
(kill-line 1)))
(ledger-toggle-current-entry)))))
(interactive)
(when (eq major-mode 'ledger-mode) ; I made this local now, should only trigger in ldg-mode
(save-excursion
(end-of-line)
(re-search-backward "^[0-9]\\{4\\}/")
(let ((begin (point))
(end (save-excursion (re-search-forward "^$"))))
(when (re-search-forward "^ Dest:Projects" end t)
(replace-match " Other:Personal"))
(goto-char begin)
(save-excursion
(when (re-search-forward "^ +; ER:" end t)
(beginning-of-line)
(kill-line 1)))
(save-excursion
(when (re-search-forward "^ +; PROJECT:" end t)
(beginning-of-line)
(kill-line 1)))
(save-excursion
(when (re-search-forward "^ +; CATEGORY:" end t)
(beginning-of-line)
(kill-line 1)))
(save-excursion
(when (re-search-forward "^ +; RECEIPT:" end t)
(beginning-of-line)
(kill-line 1)))
(ledger-toggle-current-entry)))))
(defun ledger-expense-show-receipt ()
"Uses the Receipt buffer to show the receipt of the txn we're on."

View file

@ -191,7 +191,8 @@ Show any gains (or losses) in commodity values over time.
Only show the top
.Ar number
postings.
.\".It Fl \-historical Pq Fl H
.It Fl \-historical Pq Fl H
Value commodities at the time of their acquisition.
.It Fl \-invert
Invert the value of amounts shown.
.It Fl \-market Pq Fl V
@ -309,7 +310,7 @@ fit inside the
If
.Ar INT
is zero, then the
account name will be truncated on the right. If
account name will be truncated on the right. If
.Ar INT
is greater
than
@ -320,7 +321,7 @@ desired width.
.It Fl \-account Ar EXPR
Prepend
.Ar EXPR
to all accounts reported. That is, the option
to all accounts reported. That is, the option
.Fl \-account Ar \*q'Personal'\*q
would tack
.Ar Personal:
@ -345,7 +346,7 @@ transactions used.
.It Fl \-add-budget
Show only un-budgeted postings.
.It Fl \-amount Ar EXPR Pq Fl t
Apply the given value expression to the posting amount. Using
Apply the given value expression to the posting amount. Using
.Fl \-amount Ar EXPR
you can apply an
arbitrary transformation to the postings.
@ -366,7 +367,10 @@ Alias for
Ignore init files and environment variables for the
.Nm
run.
.\".It Fl \-auto-match
.It Fl \-auto-match
When generating a ledger transaction from a CSV file using the
.Ic convert
command, automatically match an account from the Ledger journal.
.It Fl \-aux-date
Show auxiliary dates for all calculations.
Alias for
@ -378,7 +382,9 @@ running totals.
Specify the format to use for the
.Ic balance
report.
.\".It Fl \-base
.It Fl \-base
Reduce convertible commodities down the bottom of the conversion, e.g.
display time in seconds.
.It Fl \-basis Pq Fl B
Report the cost basis on all posting.
Alias for
@ -386,12 +392,12 @@ Alias for
.It Fl \-begin Ar DATE Pq Fl b
Specify the start
.Ar DATE
of all calculations. Transactions before
of all calculations. Transactions before
that date will be ignored.
.It Fl \-bold-if Ar EXPR
Print the entire line in bold if the given value expression is true.
.It Fl \-budget
Only display budgeted items. In a
Only display budgeted items. In a
.Ic register
report this displays transaction in the budget, in a balance report this
displays accounts in the budget.
@ -401,7 +407,6 @@ Specify the format to use for the
report.
.It Fl \-by-payee Pq Fl P
Group postings in the register report by common payee names.
.\".It Fl \-cache Ar FILE
.It Fl \-check-payees
Enable strict and pedantic checking for payees as well as accounts,
commodities and tags.
@ -424,7 +429,7 @@ Make the
.Ic register
report
.Ar INT
characters wide. By default
characters wide. By default
.Nm
will use all available columns in your terminal.
.It Fl \-cost
@ -461,7 +466,12 @@ Print dates using
Refer to
.Xr strftime 3
for details on the format string syntax.
.\" .It Fl \-datetime-format Ar FMT
.It Fl \-datetime-format Ar DATETIMEFMT
Print datetimes using
.Ar DATETIMEFMT .
Refer to
.Xr strftime 3
for details on the format string syntax.
.It Fl \-date-width Ar INT
Specify the width, in characters, of the date column in the
.Ic register
@ -501,8 +511,14 @@ but not
.Sy Expenses:Entertainment:Dining .
This is a display predicate, which means it only affects display,
not the total calculations.
.It Fl \-detail
Related to
.Ic convert
command. Synonym to
.Fl \-rich-data
option.
.It Fl \-deviation
Report each posting's deviation from the average. It is only meaningful
Report each posting's deviation from the average. It is only meaningful
in the
.Ic register No and Ic prices
reports.
@ -537,7 +553,7 @@ distribution. Downloaded quote price are then appended to the price
database, usually specified using the environment variable
.Ev LEDGER_PRICE_DB .
.It Fl \-effective
Show auxiliary dates for all calculations. Alias for
Show auxiliary dates for all calculations. Alias for
.Fl \-aux-date .
.It Fl \-empty Pq Fl E
Include empty accounts in report.
@ -551,7 +567,9 @@ Related to the
.Ic equity
command. Gives current account balances in the form of a register
report.
.\".It Fl \-exact
.It Fl \-exact
Report beginning and ending of periods by the date of the first and last
posting occurring in that period.
.It Fl \-exchange Ar COMMODITY Oo , Ar COMMODITY, ... Oc Pq Fl X
Display values in terms of the given
.Ar COMMODITY .
@ -560,19 +578,18 @@ The latest available price is used.
.It Fl \-file Ar FILE
Read journal data from
.Ar FILE .
.\".It Fl \-full-help
.It Fl \-first Ar INT
Print the first
.Ar INT
entries. Opposite of
entries. Opposite of
.Fl \-last Ar INT .
Alias for
.Fl \-head .
.It Fl \-flat
Force the full names of accounts to be used in the balance report. The
Force the full names of accounts to be used in the balance report. The
balance report will not use an indented tree.
.It Fl \-force-color
Output TTY color codes even if the TTY doesn't support them. Useful
Output TTY color codes even if the TTY doesn't support them. Useful
for TTYs that don't advertise their capabilities correctly.
.It Fl \-force-pager
Force
@ -618,22 +635,18 @@ register report.
.It Fl \-head Ar INT
Print the first
.Ar INT
entries. Opposite of
entries. Opposite of
.Fl \-tail Ar INT .
Alias for
.Fl \-first
.It Fl \-help
Print a summary of all the options, and what they are used for. This
can be a handy way to remember which options do what. This help screen
is also printed if
.Nm
is run without a command.
.\".It Fl \-help-calc
.\".It Fl \-help-comm
.\".It Fl \-help-disp
Print this man page.
.It Fl \-immediate
Evaluate calculations immediately rather than lazily.
.\".It Fl \-import
.It Fl \-import Ar FILE
Import
.Ar FILE
as Python module.
.It Fl \-init-file Ar FILE Pq Fl i
Read
.Ar FILE
@ -658,9 +671,9 @@ Change the sign of all reported values.
.It Fl \-last Ar INT .
Report only the last
.Ar INT
entries. Opposite of
entries. Opposite of
.Fl \-first Ar INT .
Only useful on a register report. Alias for
Only useful on a register report. Alias for
.Fl \-tail .
.It Fl \-leeway Ar INT Pq Fl Z
Alias for
@ -678,7 +691,9 @@ purchased.
.It Fl \-lots
Report the date and price at which each commodity was purchased in
a balance report.
.\".It Fl \-lots-actual
.It Fl \-lots-actual
Preserve the uniqueness of commodities so they aren't merged during
reporting without printing the lot annotations.
.It Fl \-market Pq Fl V
Use the latest market value for all commodities.
.It Fl \-master-account Ar STR
@ -717,7 +732,7 @@ Suppress printing the final total line in a balance report.
.It Fl \-now Ar DATE
Use
.Ar DATE
as the current date. This affects the output when using
as the current date. This affects the output when using
.Fl \-period ,
.Fl \-begin ,
.Fl \-end ,
@ -742,7 +757,7 @@ Use
.Ar STR
as the pager program.
.It Fl \-payee
Sets a value expression for formatting the payee. In the
Sets a value expression for formatting the payee. In the
.Ic register
report this prevents the second entry from having
a date and payee for each transaction.
@ -759,7 +774,7 @@ Calculate the percentage value of each account in a balance reports.
Only works for account that have a single commodity.
.It Fl \-period Ar PERIOD Pq Fl p
Define a period expression that sets the time period during which
transactions are to be accounted. For a
transactions are to be accounted. For a
.Ic register
report only
the transactions that satisfy the period expression with be displayed.
@ -792,12 +807,12 @@ Use the price of the commodity purchase for performing calculations.
.It Fl \-price-exp Ar STR Pq Fl Z
Set the expected freshness of price quotes, in
.Ar INT
minutes. That
minutes. That
is, if the last known quote for any commodity is older than this value,
and if
.Fl \-download
is being used, then the Internet will be
consulted again for a newer price. Otherwise, the old price is still
consulted again for a newer price. Otherwise, the old price is still
considered to be fresh enough.
Alias for
.Fl \-leeway .
@ -808,7 +823,7 @@ report.
.It Fl \-pricedb-format Ar FMT
Set the format expected for the historical price file.
.It Fl \-primary-date
Show primary dates for all calculations. Alias for
Show primary dates for all calculations. Alias for
.Fl \-actual-dates
.It Fl \-quantity Pq Fl O
Report commodity totals (this is the default).
@ -842,10 +857,27 @@ of the transaction.
Show all postings in a transaction, similar to
.Fl \-related
but show both sides of each transaction.
.\".It Fl \-revalued
.\".It Fl \-revalued-only
.\".It Fl \-revalued-total Ar EXPR
.\".It Fl \-rich-data
.It Fl \-revalued
Report discrepancy in values for manual reports by inserting
<Revalued>
postings.
This is implied when using
the
.Fl \-exchange Pq Fl X
or
.Fl \-market Pq Fl V
option.
.It Fl \-revalued-only
Show only
<Revalued>
postings.
.It Fl \-revalued-total
Display the sum of the revalued postings as the running total, which serves
to show unrealized capital in a gain/losses report.
.It Fl \-rich-data
When generating a ledger transaction from a CSV file using the
.Ic convert
command, add CSV, Imported, and UUID meta-data.
.It Fl \-seed Ar INT
Set the random seed to
.Ar INT
@ -857,8 +889,9 @@ Execute a
.Nm
script.
.It Fl \-sort Ar EXPR Pq Fl S
Sort the register report based on the value expression given to sort.
.\".It Fl \-sort-all
Sort the register report based on the value expression
.Ar EXPR .
.\".It Fl \-sort-all Ar EXPR
.It Fl \-sort-xacts
Sort the posting within transactions using the given value expression.
.It Fl \-start-of-week Ar STR
@ -879,12 +912,15 @@ Report register as a single subtotal.
.It Fl \-tail Ar INT
Report only the last
.Ar INT
entries. Only useful on a register report. Alias for
entries. Only useful on a register report. Alias for
.Fl \-last Ar INT
.It Fl \-time-colon
Display the value for commodities based on seconds as hours and minutes.
Thus 8100s will be displayed as 2:15h instead of 2.25h.
.\".It Fl \-time-report
.It Fl \-time-report
Add two columns to the
.Ic balance
report to show the earliest checkin and checkout times for timelog entries.
.It Fl \-total Ar EXPR Pq Fl T
Define a value expression used to calculate the total in reports.
.It Fl \-total-data Pq Fl J
@ -892,12 +928,12 @@ Show only dates and totals to format the output for plots.
.It Fl \-total-width Ar INT
Set the width of the total field in the register report.
.It Fl \-trace Ar INT
Enable tracing. The
Enable tracing. The
.Ar INT
specifies the level of trace desired.
.It Fl \-truncate Ar STR
Indicates how truncation should happen when the contents of columns
exceed their width. Valid arguments for
exceed their width. Valid arguments for
.Ar STR
are
.Ar leading ,
@ -917,14 +953,14 @@ Show generated unrealized gain and loss accounts in the balance
report.
.It Fl \-unrealized-gains
Allow the user to specify what account name should be used for
unrealized gains. Defaults to
unrealized gains. Defaults to
.Sy "Equity:Unrealized Gains" .
Often set in one's
.Pa ~/.ledgerrc
file to change the default.
.It Fl \-unrealized-losses
Allow the user to specify what account name should be used for
unrealized gains. Defaults to
unrealized gains. Defaults to
.Sy "Equity:Unrealized Losses" .
Often set in one's
.Pa ~/.ledgerrc
@ -936,17 +972,20 @@ precision.
Show the values used by each tag when used in combination with the
.Ic tags
command.
.\".It Fl \-value-expr Ar EXPR
.It Fl \-value-expr Ar EXPR
Set a global value expression annotation.
.It Fl \-verbose
Print detailed information on the execution of
.Nm .
.It Fl \-verify
Enable additional assertions during run-time. This causes a significant
Enable additional assertions during run-time. This causes a significant
slowdown. When combined with
.Fl \-debug Ar CODE
.Nm
will produce memory trace information.
.\".It Fl \-verify-memory
.It Fl \-verify-memory
Verify that every constructed object is properly destructed. This is for
debugging purposes only.
.It Fl \-version
Print version information and exit.
.It Fl \-weekly Pq Fl W
@ -960,7 +999,7 @@ Shorthand for
.El
.Sh PRE-COMMANDS
Pre-commands are useful when you aren't sure how a command or option
will work. The difference between a pre-command and a regular command
will work. The difference between a pre-command and a regular command
is that pre-commands ignore the journal data file completely, nor is
the user's init file read.
.Bl -tag -width -indent
@ -1117,6 +1156,12 @@ toward -infinity.
The name of the
.Nm
data file from whence the posting came.
.It Fn format string
Evaluate
.Ar string
as format just like the
.Fl \-format
option.
.It Fn format_date date format
Return the
.Ar date
@ -1125,18 +1170,56 @@ as a string using
Refer to
.Xr strftime 3
for format string details.
.\".It Fn get_at
.\".It Fn has_meta
.It Fn format_datetime datetime format
Return the
.Ar datetime
as a string using
.Ar format .
Refer to
.Xr strftime 3
for format string details.
.It Fn get_at seq index
Return value at
.Ar index
from
.Ar seq .
Used internally to construct different reports.
.It Fn has_meta
Return true if the posting has metadata named
.Ar tag ,
false otherwise.
.It Fn has_tag tag
Return true if the posting has metadata named
.Ar tag ,
false otherwise.
.\".It Fn is_seq
.It Fn is_seq value
Return true if
.Ar value
is a sequence. Used internally.
.It Fn join value
Replace all newlines in
.Ar value
with
.Li \en .
.It Fn justify value first_width latter_width right_justify colorize
Right or left justify the string representing
.Ar value .
The width of the field in the first line is given by
.Ar first_width .
For subsequent lines the width is given by
.Ar latter_width .
If
.Ar latter_width
is -1,
.Ar first_width
is used for all lines.
If
.Ar right_justify
is true then the field is right justified within the width of the field. If it
is false, then the field is left justified and padded to the full width of the
field. If
.Ar colorize
is true, then ledger will honor color settings.
.It Fn market value datetime
Return the price of
.Ar value
@ -1146,8 +1229,13 @@ Note that
.Ar datetime
must be surrounded by brackets in order to be parsed correctly, e.g.
.Bq 2012/03/23 .
.\".It Sy meta
.I.\"t Sy note
.It Fn meta
Return the value of metadata named
.Ar name .
.It Sy note
Return the note for the posting.
.It Sy now
Return the current datetime.
.\".It Sy null
.It Sy options
A variable that allows access to the values of the given command-line options
@ -1173,7 +1261,11 @@ in relation to
.Ar value_b .
.\".It Sy post
.\" A variable scope
.\".It Sy print
.It Fn print value
Print
.Ar value
to stdout.
Used internally for debugging.
.It Fn quantity value
Return the quantity of
.Ar value
@ -1192,30 +1284,61 @@ Return
.Ar value
rounded to
.Ar n
digits. Does not affect formatting.
.\".It Sy scrub
digits. Does not affect formatting.
.It Sy should_bold
Return true if expression given to
.Fl \-bold-if
evaluates to true. Internal use only!
.It Fn scrub value
Clean
.Ar value
using various transformations such as round,
stripping value annotations, and more.
.\".It Sy status
.\".It Sy strip
.It Fn strip value
Strip value annotation from
.Ar value .
.\".It Sy subcount
.It Fn tag name
Return the value of tag named
.Ar name .
.\".It Fn to_amount value
.\".It Fn to_balance value
.\".It Fn to_boolean value
.\".It Fn to_date value
.\".It Fn to_datetime value
.It Fn to_amount value
Convert
.Ar value
to an amount. Internal use only!
.It Fn to_balance value
Convert
.Ar value
to a balance. Internal use only!
.It Fn to_boolean value
Convert
.Ar value
to a boolean. Internal use only!
.It Fn to_date value
Convert
.Ar value
to a date. Internal use only!
.It Fn to_datetime value
Convert
.Ar value
to a datetime. Internal use only!
.It Fn to_int value
Return the integer value for
.Ar value .
.\".It Fn to_mask value
.\".It Fn to_sequence value
.It Fn to_mask value
Convert
.Ar value
to a mask. Internal use only!
.It Fn to_sequence value
Convert
.Ar value
to a sequence. Internal use only!
.It Fn to_string value
Convert
.Ar value
to a character string.
.It Sy today
Return todays date.
Return today's date.
.It Sy total
Return the total of the posting.
.It Sy total_expr
@ -1225,7 +1348,14 @@ option.
.It Fn trim value
Trim leading and trailing whitespace from
.Ar value .
.\".It Fn truncate
.It Fn truncated string, total_len, account_len
Truncate
.Ar string
to
.Ar total_len
enusring that each account is at least
.Ar account_len
long.
.\".It Sy uncleared
.It Sy virtual
Return true if the transaction is virtual, e.g automated, false otherwise.

File diff suppressed because it is too large Load diff

View file

@ -91,8 +91,8 @@ Returns a list with (value commodity)."
(error "Can't add different commodities, %S to %S" c1 c2)))
(defun ledger-strip (str char)
"Return STR with CHAR removed."
(replace-regexp-in-string char "" str))
"Return STR with CHAR removed."
(replace-regexp-in-string char "" str))
(defun ledger-string-to-number (str &optional decimal-comma)
"improve builtin string-to-number by handling internationalization, and return nil if number can't be parsed"
@ -105,7 +105,7 @@ Returns a list with (value commodity)."
(string-to-number nstr)))
(defun ledger-number-to-string (n &optional decimal-comma)
"number-to-string that handles comma as decimal."
"number-to-string that handles comma as decimal."
(let ((str (number-to-string n)))
(when (or decimal-comma
(assoc "decimal-comma" ledger-environment-alist))
@ -124,7 +124,7 @@ longer ones are after the value."
(concat commodity " " str))))
(defun ledger-read-commodity-string (prompt)
"Read an amount from mini-buffer using PROMPT."
"Read an amount from mini-buffer using PROMPT."
(let ((str (read-from-minibuffer
(concat prompt " (" ledger-reconcile-default-commodity "): ")))
comm)

View file

@ -157,7 +157,7 @@
(ledger-accounts)))))
(defun ledger-trim-trailing-whitespace (str)
(replace-regexp-in-string "[ \t]*$" "" str))
(replace-regexp-in-string "[ \t]*$" "" str))
(defun ledger-fully-complete-xact ()
"Completes a transaction if there is another matching payee in the buffer.
@ -235,7 +235,7 @@ ledger-magic-tab would cycle properly"
pcomplete-seen pcomplete-norm-func
pcomplete-args pcomplete-last pcomplete-index
pcomplete-autolist
(completions (pcomplete-completions))
(completions (pcomplete-completions))
(result (pcomplete-do-complete pcomplete-stub completions))
(pcomplete-termination-string ""))
(and result

View file

@ -53,7 +53,7 @@
(setq buffer-read-only t)))
(defun ledger-exec-success-p (ledger-output-buffer)
"Return t if the ledger output in LEDGER-OUTPUT-BUFFER is successful."
"Return t if the ledger output in LEDGER-OUTPUT-BUFFER is successful."
(with-current-buffer ledger-output-buffer
(goto-char (point-min))
(if (and (> (buffer-size) 1) (looking-at (regexp-quote "While")))

View file

@ -38,45 +38,45 @@
:group 'ledger)
(defun ledger-fontify-buffer-part (&optional beg end len)
"Fontify buffer from BEG to END, length LEN."
(save-excursion
(unless beg (setq beg (point-min)))
(unless end (setq end (point-max)))
(goto-char beg)
(beginning-of-line)
(while (< (point) end)
(cond ((or (looking-at ledger-xact-start-regex)
(looking-at ledger-posting-regex))
(ledger-fontify-xact-at (point)))
((looking-at ledger-directive-start-regex)
(ledger-fontify-directive-at (point))))
(ledger-navigate-next-xact-or-directive))))
"Fontify buffer from BEG to END, length LEN."
(save-excursion
(unless beg (setq beg (point-min)))
(unless end (setq end (point-max)))
(goto-char beg)
(beginning-of-line)
(while (< (point) end)
(cond ((or (looking-at ledger-xact-start-regex)
(looking-at ledger-posting-regex))
(ledger-fontify-xact-at (point)))
((looking-at ledger-directive-start-regex)
(ledger-fontify-directive-at (point))))
(ledger-navigate-next-xact-or-directive))))
(defun ledger-fontify-xact-at (position)
"Fontify the xact at POSITION."
(interactive "d")
(save-excursion
(goto-char position)
(let ((extents (ledger-navigate-find-element-extents position))
(state (ledger-transaction-state)))
(if (and ledger-fontify-xact-state-overrides state)
(cond ((eq state 'cleared)
(ledger-fontify-set-face extents 'ledger-font-xact-cleared-face))
((eq state 'pending)
(ledger-fontify-set-face extents 'ledger-font-xact-pending-face)))
(ledger-fontify-xact-by-line extents)))))
(interactive "d")
(save-excursion
(goto-char position)
(let ((extents (ledger-navigate-find-element-extents position))
(state (ledger-transaction-state)))
(if (and ledger-fontify-xact-state-overrides state)
(cond ((eq state 'cleared)
(ledger-fontify-set-face extents 'ledger-font-xact-cleared-face))
((eq state 'pending)
(ledger-fontify-set-face extents 'ledger-font-xact-pending-face)))
(ledger-fontify-xact-by-line extents)))))
(defun ledger-fontify-xact-by-line (extents)
"Do line-by-line detailed fontification of xact in EXTENTS."
(save-excursion
(ledger-fontify-xact-start (car extents))
(while (< (point) (cadr extents))
(if (looking-at "[ \t]+;")
(ledger-fontify-set-face (list (point) (progn
(end-of-line)
(point))) 'ledger-font-comment-face)
(ledger-fontify-posting (point)))
(forward-line))))
"Do line-by-line detailed fontification of xact in EXTENTS."
(save-excursion
(ledger-fontify-xact-start (car extents))
(while (< (point) (cadr extents))
(if (looking-at "[ \t]+;")
(ledger-fontify-set-face (list (point) (progn
(end-of-line)
(point))) 'ledger-font-comment-face)
(ledger-fontify-posting (point)))
(forward-line))))
(defun ledger-fontify-xact-start (pos)
"POS should be at the beginning of a line starting an xact.
@ -102,97 +102,97 @@ Fontify the first line of an xact"
(forward-line)))
(defun ledger-fontify-posting (pos)
"Fontify the posting at POS."
(let* ((state nil)
(end-of-line-comment nil)
(end (progn (end-of-line)
(point)))
(start (progn (beginning-of-line)
(point))))
"Fontify the posting at POS."
(let* ((state nil)
(end-of-line-comment nil)
(end (progn (end-of-line)
(point)))
(start (progn (beginning-of-line)
(point))))
;; Look for a posting status flag
(set-match-data nil 'reseat)
(re-search-forward " \\([*!]\\) " end t)
(if (match-string 1)
(setq state (ledger-state-from-string (match-string 1))))
(beginning-of-line)
(re-search-forward "[[:graph:]]\\([ \t][ \t]\\)" end 'end) ;; find the end of the account, or end of line
;; Look for a posting status flag
(set-match-data nil 'reseat)
(re-search-forward " \\([*!]\\) " end t)
(if (match-string 1)
(setq state (ledger-state-from-string (match-string 1))))
(beginning-of-line)
(re-search-forward "[[:graph:]]\\([ \t][ \t]\\)" end 'end) ;; find the end of the account, or end of line
(when (<= (point) end) ;; we are still on the line
(ledger-fontify-set-face (list start (point))
(cond ((eq state 'cleared)
'ledger-font-posting-account-cleared-face)
((eq state 'pending)
'ledger-font-posting-account-pending-face)
(t
'ledger-font-posting-account-face)))
(when (<= (point) end) ;; we are still on the line
(ledger-fontify-set-face (list start (point))
(cond ((eq state 'cleared)
'ledger-font-posting-account-cleared-face)
((eq state 'pending)
'ledger-font-posting-account-pending-face)
(t
'ledger-font-posting-account-face)))
(when (< (point) end) ;; there is still more to fontify
(setq start (point)) ;; update start of next font region
(setq end-of-line-comment (re-search-forward ";" end 'end)) ;; find the end of the line, or start of a comment
(ledger-fontify-set-face (list start (point) )
(cond ((eq state 'cleared)
'ledger-font-posting-amount-cleared-face)
((eq state 'pending)
'ledger-font-posting-amount-pending-face)
(t
'ledger-font-posting-amount-face)))
(when end-of-line-comment
(setq start (point))
(end-of-line)
(ledger-fontify-set-face (list (- start 1) (point)) ;; subtract 1 from start because we passed the semi-colon
'ledger-font-comment-face))))))
(when (< (point) end) ;; there is still more to fontify
(setq start (point)) ;; update start of next font region
(setq end-of-line-comment (re-search-forward ";" end 'end)) ;; find the end of the line, or start of a comment
(ledger-fontify-set-face (list start (point) )
(cond ((eq state 'cleared)
'ledger-font-posting-amount-cleared-face)
((eq state 'pending)
'ledger-font-posting-amount-pending-face)
(t
'ledger-font-posting-amount-face)))
(when end-of-line-comment
(setq start (point))
(end-of-line)
(ledger-fontify-set-face (list (- start 1) (point)) ;; subtract 1 from start because we passed the semi-colon
'ledger-font-comment-face))))))
(defun ledger-fontify-directive-at (pos)
"Fontify the directive at POS."
(let ((extents (ledger-navigate-find-element-extents pos))
(face 'ledger-font-default-face))
(cond ((looking-at "=")
(setq face 'ledger-font-auto-xact-face))
((looking-at "~")
(setq face 'ledger-font-periodic-xact-face))
((looking-at "[;#%|\\*]")
(setq face 'ledger-font-comment-face))
((looking-at "\\(year\\)\\|Y")
(setq face 'ledger-font-year-directive-face))
((looking-at "account")
(setq face 'ledger-font-account-directive-face))
((looking-at "apply")
(setq face 'ledger-font-apply-directive-face))
((looking-at "alias")
(setq face 'ledger-font-alias-directive-face))
((looking-at "assert")
(setq face 'ledger-font-assert-directive-face))
((looking-at "\\(bucket\\)\\|A")
(setq face 'ledger-font-bucket-directive-face))
((looking-at "capture")
(setq face 'ledger-font-capture-directive-face))
((looking-at "check")
(setq face 'ledger-font-check-directive-face))
((looking-at "commodity")
(setq face 'ledger-font-commodity-directive-face))
((looking-at "define")
(setq face 'ledger-font-define-directive-face))
((looking-at "end")
(setq face 'ledger-font-end-directive-face))
((looking-at "expr")
(setq face 'ledger-font-expr-directive-face))
((looking-at "fixed")
(setq face 'ledger-font-fixed-directive-face))
((looking-at "include")
(setq face 'ledger-font-include-directive-face))
((looking-at "payee")
(setq face 'ledger-font-payee-directive-face))
((looking-at "P")
(setq face 'ledger-font-price-directive-face))
((looking-at "tag")
(setq face 'ledger-font-tag-directive-face)))
(ledger-fontify-set-face extents face)))
"Fontify the directive at POS."
(let ((extents (ledger-navigate-find-element-extents pos))
(face 'ledger-font-default-face))
(cond ((looking-at "=")
(setq face 'ledger-font-auto-xact-face))
((looking-at "~")
(setq face 'ledger-font-periodic-xact-face))
((looking-at "[;#%|\\*]")
(setq face 'ledger-font-comment-face))
((looking-at "\\(year\\)\\|Y")
(setq face 'ledger-font-year-directive-face))
((looking-at "account")
(setq face 'ledger-font-account-directive-face))
((looking-at "apply")
(setq face 'ledger-font-apply-directive-face))
((looking-at "alias")
(setq face 'ledger-font-alias-directive-face))
((looking-at "assert")
(setq face 'ledger-font-assert-directive-face))
((looking-at "\\(bucket\\)\\|A")
(setq face 'ledger-font-bucket-directive-face))
((looking-at "capture")
(setq face 'ledger-font-capture-directive-face))
((looking-at "check")
(setq face 'ledger-font-check-directive-face))
((looking-at "commodity")
(setq face 'ledger-font-commodity-directive-face))
((looking-at "define")
(setq face 'ledger-font-define-directive-face))
((looking-at "end")
(setq face 'ledger-font-end-directive-face))
((looking-at "expr")
(setq face 'ledger-font-expr-directive-face))
((looking-at "fixed")
(setq face 'ledger-font-fixed-directive-face))
((looking-at "include")
(setq face 'ledger-font-include-directive-face))
((looking-at "payee")
(setq face 'ledger-font-payee-directive-face))
((looking-at "P")
(setq face 'ledger-font-price-directive-face))
((looking-at "tag")
(setq face 'ledger-font-tag-directive-face)))
(ledger-fontify-set-face extents face)))
(defun ledger-fontify-set-face (extents face)
"Set the text in EXTENTS to FACE."
(put-text-property (car extents) (cadr extents) 'face face))
"Set the text in EXTENTS to FACE."
(put-text-property (car extents) (cadr extents) 'face face))
(provide 'ledger-fontify)

View file

@ -35,7 +35,7 @@
(defvar ledger-default-date-format "%Y/%m/%d")
(defun ledger-init-parse-initialization (buffer)
"Parse the .ledgerrc file in BUFFER."
"Parse the .ledgerrc file in BUFFER."
(with-current-buffer buffer
(let (environment-alist)
(goto-char (point-min))
@ -56,7 +56,7 @@
environment-alist)))
(defun ledger-init-load-init-file ()
"Load and parse the .ledgerrc file."
"Load and parse the .ledgerrc file."
(interactive)
(let ((init-base-name (file-name-nondirectory ledger-init-file-name)))
(if (get-buffer init-base-name) ;; init file already loaded, parse it and leave it

View file

@ -63,7 +63,7 @@
(defun ledger-mode-dump-variable (var)
"Format VAR for dump to buffer."
(if var
(if var
(insert (format " %s: %S\n" (symbol-name var) (eval var)))))
(defun ledger-mode-dump-group (group)
@ -78,7 +78,7 @@
(defun ledger-mode-dump-configuration ()
"Dump all customizations."
(interactive)
(interactive)
(find-file "ledger-mode-dump")
(ledger-mode-dump-group 'ledger))
@ -99,11 +99,11 @@
(defun ledger-read-account-with-prompt (prompt)
"Read an account from the minibuffer with PROMPT."
(let ((context (ledger-context-at-point)))
(let ((context (ledger-context-at-point)))
(ledger-read-string-with-default prompt
(if (eq (ledger-context-current-field context) 'account)
(regexp-quote (ledger-context-field-value context 'account))
nil))))
(if (eq (ledger-context-current-field context) 'account)
(regexp-quote (ledger-context-field-value context 'account))
nil))))
(defun ledger-read-date (prompt)
"Return user-supplied date after `PROMPT', defaults to today."
@ -222,7 +222,7 @@ With a prefix argument, remove the effective date."
(defun ledger-mode-remove-extra-lines ()
"Get rid of multiple empty lines."
(goto-char (point-min))
(goto-char (point-min))
(while (re-search-forward "\n\n\\(\n\\)+" nil t)
(replace-match "\n\n")))
@ -338,10 +338,10 @@ With a prefix argument, remove the effective date."
'(ledger-font-lock-keywords t t nil nil
(font-lock-fontify-region-function . ledger-fontify-buffer-part))))
(set (make-local-variable 'pcomplete-parse-arguments-function) 'ledger-parse-arguments)
(set (make-local-variable 'pcomplete-command-completion-function) 'ledger-complete-at-point)
(set (make-local-variable 'pcomplete-parse-arguments-function) 'ledger-parse-arguments)
(set (make-local-variable 'pcomplete-command-completion-function) 'ledger-complete-at-point)
(add-hook 'completion-at-point-functions 'pcomplete-completions-at-point nil t)
(add-hook 'after-save-hook 'ledger-report-redo)
(add-hook 'after-save-hook 'ledger-report-redo)
(add-hook 'post-command-hook 'ledger-highlight-xact-under-point nil t)

View file

@ -39,49 +39,49 @@
(goto-char (point-max))))
(defun ledger-navigate-start-xact-or-directive-p ()
"Return t if at the beginning of an empty or all-whitespace line."
(not (looking-at "[ \t]\\|\\(^$\\)")))
"Return t if at the beginning of an empty or all-whitespace line."
(not (looking-at "[ \t]\\|\\(^$\\)")))
(defun ledger-navigate-next-xact-or-directive ()
"Move to the beginning of the next xact or directive."
(interactive)
(beginning-of-line)
(if (ledger-navigate-start-xact-or-directive-p) ; if we are the start of an xact, move forward to the next xact
(progn
(forward-line)
(if (not (ledger-navigate-start-xact-or-directive-p)) ; we have moved forward and are not at another xact, recurse forward
(ledger-navigate-next-xact-or-directive)))
(while (not (or (eobp) ; we didn't start off at the beginning of an xact
(ledger-navigate-start-xact-or-directive-p)))
(forward-line))))
"Move to the beginning of the next xact or directive."
(interactive)
(beginning-of-line)
(if (ledger-navigate-start-xact-or-directive-p) ; if we are the start of an xact, move forward to the next xact
(progn
(forward-line)
(if (not (ledger-navigate-start-xact-or-directive-p)) ; we have moved forward and are not at another xact, recurse forward
(ledger-navigate-next-xact-or-directive)))
(while (not (or (eobp) ; we didn't start off at the beginning of an xact
(ledger-navigate-start-xact-or-directive-p)))
(forward-line))))
(defun ledger-navigate-prev-xact-or-directive ()
"Move point to beginning of previous xact."
(interactive)
(let ((context (car (ledger-context-at-point))))
(when (equal context 'acct-transaction)
(ledger-navigate-beginning-of-xact))
(beginning-of-line)
(re-search-backward "^[[:graph:]]" nil t)))
(interactive)
(let ((context (car (ledger-context-at-point))))
(when (equal context 'acct-transaction)
(ledger-navigate-beginning-of-xact))
(beginning-of-line)
(re-search-backward "^[[:graph:]]" nil t)))
(defun ledger-navigate-beginning-of-xact ()
"Move point to the beginning of the current xact."
(interactive)
;; need to start at the beginning of a line incase we are in the first line of an xact already.
(beginning-of-line)
(let ((sreg (concat "^\\(=\\|~\\|" ledger-iso-date-regexp "\\)")))
(unless (looking-at sreg)
(re-search-backward sreg nil t)
(beginning-of-line)))
(point))
"Move point to the beginning of the current xact."
(interactive)
;; need to start at the beginning of a line incase we are in the first line of an xact already.
(beginning-of-line)
(let ((sreg (concat "^\\(=\\|~\\|" ledger-iso-date-regexp "\\)")))
(unless (looking-at sreg)
(re-search-backward sreg nil t)
(beginning-of-line)))
(point))
(defun ledger-navigate-end-of-xact ()
"Move point to end of xact."
(interactive)
(interactive)
(ledger-navigate-next-xact-or-directive)
(re-search-backward ".$")
(end-of-line)
(point))
(re-search-backward ".$")
(end-of-line)
(point))
(defun ledger-navigate-to-line (line-number)
"Rapidly move point to line LINE-NUMBER."
@ -95,61 +95,61 @@ Requires empty line separating xacts."
(save-excursion
(goto-char pos)
(list (ledger-navigate-beginning-of-xact)
(ledger-navigate-end-of-xact))))
(ledger-navigate-end-of-xact))))
(defun ledger-navigate-find-directive-extents (pos)
"Return the extents of the directive at POS."
(goto-char pos)
(let ((begin (progn (beginning-of-line)
(point)))
(end (progn (end-of-line)
(+ 1 (point)))))
;; handle block comments here
(beginning-of-line)
(if (looking-at " *;")
(progn
(while (and (looking-at " *;")
(> (point) (point-min)))
(forward-line -1))
;; We are either at the beginning of the buffer, or we found
;; a line outside the comment. If we are not at the
;; beginning of the buffer then we need to move forward a
;; line.
(if (> (point) (point-min))
(progn (forward-line 1)
(beginning-of-line)))
(setq begin (point))
(goto-char pos)
(beginning-of-line)
(while (and (looking-at " *;")
(< (point) (point-max)))
(forward-line 1))
(setq end (point))))
(list begin end)))
(goto-char pos)
(let ((begin (progn (beginning-of-line)
(point)))
(end (progn (end-of-line)
(+ 1 (point)))))
;; handle block comments here
(beginning-of-line)
(if (looking-at " *;")
(progn
(while (and (looking-at " *;")
(> (point) (point-min)))
(forward-line -1))
;; We are either at the beginning of the buffer, or we found
;; a line outside the comment. If we are not at the
;; beginning of the buffer then we need to move forward a
;; line.
(if (> (point) (point-min))
(progn (forward-line 1)
(beginning-of-line)))
(setq begin (point))
(goto-char pos)
(beginning-of-line)
(while (and (looking-at " *;")
(< (point) (point-max)))
(forward-line 1))
(setq end (point))))
(list begin end)))
(defun ledger-navigate-block-comment (pos)
"Move past the block comment at POS, and return its extents."
(interactive "d")
(goto-char pos)
(let ((begin (progn (beginning-of-line)
(point)))
(end (progn (end-of-line)
(point))))
;; handle block comments here
(beginning-of-line)
(if (looking-at " *;")
(progn
(while (and (looking-at " *;")
(> (point) (point-min)))
(forward-line -1))
(setq begin (point))
(goto-char pos)
(beginning-of-line)
(while (and (looking-at " *;")
(< (point) (point-max)))
(forward-line 1))
(setq end (point))))
(list begin end)))
(interactive "d")
(goto-char pos)
(let ((begin (progn (beginning-of-line)
(point)))
(end (progn (end-of-line)
(point))))
;; handle block comments here
(beginning-of-line)
(if (looking-at " *;")
(progn
(while (and (looking-at " *;")
(> (point) (point-min)))
(forward-line -1))
(setq begin (point))
(goto-char pos)
(beginning-of-line)
(while (and (looking-at " *;")
(< (point) (point-max)))
(forward-line 1))
(setq end (point))))
(list begin end)))
(defun ledger-navigate-find-element-extents (pos)

View file

@ -118,7 +118,7 @@ currently active."
Argument OVL-BOUNDS contains bounds for the transactions to be left visible."
(let* ((beg (caar ovl-bounds))
(end (cadar ovl-bounds)))
(ledger-occur-remove-overlays)
(ledger-occur-remove-overlays)
(ledger-occur-make-invisible-overlay (point-min) (1- beg))
(dolist (visible (cdr ovl-bounds))
(ledger-occur-make-visible-overlay beg end)
@ -143,25 +143,25 @@ Argument OVL-BOUNDS contains bounds for the transactions to be left visible."
(while (not (eobp))
;; if something found
(when (setq endpoint (re-search-forward regex nil 'end))
(setq bounds (ledger-navigate-find-element-extents endpoint))
(push bounds lines)
;; move to the end of the xact, no need to search inside it more
(setq bounds (ledger-navigate-find-element-extents endpoint))
(push bounds lines)
;; move to the end of the xact, no need to search inside it more
(goto-char (cadr bounds))))
(nreverse lines))))
(defun ledger-occur-compress-matches (buffer-matches)
"identify sequential xacts to reduce number of overlays required"
(if buffer-matches
(let ((points (list))
(current-beginning (caar buffer-matches))
(current-end (cadar buffer-matches)))
(dolist (match (cdr buffer-matches))
(if (< (- (car match) current-end) 2)
(setq current-end (cadr match))
(push (list current-beginning current-end) points)
(setq current-beginning (car match))
(setq current-end (cadr match))))
(nreverse (push (list current-beginning current-end) points)))))
(if buffer-matches
(let ((points (list))
(current-beginning (caar buffer-matches))
(current-end (cadar buffer-matches)))
(dolist (match (cdr buffer-matches))
(if (< (- (car match) current-end) 2)
(setq current-end (cadr match))
(push (list current-beginning current-end) points)
(setq current-beginning (car match))
(setq current-end (cadr match))))
(nreverse (push (list current-beginning current-end) points)))))
(provide 'ledger-occur)

View file

@ -95,8 +95,8 @@ at beginning of account"
(current-column))))
(defun ledger-post-align-xact (pos)
"Align all the posting in the xact at POS."
(interactive "d")
"Align all the posting in the xact at POS."
(interactive "d")
(let ((bounds (ledger-navigate-find-xact-extents pos)))
(ledger-post-align-postings (car bounds) (cadr bounds))))

View file

@ -77,7 +77,7 @@ Default is ledger-default-date-format."
:group 'ledger-reconcile)
(defcustom ledger-reconcile-buffer-header "Reconciling account %s\n\n"
"Default header string for the reconcile buffer.
"Default header string for the reconcile buffer.
If non-nil, the name of the account being reconciled will be substituted
into the '%s'. If nil, no header will be displayed."
@ -85,7 +85,7 @@ If non-nil, the name of the account being reconciled will be substituted
:group 'ledger-reconcile)
(defcustom ledger-reconcile-buffer-line-format "%(date)s %-4(code)s %-50(payee)s %-30(account)s %15(amount)s\n"
"Format string for the ledger reconcile posting format.
"Format string for the ledger reconcile posting format.
Available fields are date, status, code, payee, account,
amount. The format for each field is %WIDTH(FIELD), WIDTH can be
preced by a minus sign which mean to left justify and pad the
@ -124,12 +124,12 @@ Possible values are '(date)', '(amount)', '(payee)' or '(0)' for no sorting, i.e
"If S is shorter than LEN, pad it with PADDING on the left."
(let ((extra (max 0 (- len (length s)))))
(concat (make-string extra (string-to-char padding))
s)))
s)))
(defun ledger-reconcile-s-pad-right (len padding s)
"If S is shorter than LEN, pad it with PADDING on the right."
(let ((extra (max 0 (- len (length s)))))
(concat s
(make-string extra (string-to-char padding)))))
(make-string extra (string-to-char padding)))))
(defun ledger-reconcile-s-left (len s)
"Return up to the LEN first chars of S."
(if (> (length s) len)
@ -139,7 +139,7 @@ Possible values are '(date)', '(amount)', '(payee)' or '(0)' for no sorting, i.e
"Return up to the LEN last chars of S."
(let ((l (length s)))
(if (> l len)
(substring s (- l len) l)
(substring s (- l len) l)
s)))
(defun ledger-reconcile-truncate-right (str len)
@ -253,9 +253,9 @@ Return the number of uncleared xacts found."
(with-current-buffer recon-buf
(ledger-reconcile-refresh)
(set-buffer-modified-p nil))
(when curbufwin
(select-window curbufwin)
(goto-char curpoint)))))
(when curbufwin
(select-window curbufwin)
(goto-char curpoint)))))
(defun ledger-reconcile-add ()
"Use ledger xact to add a new transaction."
@ -281,34 +281,34 @@ Return the number of uncleared xacts found."
(defun ledger-reconcile-visit (&optional come-back)
"Recenter ledger buffer on transaction and COME-BACK if non-nil."
(interactive)
(beginning-of-line)
(let* ((where (get-text-property (1+ (point)) 'where))
(target-buffer (if where
(ledger-reconcile-get-buffer where)
nil))
(cur-win (get-buffer-window (get-buffer ledger-recon-buffer-name))))
(when target-buffer
(switch-to-buffer-other-window target-buffer)
(ledger-navigate-to-line (cdr where))
(forward-char)
(recenter)
(ledger-highlight-xact-under-point)
(forward-char -1)
(when (and come-back cur-win)
(select-window cur-win)
(get-buffer ledger-recon-buffer-name)))))
(beginning-of-line)
(let* ((where (get-text-property (1+ (point)) 'where))
(target-buffer (if where
(ledger-reconcile-get-buffer where)
nil))
(cur-win (get-buffer-window (get-buffer ledger-recon-buffer-name))))
(when target-buffer
(switch-to-buffer-other-window target-buffer)
(ledger-navigate-to-line (cdr where))
(forward-char)
(recenter)
(ledger-highlight-xact-under-point)
(forward-char -1)
(when (and come-back cur-win)
(select-window cur-win)
(get-buffer ledger-recon-buffer-name)))))
(defun ledger-reconcile-save ()
"Save the ledger buffer."
(interactive)
(let ((cur-buf (current-buffer))
(cur-point (point)))
(dolist (buf (cons ledger-buf ledger-bufs))
(with-current-buffer buf
(basic-save-buffer)))
(switch-to-buffer-other-window cur-buf)
(goto-char cur-point)))
(let ((cur-buf (current-buffer))
(cur-point (point)))
(dolist (buf (cons ledger-buf ledger-bufs))
(with-current-buffer buf
(basic-save-buffer)))
(switch-to-buffer-other-window cur-buf)
(goto-char cur-point)))
(defun ledger-reconcile-finish ()
@ -369,55 +369,55 @@ POSTING is used in `ledger-clear-whole-transactions' is nil."
(nth 0 posting))))) ;; return line-no of posting
(defun ledger-reconcile-compile-format-string (fstr)
"Return a function that implements the format string in FSTR."
(let (fields
(start 0))
(while (string-match "(\\(.*?\\))" fstr start)
(setq fields (cons (intern (match-string 1 fstr)) fields))
(setq start (match-end 0)))
(setq fields (list* 'format (replace-regexp-in-string "(.*?)" "" fstr) (nreverse fields)))
`(lambda (date code status payee account amount)
,fields)))
"Return a function that implements the format string in FSTR."
(let (fields
(start 0))
(while (string-match "(\\(.*?\\))" fstr start)
(setq fields (cons (intern (match-string 1 fstr)) fields))
(setq start (match-end 0)))
(setq fields (list* 'format (replace-regexp-in-string "(.*?)" "" fstr) (nreverse fields)))
`(lambda (date code status payee account amount)
,fields)))
(defun ledger-reconcile-format-posting (beg where fmt date code status payee account amount)
"Format posting for the reconcile buffer."
(insert (funcall fmt date code status payee account amount))
"Format posting for the reconcile buffer."
(insert (funcall fmt date code status payee account amount))
; Set face depending on cleared status
(if status
(if (eq status 'pending)
(set-text-properties beg (1- (point))
(list 'face 'ledger-font-reconciler-pending-face
'where where))
(set-text-properties beg (1- (point))
(list 'face 'ledger-font-reconciler-cleared-face
'where where)))
(set-text-properties beg (1- (point))
(list 'face 'ledger-font-reconciler-uncleared-face
'where where))))
; Set face depending on cleared status
(if status
(if (eq status 'pending)
(set-text-properties beg (1- (point))
(list 'face 'ledger-font-reconciler-pending-face
'where where))
(set-text-properties beg (1- (point))
(list 'face 'ledger-font-reconciler-cleared-face
'where where)))
(set-text-properties beg (1- (point))
(list 'face 'ledger-font-reconciler-uncleared-face
'where where))))
(defun ledger-reconcile-format-xact (xact fmt)
"Format XACT using FMT."
(let ((date-format (or (cdr (assoc "date-format" ledger-environment-alist))
ledger-default-date-format)))
(dolist (posting (nthcdr 5 xact))
(let ((beg (point))
(where (ledger-marker-where-xact-is xact posting)))
(ledger-reconcile-format-posting beg
where
fmt
(format-time-string date-format (nth 2 xact)) ; date
(if (nth 3 xact) (nth 3 xact) "") ; code
(nth 3 posting) ; status
"Format XACT using FMT."
(let ((date-format (or (cdr (assoc "date-format" ledger-environment-alist))
ledger-default-date-format)))
(dolist (posting (nthcdr 5 xact))
(let ((beg (point))
(where (ledger-marker-where-xact-is xact posting)))
(ledger-reconcile-format-posting beg
where
fmt
(format-time-string date-format (nth 2 xact)) ; date
(if (nth 3 xact) (nth 3 xact) "") ; code
(nth 3 posting) ; status
(ledger-reconcile-truncate-right
(nth 4 xact) ; payee
ledger-reconcile-buffer-payee-max-chars)
(nth 4 xact) ; payee
ledger-reconcile-buffer-payee-max-chars)
(ledger-reconcile-truncate-left
(nth 1 posting) ; account
ledger-reconcile-buffer-account-max-chars)
(nth 2 posting)))))) ; amount
(nth 1 posting) ; account
ledger-reconcile-buffer-account-max-chars)
(nth 2 posting)))))) ; amount
(defun ledger-do-reconcile (&optional sort)
"SORT the uncleared transactions in the account and display them in the *Reconcile* buffer.
@ -437,7 +437,7 @@ Return a count of the uncleared transactions."
(unless (eobp)
(if (looking-at "(")
(read (current-buffer))))))) ;current-buffer is the *temp* created above
(fmt (ledger-reconcile-compile-format-string ledger-reconcile-buffer-line-format)))
(fmt (ledger-reconcile-compile-format-string ledger-reconcile-buffer-line-format)))
(if (and ledger-success (> (length xacts) 0))
(progn
(if ledger-reconcile-buffer-header
@ -494,11 +494,11 @@ moved and recentered. If they aren't strange things happen."
(pop-to-buffer rbuf)))
(defun ledger-reconcile-check-valid-account (account)
"Check to see if ACCOUNT exists in the ledger file"
(if (> (length account) 0)
(save-excursion
(goto-char (point-min))
(search-forward account nil t))))
"Check to see if ACCOUNT exists in the ledger file"
(if (> (length account) 0)
(save-excursion
(goto-char (point-min))
(search-forward account nil t))))
(defun ledger-reconcile ()
"Start reconciling, prompt for account."
@ -507,38 +507,38 @@ moved and recentered. If they aren't strange things happen."
(buf (current-buffer))
(rbuf (get-buffer ledger-recon-buffer-name)))
(when (ledger-reconcile-check-valid-account account)
(add-hook 'after-save-hook 'ledger-reconcile-refresh-after-save nil t)
(when (ledger-reconcile-check-valid-account account)
(add-hook 'after-save-hook 'ledger-reconcile-refresh-after-save nil t)
(if rbuf ;; *Reconcile* already exists
(with-current-buffer rbuf
(set 'ledger-acct account) ;; already buffer local
(when (not (eq buf rbuf))
;; called from some other ledger-mode buffer
(ledger-reconcile-quit-cleanup)
(setq ledger-buf buf)) ;; should already be buffer-local
(if rbuf ;; *Reconcile* already exists
(with-current-buffer rbuf
(set 'ledger-acct account) ;; already buffer local
(when (not (eq buf rbuf))
;; called from some other ledger-mode buffer
(ledger-reconcile-quit-cleanup)
(setq ledger-buf buf)) ;; should already be buffer-local
(unless (get-buffer-window rbuf)
(ledger-reconcile-open-windows buf rbuf)))
(unless (get-buffer-window rbuf)
(ledger-reconcile-open-windows buf rbuf)))
;; no recon-buffer, starting from scratch.
;; no recon-buffer, starting from scratch.
(with-current-buffer (setq rbuf
(get-buffer-create ledger-recon-buffer-name))
(ledger-reconcile-open-windows buf rbuf)
(ledger-reconcile-mode)
(make-local-variable 'ledger-target)
(set (make-local-variable 'ledger-buf) buf)
(set (make-local-variable 'ledger-acct) account)))
(with-current-buffer (setq rbuf
(get-buffer-create ledger-recon-buffer-name))
(ledger-reconcile-open-windows buf rbuf)
(ledger-reconcile-mode)
(make-local-variable 'ledger-target)
(set (make-local-variable 'ledger-buf) buf)
(set (make-local-variable 'ledger-acct) account)))
;; Narrow the ledger buffer
(with-current-buffer rbuf
(save-excursion
(if ledger-narrow-on-reconcile
(ledger-occur account)))
(if (> (ledger-reconcile-refresh) 0)
(ledger-reconcile-change-target))
(ledger-display-balance)))))
;; Narrow the ledger buffer
(with-current-buffer rbuf
(save-excursion
(if ledger-narrow-on-reconcile
(ledger-occur account)))
(if (> (ledger-reconcile-refresh) 0)
(ledger-reconcile-change-target))
(ledger-display-balance)))))
(defvar ledger-reconcile-mode-abbrev-table)
@ -549,7 +549,7 @@ moved and recentered. If they aren't strange things happen."
(defmacro ledger-reconcile-change-sort-key-and-refresh (sort-by)
"Set the sort-key to SORT-BY."
`(lambda ()
`(lambda ()
(interactive)
(setq ledger-reconcile-sort-key ,sort-by)

View file

@ -108,8 +108,8 @@
defs
(list
`(defmacro
,(intern (concat "ledger-regex-" (symbol-name name)))
(&optional string)
,(intern (concat "ledger-regex-" (symbol-name name)))
(&optional string)
,(format "Return the match string for the %s" name)
(match-string
,(intern (concat "ledger-regex-" (symbol-name name)
@ -153,9 +153,9 @@
defs
(list
`(defmacro
,(intern (concat "ledger-regex-" (symbol-name name)
"-" (symbol-name var)))
(&optional string)
,(intern (concat "ledger-regex-" (symbol-name name)
"-" (symbol-name var)))
(&optional string)
,(format "Return the sub-group match for the %s %s."
name var)
(match-string
@ -333,8 +333,8 @@
"\\)"))
(defconst ledger-xact-start-regex
(concat "^" ledger-iso-date-regexp ;; subexp 1
"\\(=" ledger-iso-date-regexp "\\)?"
(concat "^" ledger-iso-date-regexp ;; subexp 1
"\\(=" ledger-iso-date-regexp "\\)?"
))
(defconst ledger-xact-after-date-regex
@ -345,17 +345,17 @@
))
(defconst ledger-posting-regex
(concat "^[ \t]+ ?" ;; initial white space
"\\([*!]\\)? ?" ;; state, subexpr 1
"\\([[:print:]]+\\([ \t][ \t]\\)\\)" ;; account, subexpr 2
"\\([^;\n]*\\)" ;; amount, subexpr 4
"\\(.*\\)" ;; comment, subexpr 5
))
(concat "^[ \t]+ ?" ;; initial white space
"\\([*!]\\)? ?" ;; state, subexpr 1
"\\([[:print:]]+\\([ \t][ \t]\\)\\)" ;; account, subexpr 2
"\\([^;\n]*\\)" ;; amount, subexpr 4
"\\(.*\\)" ;; comment, subexpr 5
))
(defconst ledger-directive-start-regex
"[=~;#%|\\*[A-Za-z]")
"[=~;#%|\\*[A-Za-z]")
(provide 'ledger-regex)

View file

@ -57,7 +57,7 @@ specifier."
'(("ledger-file" . ledger-report-ledger-file-format-specifier)
("payee" . ledger-report-payee-format-specifier)
("account" . ledger-report-account-format-specifier)
("tagname" . ledger-report-tagname-format-specifier)
("tagname" . ledger-report-tagname-format-specifier)
("tagvalue" . ledger-report-tagvalue-format-specifier))
"An alist mapping ledger report format specifiers to implementing functions.
@ -67,14 +67,14 @@ text that should replace the format specifier."
:group 'ledger-report)
(defcustom ledger-report-auto-refresh t
"If t then automatically rerun the report when the ledger buffer is saved."
:type 'boolean
:group 'ledger-report)
"If t then automatically rerun the report when the ledger buffer is saved."
:type 'boolean
:group 'ledger-report)
(defcustom ledger-report-auto-refresh-sticky-cursor nil
"If t then try to place cursor at same relative position as it was before auto-refresh."
:type 'boolean
:group 'ledger-report)
"If t then try to place cursor at same relative position as it was before auto-refresh."
:type 'boolean
:group 'ledger-report)
(defvar ledger-report-buffer-name "*Ledger Report*")
@ -91,10 +91,10 @@ text that should replace the format specifier."
(defvar ledger-report-cursor-line-number nil)
(defun ledger-report-reverse-report ()
"Reverse the order of the report."
(interactive)
(ledger-report-reverse-lines)
(setq ledger-report-is-reversed (not ledger-report-is-reversed)))
"Reverse the order of the report."
(interactive)
(ledger-report-reverse-lines)
(setq ledger-report-is-reversed (not ledger-report-is-reversed)))
(defun ledger-report-reverse-lines ()
(goto-char (point-min))
@ -203,7 +203,7 @@ used to generate the buffer, navigating the buffer, etc."
(set (make-local-variable 'ledger-buf) buf)
(set (make-local-variable 'ledger-report-name) report-name)
(set (make-local-variable 'ledger-original-window-cfg) wcfg)
(set (make-local-variable 'ledger-report-is-reversed) nil)
(set (make-local-variable 'ledger-report-is-reversed) nil)
(ledger-do-report (ledger-report-cmd report-name edit))
(shrink-window-if-larger-than-buffer)
(set-buffer-modified-p nil)
@ -387,30 +387,30 @@ Optional EDIT the command."
(defun ledger-report-redo ()
"Redo the report in the current ledger report buffer."
(interactive)
(let ((cur-buf (current-buffer)))
(if (and ledger-report-auto-refresh
(or (string= (format-mode-line 'mode-name) "Ledger")
(string= (format-mode-line 'mode-name) "Ledger-Report"))
(get-buffer ledger-report-buffer-name))
(progn
(let ((cur-buf (current-buffer)))
(if (and ledger-report-auto-refresh
(or (string= (format-mode-line 'mode-name) "Ledger")
(string= (format-mode-line 'mode-name) "Ledger-Report"))
(get-buffer ledger-report-buffer-name))
(progn
(pop-to-buffer (get-buffer ledger-report-buffer-name))
(shrink-window-if-larger-than-buffer)
(setq buffer-read-only nil)
(setq ledger-report-cursor-line-number (line-number-at-pos))
(erase-buffer)
(ledger-do-report ledger-report-cmd)
(setq buffer-read-only nil)
(if ledger-report-is-reversed (ledger-report-reverse-lines))
(if ledger-report-auto-refresh-sticky-cursor (forward-line (- ledger-report-cursor-line-number 5)))
(pop-to-buffer cur-buf)))))
(pop-to-buffer (get-buffer ledger-report-buffer-name))
(shrink-window-if-larger-than-buffer)
(setq buffer-read-only nil)
(setq ledger-report-cursor-line-number (line-number-at-pos))
(erase-buffer)
(ledger-do-report ledger-report-cmd)
(setq buffer-read-only nil)
(if ledger-report-is-reversed (ledger-report-reverse-lines))
(if ledger-report-auto-refresh-sticky-cursor (forward-line (- ledger-report-cursor-line-number 5)))
(pop-to-buffer cur-buf)))))
(defun ledger-report-quit ()
"Quit the ledger report buffer."
(interactive)
(ledger-report-goto)
(set-window-configuration ledger-original-window-cfg)
(kill-buffer (get-buffer ledger-report-buffer-name)))
"Quit the ledger report buffer."
(interactive)
(ledger-report-goto)
(set-window-configuration ledger-original-window-cfg)
(kill-buffer (get-buffer ledger-report-buffer-name)))
(defun ledger-report-edit-reports ()
"Edit the defined ledger reports."
@ -418,10 +418,10 @@ Optional EDIT the command."
(customize-variable 'ledger-reports))
(defun ledger-report-edit-report ()
(interactive)
"Edit the current report command in the mini buffer and re-run the report"
(setq ledger-report-cmd (ledger-report-read-command ledger-report-cmd))
(ledger-report-redo))
(interactive)
"Edit the current report command in the mini buffer and re-run the report"
(setq ledger-report-cmd (ledger-report-read-command ledger-report-cmd))
(ledger-report-redo))
(defun ledger-report-read-new-name ()
"Read the name for a new report from the minibuffer."

View file

@ -60,21 +60,21 @@
:group 'ledger-schedule)
(defcustom ledger-schedule-week-days '(("Mo" 1)
("Tu" 2)
("We" 3)
("Th" 4)
("Fr" 5)
("Sa" 6)
("Su" 7))
"List of weekday abbreviations. There must be exactly seven
("Tu" 2)
("We" 3)
("Th" 4)
("Fr" 5)
("Sa" 6)
("Su" 7))
"List of weekday abbreviations. There must be exactly seven
entries each with a two character abbreviation for a day and the
number of that day in the week. "
:type '(alist :value-type (group integer))
:group 'ledger-schedule)
:type '(alist :value-type (group integer))
:group 'ledger-schedule)
(defsubst between (val low high)
"Return TRUE if VAL > LOW and < HIGH."
(and (>= val low) (<= val high)))
"Return TRUE if VAL > LOW and < HIGH."
(and (>= val low) (<= val high)))
(defun ledger-schedule-days-in-month (month year)
"Return number of days in the MONTH, MONTH is from 1 to 12.
@ -86,8 +86,8 @@ If YEAR is nil, assume it is not a leap year"
(error "Month out of range, MONTH=%S" month)))
(defun ledger-schedule-encode-day-of-week (day-string)
"Return the numerical day of week corresponding to DAY-STRING."
(cadr (assoc day-string ledger-schedule-week-days)))
"Return the numerical day of week corresponding to DAY-STRING."
(cadr (assoc day-string ledger-schedule-week-days)))
;; Macros to handle date expressions
@ -173,10 +173,10 @@ the transaction should be logged for that day."
xact-list)))
(defun ledger-schedule-read-descriptor-tree (descriptor-string)
"Read DESCRIPTOR-STRING and return a form that evaluates dates."
(ledger-schedule-transform-auto-tree
(split-string
(substring descriptor-string 1 (string-match "]" descriptor-string)) " ")))
"Read DESCRIPTOR-STRING and return a form that evaluates dates."
(ledger-schedule-transform-auto-tree
(split-string
(substring descriptor-string 1 (string-match "]" descriptor-string)) " ")))
(defun ledger-schedule-transform-auto-tree (descriptor-string-list)
"Take DESCRIPTOR-STRING-LIST, and return a string with a lambda function of date."
@ -202,84 +202,84 @@ the transaction should be logged for that day."
(defun ledger-schedule-compile-constraints (descriptor-string)
"Return a list with the year, month and day fields split."
(let ((fields (split-string descriptor-string "[/\\-]" t)))
(if (string-match "[A-Za-z]" descriptor-string)
(ledger-schedule-constrain-day (nth 0 fields) (nth 1 fields) (nth 2 fields))
(list 'and
(ledger-schedule-constrain-day (nth 0 fields) (nth 1 fields) (nth 2 fields))
(ledger-schedule-constrain-year (nth 0 fields) (nth 1 fields) (nth 2 fields))
(ledger-schedule-constrain-month (nth 0 fields) (nth 1 fields) (nth 2 fields))))))
(if (string-match "[A-Za-z]" descriptor-string)
(ledger-schedule-constrain-day (nth 0 fields) (nth 1 fields) (nth 2 fields))
(list 'and
(ledger-schedule-constrain-day (nth 0 fields) (nth 1 fields) (nth 2 fields))
(ledger-schedule-constrain-year (nth 0 fields) (nth 1 fields) (nth 2 fields))
(ledger-schedule-constrain-month (nth 0 fields) (nth 1 fields) (nth 2 fields))))))
(defun ledger-schedule-constrain-year (year-desc month-desc day-desc)
"Return a form that constrains the year.
"Return a form that constrains the year.
YEAR-DESC, MONT-DESC, and DAY-DESC are the string portions of the
date descriptor."
(cond ((string= year-desc "*") t)
((/= 0 (string-to-number year-desc))
`(memq (nth 5 (decode-time date)) ',(mapcar 'string-to-number (split-string year-desc ","))))
(t
(error "Improperly specified year constraint: %s %s %s" year-desc month-desc day-desc))))
(cond ((string= year-desc "*") t)
((/= 0 (string-to-number year-desc))
`(memq (nth 5 (decode-time date)) ',(mapcar 'string-to-number (split-string year-desc ","))))
(t
(error "Improperly specified year constraint: %s %s %s" year-desc month-desc day-desc))))
(defun ledger-schedule-constrain-month (year-desc month-desc day-desc)
"Return a form that constrains the month.
"Return a form that constrains the month.
YEAR-DESC, MONT-DESC, and DAY-DESC are the string portions of the
date descriptor."
(cond ((string= month-desc "*")
t) ;; always match
((string= month-desc "E") ;; Even
`(evenp (nth 4 (decode-time date))))
((string= month-desc "O") ;; Odd
`(oddp (nth 4 (decode-time date))))
((/= 0 (string-to-number month-desc)) ;; Starts with number
`(memq (nth 4 (decode-time date)) ',(mapcar 'string-to-number (split-string month-desc ","))))
(t
(error "Improperly specified month constraint: %s %s %s" year-desc month-desc day-desc))))
(cond ((string= month-desc "*")
t) ;; always match
((string= month-desc "E") ;; Even
`(evenp (nth 4 (decode-time date))))
((string= month-desc "O") ;; Odd
`(oddp (nth 4 (decode-time date))))
((/= 0 (string-to-number month-desc)) ;; Starts with number
`(memq (nth 4 (decode-time date)) ',(mapcar 'string-to-number (split-string month-desc ","))))
(t
(error "Improperly specified month constraint: %s %s %s" year-desc month-desc day-desc))))
(defun ledger-schedule-constrain-day (year-desc month-desc day-desc)
"Return a form that constrains the day.
"Return a form that constrains the day.
YEAR-DESC, MONT-DESC, and DAY-DESC are the string portions of the
date descriptor."
(cond ((string= day-desc "*")
t)
((string-match "[A-Za-z]" day-desc) ;; There is something other than digits and commas
(ledger-schedule-parse-complex-date year-desc month-desc day-desc))
((/= 0 (string-to-number day-desc))
`(memq (nth 3 (decode-time date)) ',(mapcar 'string-to-number (split-string day-desc ","))))
(t
(error "Improperly specified day constraint: %s %s %s" year-desc month-desc day-desc))))
(cond ((string= day-desc "*")
t)
((string-match "[A-Za-z]" day-desc) ;; There is something other than digits and commas
(ledger-schedule-parse-complex-date year-desc month-desc day-desc))
((/= 0 (string-to-number day-desc))
`(memq (nth 3 (decode-time date)) ',(mapcar 'string-to-number (split-string day-desc ","))))
(t
(error "Improperly specified day constraint: %s %s %s" year-desc month-desc day-desc))))
(defun ledger-schedule-parse-complex-date (year-desc month-desc day-desc)
"Parse day descriptors that have repeats."
(let ((years (mapcar 'string-to-number (split-string year-desc ",")))
(months (mapcar 'string-to-number (split-string month-desc ",")))
(day-parts (split-string day-desc "+"))
(every-nth (string-match "+" day-desc)))
(if every-nth
(let ((base-day (string-to-number (car day-parts)))
(increment (string-to-number (substring (cadr day-parts) 0
(string-match "[A-Za-z]" (cadr day-parts)))))
(day-of-week (ledger-schedule-encode-day-of-week
(substring (cadr day-parts) (string-match "[A-Za-z]" (cadr day-parts))))))
(ledger-schedule-constrain-every-count-day day-of-week increment (encode-time 0 0 0 base-day (car months) (car years))))
(let ((count (string-to-number (substring (car day-parts) 0 1)))
(day-of-week (ledger-schedule-encode-day-of-week
(substring (car day-parts) (string-match "[A-Za-z]" (car day-parts))))))
(ledger-schedule-constrain-day-in-month count day-of-week)))))
"Parse day descriptors that have repeats."
(let ((years (mapcar 'string-to-number (split-string year-desc ",")))
(months (mapcar 'string-to-number (split-string month-desc ",")))
(day-parts (split-string day-desc "+"))
(every-nth (string-match "+" day-desc)))
(if every-nth
(let ((base-day (string-to-number (car day-parts)))
(increment (string-to-number (substring (cadr day-parts) 0
(string-match "[A-Za-z]" (cadr day-parts)))))
(day-of-week (ledger-schedule-encode-day-of-week
(substring (cadr day-parts) (string-match "[A-Za-z]" (cadr day-parts))))))
(ledger-schedule-constrain-every-count-day day-of-week increment (encode-time 0 0 0 base-day (car months) (car years))))
(let ((count (string-to-number (substring (car day-parts) 0 1)))
(day-of-week (ledger-schedule-encode-day-of-week
(substring (car day-parts) (string-match "[A-Za-z]" (car day-parts))))))
(ledger-schedule-constrain-day-in-month count day-of-week)))))
(defun ledger-schedule-list-upcoming-xacts (candidate-items early horizon)
"Search CANDIDATE-ITEMS for xacts that occur within the period today - EARLY to today + HORIZON."
(let ((start-date (time-subtract (current-time) (days-to-time early)))
test-date items)
(loop for day from 0 to (+ early horizon) by 1 do
(setq test-date (time-add start-date (days-to-time day)))
(dolist (candidate candidate-items items)
(if (funcall (car candidate) test-date)
(setq items (append items (list (list test-date (cadr candidate))))))))
items))
"Search CANDIDATE-ITEMS for xacts that occur within the period today - EARLY to today + HORIZON."
(let ((start-date (time-subtract (current-time) (days-to-time early)))
test-date items)
(loop for day from 0 to (+ early horizon) by 1 do
(setq test-date (time-add start-date (days-to-time day)))
(dolist (candidate candidate-items items)
(if (funcall (car candidate) test-date)
(setq items (append items (list (list test-date (cadr candidate))))))))
items))
(defun ledger-schedule-create-auto-buffer (candidate-items early horizon ledger-buf)
"Format CANDIDATE-ITEMS for display."
@ -290,7 +290,7 @@ date descriptor."
(with-current-buffer schedule-buf
(erase-buffer)
(dolist (candidate candidates)
(insert (format-time-string date-format (car candidate) ) " " (cadr candidate) "\n"))
(insert (format-time-string date-format (car candidate) ) " " (cadr candidate) "\n"))
(ledger-mode))
(length candidates)))
@ -311,15 +311,15 @@ Use a prefix arg to change the default value"
(read-number "Look forward: " ledger-schedule-look-forward))
(list ledger-schedule-file ledger-schedule-look-backward ledger-schedule-look-forward)))
(if (and file
(file-exists-p file))
(progn
(ledger-schedule-create-auto-buffer
(ledger-schedule-scan-transactions file)
look-backward
look-forward
(current-buffer))
(pop-to-buffer ledger-schedule-buffer-name))
(error "Could not find ledger schedule file at %s" file)))
(file-exists-p file))
(progn
(ledger-schedule-create-auto-buffer
(ledger-schedule-scan-transactions file)
look-backward
look-forward
(current-buffer))
(pop-to-buffer ledger-schedule-buffer-name))
(error "Could not find ledger schedule file at %s" file)))
(provide 'ledger-schedule)

View file

@ -28,17 +28,17 @@
(defun ledger-sort-find-start ()
"Find the beginning of a sort region"
"Find the beginning of a sort region"
(if (re-search-forward ";.*Ledger-mode:.*Start sort" nil t)
(match-end 0)))
(defun ledger-sort-find-end ()
"Find the end of a sort region"
"Find the end of a sort region"
(if (re-search-forward ";.*Ledger-mode:.*End sort" nil t)
(match-end 0)))
(defun ledger-sort-insert-start-mark ()
"Insert a marker to start a sort region"
"Insert a marker to start a sort region"
(interactive)
(save-excursion
(goto-char (point-min))
@ -48,7 +48,7 @@
(insert "\n; Ledger-mode: Start sort\n\n"))
(defun ledger-sort-insert-end-mark ()
"Insert a marker to end a sort region"
"Insert a marker to end a sort region"
(interactive)
(save-excursion
(goto-char (point-min))
@ -64,7 +64,7 @@
(defun ledger-sort-region (beg end)
"Sort the region from BEG to END in chronological order."
(interactive "r") ;; load beg and end from point and mark
;; automagically
;; automagically
(let ((new-beg beg)
(new-end end)
point-delta
@ -77,14 +77,14 @@
(save-excursion
(save-restriction
(goto-char beg)
;; make sure point is at the beginning of a xact
;; make sure point is at the beginning of a xact
(ledger-navigate-next-xact)
(unless (looking-at ledger-payee-any-status-regex)
(ledger-navigate-next-xact))
(setq new-beg (point))
(goto-char end)
(ledger-navigate-next-xact)
;; make sure end of region is at the beginning of next record
;; make sure end of region is at the beginning of next record
;; after the region
(setq new-end (point))
(narrow-to-region new-beg new-end)

View file

@ -114,8 +114,8 @@ dropped."
(when (not (eq (ledger-state-from-char (char-after)) 'comment))
(insert (ledger-char-from-state cur-status) " ")
(if (and (search-forward " " (line-end-position) t)
(looking-at " "))
(delete-char 2)))
(looking-at " "))
(delete-char 2)))
(forward-line))
(setq new-status nil)))

View file

@ -185,8 +185,8 @@ correct chronological place in the buffer."
(goto-char (point-min))
(if (looking-at "Error: ")
(error (concat "Error in ledger-add-transaction: " (buffer-string)))
(ledger-post-align-postings (point-min) (point-max))
(buffer-string)))
(ledger-post-align-postings (point-min) (point-max))
(buffer-string)))
"\n"))
(progn
(insert (car args) " \n\n")

View file

@ -28,7 +28,6 @@ set(LEDGER_SOURCES
textual.cc
temps.cc
journal.cc
archive.cc
account.cc
xact.cc
post.cc
@ -80,7 +79,6 @@ set(LEDGER_INCLUDES
account.h
amount.h
annotate.h
archive.h
balance.h
chain.h
commodity.h

View file

@ -289,26 +289,6 @@ public:
}
bool children_with_xdata() const;
std::size_t children_with_flags(xdata_t::flags_t flags) const;
#if HAVE_BOOST_SERIALIZATION
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & boost::serialization::base_object<supports_flags<> >(*this);
ar & boost::serialization::base_object<scope_t>(*this);
ar & parent;
ar & name;
ar & note;
ar & depth;
ar & accounts;
ar & posts;
ar & _fullname;
}
#endif // HAVE_BOOST_SERIALIZATION
};
std::ostream& operator<<(std::ostream& out, const account_t& account);

View file

@ -93,20 +93,6 @@ struct amount_t::bigint_t : public supports_flags<>
}
return true;
}
#if HAVE_BOOST_SERIALIZATION
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */)
{
ar & boost::serialization::base_object<supports_flags<> >(*this);
ar & val;
ar & prec;
ar & refc;
}
#endif // HAVE_BOOST_SERIALIZATION
};
bool amount_t::is_initialized = false;
@ -1331,69 +1317,4 @@ void put_amount(property_tree::ptree& st, const amount_t& amt,
st.put("quantity", amt.quantity_string());
}
#if HAVE_BOOST_SERIALIZATION
template<class Archive>
void amount_t::serialize(Archive& ar, const unsigned int /* version */)
{
ar & is_initialized;
ar & quantity;
ar & commodity_;
}
#endif // HAVE_BOOST_SERIALIZATION
} // namespace ledger
#if HAVE_BOOST_SERIALIZATION
namespace boost {
namespace serialization {
template <class Archive>
void serialize(Archive& ar, MP_INT& mpz, const unsigned int /* version */)
{
ar & mpz._mp_alloc;
ar & mpz._mp_size;
ar & mpz._mp_d;
}
template <class Archive>
void serialize(Archive& ar, MP_RAT& mpq, const unsigned int /* version */)
{
ar & mpq._mp_num;
ar & mpq._mp_den;
}
template <class Archive>
void serialize(Archive& ar, long unsigned int& integer,
const unsigned int /* version */)
{
ar & make_binary_object(&integer, sizeof(long unsigned int));
}
} // namespace serialization
} // namespace boost
BOOST_CLASS_EXPORT(ledger::annotated_commodity_t)
template void boost::serialization::serialize(boost::archive::binary_iarchive&,
MP_INT&, const unsigned int);
template void boost::serialization::serialize(boost::archive::binary_oarchive&,
MP_INT&, const unsigned int);
template void boost::serialization::serialize(boost::archive::binary_iarchive&,
MP_RAT&, const unsigned int);
template void boost::serialization::serialize(boost::archive::binary_oarchive&,
MP_RAT&, const unsigned int);
template void boost::serialization::serialize(boost::archive::binary_iarchive&,
long unsigned int&,
const unsigned int);
template void boost::serialization::serialize(boost::archive::binary_oarchive&,
long unsigned int&,
const unsigned int);
template void ledger::amount_t::serialize(boost::archive::binary_iarchive&,
const unsigned int);
template void ledger::amount_t::serialize(boost::archive::binary_oarchive&,
const unsigned int);
#endif // HAVE_BOOST_SERIALIZATION

View file

@ -743,16 +743,6 @@ public:
bool valid() const;
#if HAVE_BOOST_SERIALIZATION
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */);
#endif // HAVE_BOOST_SERIALIZATION
/*@}*/
};

View file

@ -107,21 +107,6 @@ struct annotation_t : public supports_flags<>,
assert(*this);
return true;
}
#if HAVE_BOOST_SERIALIZATION
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & boost::serialization::base_object<supports_flags<> >(*this);
ar & price;
ar & date;
ar & tag;
}
#endif // HAVE_BOOST_SERIALIZATION
};
void put_annotation(property_tree::ptree& pt, const annotation_t& details);
@ -162,21 +147,6 @@ struct keep_details_t
return keep_price || keep_date || keep_tag;
}
bool keep_any(const commodity_t& comm) const;
#if HAVE_BOOST_SERIALIZATION
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & keep_price;
ar & keep_date;
ar & keep_tag;
ar & only_actuals;
}
#endif // HAVE_BOOST_SERIALIZATION
};
inline std::ostream& operator<<(std::ostream& out,
@ -250,24 +220,6 @@ public:
virtual void write_annotations(std::ostream& out,
bool no_computed_annotations = false) const;
#if HAVE_BOOST_SERIALIZATION
private:
explicit annotated_commodity_t() : ptr(NULL) {
TRACE_CTOR(annotated_commodity_t, "");
}
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & boost::serialization::base_object<commodity_t>(*this);
ar & ptr;
ar & details;
}
#endif // HAVE_BOOST_SERIALIZATION
};
inline annotated_commodity_t&

View file

@ -1,295 +0,0 @@
/*
* Copyright (c) 2003-2015, John Wiegley. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of New Artisans LLC nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <system.hh>
#if HAVE_BOOST_SERIALIZATION
#include "archive.h"
#include "amount.h"
#include "commodity.h"
#include "pool.h"
#include "scope.h"
#include "account.h"
#include "post.h"
#include "xact.h"
#define LEDGER_MAGIC 0x4c454447
#define ARCHIVE_VERSION 0x03000006
//BOOST_IS_ABSTRACT(ledger::scope_t)
BOOST_CLASS_EXPORT(ledger::scope_t)
BOOST_CLASS_EXPORT(ledger::child_scope_t)
BOOST_CLASS_EXPORT(ledger::symbol_scope_t)
BOOST_CLASS_EXPORT(ledger::call_scope_t)
BOOST_CLASS_EXPORT(ledger::account_t)
BOOST_CLASS_EXPORT(ledger::item_t)
BOOST_CLASS_EXPORT(ledger::post_t)
BOOST_CLASS_EXPORT(ledger::xact_base_t)
BOOST_CLASS_EXPORT(ledger::xact_t)
BOOST_CLASS_EXPORT(ledger::auto_xact_t)
BOOST_CLASS_EXPORT(ledger::period_xact_t)
template void ledger::journal_t::serialize(boost::archive::binary_oarchive&,
const unsigned int);
template void ledger::journal_t::serialize(boost::archive::binary_iarchive&,
const unsigned int);
namespace ledger {
namespace {
bool read_header_bits(std::istream& in) {
uint32_t bytes;
assert(sizeof(uint32_t) == 4);
in.read(reinterpret_cast<char *>(&bytes), sizeof(uint32_t));
if (bytes != LEDGER_MAGIC) {
DEBUG("archive.journal", "Magic bytes not present");
return false;
}
in.read(reinterpret_cast<char *>(&bytes), sizeof(uint32_t));
if (bytes != ARCHIVE_VERSION) {
DEBUG("archive.journal", "Archive version mismatch");
return false;
}
return true;
}
void write_header_bits(std::ostream& out) {
uint32_t bytes;
assert(sizeof(uint32_t) == 4);
bytes = LEDGER_MAGIC;
out.write(reinterpret_cast<char *>(&bytes), sizeof(uint32_t));
bytes = ARCHIVE_VERSION;
out.write(reinterpret_cast<char *>(&bytes), sizeof(uint32_t));
}
}
bool archive_t::read_header()
{
uintmax_t size = file_size(file);
if (size < 8)
return false;
// Open the stream, read the version number and the list of sources
ifstream stream(file, std::ios::binary);
if (! read_header_bits(stream))
return false;
boost::archive::binary_iarchive iarchive(stream);
DEBUG("archive.journal", "Reading header from archive");
iarchive >> *this;
DEBUG("archive.journal",
"Version number: " << std::hex << ARCHIVE_VERSION << std::dec);
DEBUG("archive.journal", "Number of sources: " << sources.size());
#if DEBUG_ON
foreach (const journal_t::fileinfo_t& i, sources)
DEBUG("archive.journal", "Loaded source: " << *i.filename);
#endif
return true;
}
bool archive_t::should_load(const std::list<path>& data_files)
{
std::size_t found = 0;
DEBUG("archive.journal", "Should the archive be loaded?");
if (! exists(file)) {
DEBUG("archive.journal", "No, it does not exist");
return false;
}
if (! read_header()) {
DEBUG("archive.journal", "No, header failed to read");
return false;
}
if (data_files.empty()) {
DEBUG("archive.journal", "No, there were no data files!");
return false;
}
if (sources.empty()) {
DEBUG("archive.journal", "No, there were no sources!");
return false;
}
if (data_files.size() != sources.size()) {
DEBUG("archive.journal", "No, number of sources doesn't match: "
<< data_files.size() << " != " << sources.size());
return false;
}
foreach (const path& p, data_files) {
DEBUG("archive.journal", "Scanning for data file: " << p);
if (! exists(p)) {
DEBUG("archive.journal", "No, an input source no longer exists: " << p);
return false;
}
foreach (const journal_t::fileinfo_t& i, sources) {
assert(! i.from_stream);
assert(i.filename);
DEBUG("archive.journal", "Comparing against source file: " << *i.filename);
if (*i.filename == p) {
if (! exists(*i.filename)) {
DEBUG("archive.journal",
"No, a referent source no longer exists: " << *i.filename);
return false;
}
if (i.modtime != posix_time::from_time_t(last_write_time(p))) {
DEBUG("archive.journal", "No, a source's modtime has changed: " << p);
return false;
}
if (i.size != file_size(p)) {
DEBUG("archive.journal", "No, a source's size has changed: " << p);
return false;
}
found++;
}
}
}
if (found != data_files.size()) {
DEBUG("archive.journal", "No, not every source's name matched");
return false;
}
DEBUG("archive.journal", "Yes, it should be loaded!");
return true;
}
bool archive_t::should_save(journal_t& journal)
{
std::list<path> data_files;
DEBUG("archive.journal", "Should the archive be saved?");
if (journal.was_loaded) {
DEBUG("archive.journal", "No, it's one we loaded before");
return false;
}
if (journal.sources.empty()) {
DEBUG("archive.journal", "No, there were no sources!");
return false;
}
foreach (const journal_t::fileinfo_t& i, journal.sources) {
if (i.from_stream) {
DEBUG("archive.journal", "No, one source was from a stream");
return false;
}
if (! exists(*i.filename)) {
DEBUG("archive.journal",
"No, a source no longer exists: " << *i.filename);
return false;
}
data_files.push_back(*i.filename);
}
if (should_load(data_files)) {
DEBUG("archive.journal", "No, because it's still loadable");
return false;
}
DEBUG("archive.journal", "Yes, it should be saved!");
return true;
}
void archive_t::save(journal_t& journal)
{
INFO_START(archive, "Saved journal file cache");
ofstream stream(file, std::ios::binary);
write_header_bits(stream);
sources = journal.sources;
#if DEBUG_ON
foreach (const journal_t::fileinfo_t& i, sources)
DEBUG("archive.journal", "Saving source: " << *i.filename);
#endif
boost::archive::binary_oarchive oa(stream);
DEBUG("archive.journal", "Creating archive with version "
<< std::hex << ARCHIVE_VERSION << std::dec);
oa << *this;
DEBUG("archive.journal",
"Archiving journal with " << sources.size() << " sources");
oa << journal;
INFO_FINISH(archive);
}
bool archive_t::load(journal_t& journal)
{
INFO_START(archive, "Read cached journal file");
ifstream stream(file, std::ios::binary);
if (! read_header_bits(stream))
return false;
boost::archive::binary_iarchive iarchive(stream);
// Skip past the archive header, it was already read in before
archive_t temp;
iarchive >> temp;
iarchive >> journal;
journal.was_loaded = true;
INFO_FINISH(archive);
return true;
}
} // namespace ledger
#endif // HAVE_BOOST_SERIALIZATION

View file

@ -1,92 +0,0 @@
/*
* Copyright (c) 2003-2015, John Wiegley. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* - Neither the name of New Artisans LLC nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @defgroup report Reporting
*/
/**
* @file archive.h
* @author John Wiegley
*
* @ingroup report
*/
#ifndef _ARCHIVE_H
#define _ARCHIVE_H
#include "journal.h"
namespace ledger {
class archive_t
{
path file;
std::list<journal_t::fileinfo_t> sources;
public:
archive_t() {
TRACE_CTOR(archive_t, "");
}
archive_t(const path& _file) : file(_file) {
TRACE_CTOR(archive_t, "const path&");
}
archive_t(const archive_t& ar) : file(ar.file) {
TRACE_CTOR(archive_t, "copy");
}
~archive_t() {
TRACE_DTOR(archive_t);
}
bool read_header();
bool should_load(const std::list<path>& data_files);
bool should_save(journal_t& journal);
void save(journal_t& journal);
bool load(journal_t& journal);
#if HAVE_BOOST_SERIALIZATION
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & sources;
}
#endif // HAVE_BOOST_SERIALIZATION
};
} // namespace ledger
#endif // _ARCHIVE_H

View file

@ -594,18 +594,6 @@ public:
}
return true;
}
#if HAVE_BOOST_SERIALIZATION
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & amounts;
}
#endif // HAVE_BOOST_SERIALIZATION
};
inline std::ostream& operator<<(std::ostream& out, const balance_t& bal) {

View file

@ -68,19 +68,6 @@ struct price_point_t
bool operator==(const price_point_t& other) const {
return when == other.when && price == other.price;
}
#if HAVE_BOOST_SERIALIZATION
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & when;
ar & price;
}
#endif // HAVE_BOOST_SERIALIZATION
};
class commodity_t
@ -138,28 +125,6 @@ protected:
virtual ~base_t() {
TRACE_DTOR(commodity_t::base_t);
}
#if HAVE_BOOST_SERIALIZATION
private:
base_t() {
TRACE_CTOR(base_t, "");
}
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & boost::serialization::base_object<supports_flags<uint_least16_t> >(*this);
ar & symbol;
ar & precision;
ar & name;
ar & note;
ar & smaller;
ar & larger;
}
#endif // HAVE_BOOST_SERIALIZATION
};
shared_ptr<base_t> base;
@ -315,32 +280,6 @@ public:
struct compare_by_commodity {
bool operator()(const amount_t * left, const amount_t * right) const;
};
#if HAVE_BOOST_SERIALIZATION
private:
supports_flags<uint_least16_t> temp_flags;
protected:
explicit commodity_t()
: delegates_flags<uint_least16_t>(temp_flags), parent_(NULL),
annotated(false) {
TRACE_CTOR(commodity_t, "");
}
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & boost::serialization::base_object<delegates_flags<uint_least16_t> >(*this);
ar & base;
ar & parent_;
ar & qualified_symbol;
ar & annotated;
}
#endif // HAVE_BOOST_SERIALIZATION
};
inline std::ostream& operator<<(std::ostream& out, const commodity_t& comm) {

View file

@ -106,19 +106,6 @@ public:
virtual string context_to_str() const;
virtual void print(std::ostream& out) const;
virtual void dump(std::ostream& out) const;
#if HAVE_BOOST_SERIALIZATION
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & boost::serialization::base_object<base_type>(*this);
ar & ptr;
}
#endif // HAVE_BOOST_SERIALIZATION
};
/**

View file

@ -231,21 +231,6 @@ public:
out << std::endl << _("--- Result value ---") << std::endl;
return calc();
}
#if HAVE_BOOST_SERIALIZATION
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & context;
ar & str;
if (Archive::is_loading::value)
compiled = false;
}
#endif // HAVE_BOOST_SERIALIZATION
};
template <typename ResultType>

View file

@ -90,17 +90,6 @@ public:
void drop_flags(const flags_t arg) {
_flags = static_cast<T>(static_cast<U>(_flags) & static_cast<U>(~arg));
}
#if HAVE_BOOST_SERIALIZATION
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */)
{
ar & _flags;
}
#endif // HAVE_BOOST_SERIALIZATION
};
template <typename T = boost::uint_least8_t, typename U = T>
@ -193,17 +182,6 @@ public:
void drop_flags(const flags_t arg) {
_flags.drop_flags(arg);
}
#if HAVE_BOOST_SERIALIZATION
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */)
{
ar & _flags;
}
#endif // HAVE_BOOST_SERIALIZATION
};
#endif // _FLAGS_H

View file

@ -316,9 +316,6 @@ option_t<global_scope_t> * global_scope_t::lookup_option(const char * p)
case 'd':
OPT(debug_);
break;
case 'f':
OPT(full_help);
break;
case 'h':
OPT_(help);
break;

View file

@ -147,7 +147,6 @@ See LICENSE file included with the distribution for details and disclaimer.");
void visit_man_page() const;
OPTION_(global_scope_t, full_help, DO() { parent->visit_man_page(); }); // -H
OPTION_(global_scope_t, help, DO() { parent->visit_man_page(); }); // -h
OPTION__

View file

@ -78,23 +78,6 @@ struct position_t
}
return *this;
}
#if HAVE_BOOST_SERIALIZATION
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & pathname;
ar & beg_pos;
ar & beg_line;
ar & end_pos;
ar & end_line;
ar & sequence;
}
#endif // HAVE_BOOST_SERIALIZATION
};
class item_t : public supports_flags<uint_least16_t>, public scope_t
@ -226,25 +209,6 @@ public:
const string& name);
bool valid() const;
#if HAVE_BOOST_SERIALIZATION
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & boost::serialization::base_object<supports_flags<uint_least16_t> >(*this);
ar & boost::serialization::base_object<scope_t>(*this);
ar & _state;
ar & _date;
ar & _date_aux;
ar & note;
ar & pos;
ar & metadata;
}
#endif // HAVE_BOOST_SERIALIZATION
};
value_t get_comment(item_t& item);

View file

@ -100,21 +100,6 @@ public:
~fileinfo_t() throw() {
TRACE_DTOR(journal_t::fileinfo_t);
}
#if HAVE_BOOST_SERIALIZATION
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & filename;
ar & size;
ar & modtime;
ar & from_stream;
}
#endif // HAVE_BOOST_SERIALIZATION
};
account_t * master;
@ -215,26 +200,6 @@ public:
private:
std::size_t read_textual(parse_context_stack_t& context);
#if HAVE_BOOST_SERIALIZATION
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & master;
ar & bucket;
ar & xacts;
ar & auto_xacts;
ar & period_xacts;
ar & sources;
ar & payee_mappings;
ar & account_mappings;
ar & checksum_map;
}
#endif // HAVE_BOOST_SERIALIZATION
};
} // namespace ledger

View file

@ -54,7 +54,7 @@ namespace {
struct usage_sorter {
bool operator()(const account_use_pair& left,
const account_use_pair& right) const {
return left.second > right.second;
return left.second < right.second;
}
};
}

View file

@ -124,25 +124,6 @@ public:
}
return true;
}
#if HAVE_BOOST_SERIALIZATION
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
string temp;
if (Archive::is_loading::value) {
ar & temp;
*this = temp;
} else {
temp = str();
ar & temp;
}
}
#endif // HAVE_BOOST_SERIALIZATION
};
inline std::ostream& operator<<(std::ostream& out, const mask_t& mask) {

View file

@ -314,33 +314,6 @@ private:
value_t calc_call(scope_t& scope, ptr_op_t * locus, const int depth);
value_t calc_cons(scope_t& scope, ptr_op_t * locus, const int depth);
value_t calc_seq(scope_t& scope, ptr_op_t * locus, const int depth);
#if HAVE_BOOST_SERIALIZATION
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & refc;
ar & kind;
if (Archive::is_loading::value || ! left_ || ! left_->is_function()) {
ar & left_;
} else {
ptr_op_t temp_op;
ar & temp_op;
}
if (Archive::is_loading::value || is_value() || is_ident() ||
(kind > UNARY_OPERATORS &&
(! has_right() || ! right()->is_function()))) {
ar & data;
} else {
variant<ptr_op_t, value_t, string, expr_t::func_t> temp_data;
ar & temp_data;
}
}
#endif // HAVE_BOOST_SERIALIZATION
};
inline expr_t::ptr_op_t

View file

@ -132,26 +132,6 @@ public:
parse_price_expression(const std::string& str,
const bool add_prices = true,
const optional<datetime_t>& moment = none);
#if HAVE_BOOST_SERIALIZATION
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & current_pool;
ar & commodities;
ar & annotated_commodities;
ar & null_commodity;
ar & default_commodity;
ar & keep_base;
ar & price_db;
ar & quote_leeway;
ar & get_quotes;
}
#endif // HAVE_BOOST_SERIALIZATION
};
} // namespace ledger

View file

@ -255,24 +255,6 @@ public:
}
}
};
#if HAVE_BOOST_SERIALIZATION
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & boost::serialization::base_object<item_t>(*this);
ar & xact;
ar & account;
ar & amount;
ar & amount_expr;
ar & cost;
ar & assigned_amount;
}
#endif // HAVE_BOOST_SERIALIZATION
};
class journal_t;

View file

@ -90,19 +90,6 @@ public:
.to_boolean() :
true);
}
#if HAVE_BOOST_SERIALIZATION
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & boost::serialization::base_object<expr_t>(*this);
ar & what_to_keep;
}
#endif // HAVE_BOOST_SERIALIZATION
};
} // namespace ledger

View file

@ -496,7 +496,7 @@ public:
"%-(ansify_if(partial_account(options.flat), blue if color))\n%/"
"%$1 %$2 %$3\n%/"
"%(prepend_width ? \" \" * int(prepend_width) : \"\")"
"---------------- ---------------- ---------\n");
"---------------- ---------------- ---------\n");
});
OPTION(report_t, color);

View file

@ -83,20 +83,6 @@ struct symbol_t
bool operator==(const symbol_t& sym) const {
return kind == sym.kind || name == sym.name;
}
#if HAVE_BOOST_SERIALIZATION
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & kind;
ar & name;
ar & definition;
}
#endif // HAVE_BOOST_SERIALIZATION
};
class empty_scope_t;
@ -127,16 +113,6 @@ public:
virtual bool type_required() const {
return false;
}
#if HAVE_BOOST_SERIALIZATION
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive&, const unsigned int /* version */) {}
#endif // HAVE_BOOST_SERIALIZATION
};
class empty_scope_t : public scope_t
@ -184,19 +160,6 @@ public:
return parent->lookup(kind, name);
return NULL;
}
#if HAVE_BOOST_SERIALIZATION
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & boost::serialization::base_object<scope_t>(*this);
ar & parent;
}
#endif // HAVE_BOOST_SERIALIZATION
};
class bind_scope_t : public child_scope_t
@ -233,19 +196,6 @@ public:
return def;
return child_scope_t::lookup(kind, name);
}
#if HAVE_BOOST_SERIALIZATION
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & boost::serialization::base_object<child_scope_t>(*this);
ar & grandchild;
}
#endif // HAVE_BOOST_SERIALIZATION
};
template <typename T>
@ -323,19 +273,6 @@ public:
virtual expr_t::ptr_op_t lookup(const symbol_t::kind_t kind,
const string& name);
#if HAVE_BOOST_SERIALIZATION
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & boost::serialization::base_object<child_scope_t>(*this);
ar & symbols;
}
#endif // HAVE_BOOST_SERIALIZATION
};
class context_scope_t : public child_scope_t
@ -365,24 +302,6 @@ public:
virtual bool type_required() const {
return required;
}
#if HAVE_BOOST_SERIALIZATION
protected:
explicit context_scope_t() {
TRACE_CTOR(context_scope_t, "");
}
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & boost::serialization::base_object<child_scope_t>(*this);
ar & value_type_context;
ar & required;
}
#endif // HAVE_BOOST_SERIALIZATION
};
class call_scope_t : public context_scope_t
@ -480,24 +399,6 @@ public:
bool empty() const {
return args.size() == 0;
}
#if HAVE_BOOST_SERIALIZATION
protected:
explicit call_scope_t() : depth(0) {
TRACE_CTOR(call_scope_t, "");
}
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & boost::serialization::base_object<context_scope_t>(*this);
ar & args;
//ar & ptr;
}
#endif // HAVE_BOOST_SERIALIZATION
};
template <>

View file

@ -37,7 +37,6 @@
#include "journal.h"
#include "iterators.h"
#include "filters.h"
#include "archive.h"
namespace ledger {
@ -128,16 +127,6 @@ std::size_t session_t::read_data(const string& master_account)
if (HANDLED(value_expr_))
journal->value_expr = HANDLER(value_expr_).str();
#if HAVE_BOOST_SERIALIZATION
optional<archive_t> cache;
if (HANDLED(cache_) && master_account.empty())
cache = archive_t(HANDLED(cache_).str());
if (! (cache &&
cache->should_load(HANDLER(file_).data_files) &&
cache->load(*journal.get()))) {
#endif // HAVE_BOOST_SERIALIZATION
if (price_db_path) {
if (exists(*price_db_path)) {
parsing_context.push(*price_db_path);
@ -191,12 +180,6 @@ std::size_t session_t::read_data(const string& master_account)
<< "] == journal->xacts.size() [" << journal->xacts.size() << "]");
assert(xact_count == journal->xacts.size());
#if HAVE_BOOST_SERIALIZATION
if (cache && cache->should_save(*journal.get()))
cache->save(*journal.get());
}
#endif // HAVE_BOOST_SERIALIZATION
if (populated_data_files)
HANDLER(file_).data_files.clear();
@ -333,8 +316,7 @@ option_t<session_t> * session_t::lookup_option(const char * p)
OPT_CH(price_exp_);
break;
case 'c':
OPT(cache_);
else OPT(check_payees);
OPT(check_payees);
break;
case 'd':
OPT(download); // -Q

View file

@ -97,7 +97,6 @@ public:
void report_options(std::ostream& out)
{
HANDLER(cache_).report(out);
HANDLER(check_payees).report(out);
HANDLER(day_break).report(out);
HANDLER(download).report(out);
@ -126,7 +125,6 @@ public:
* Option handlers
*/
OPTION(session_t, cache_);
OPTION(session_t, check_payees);
OPTION(session_t, day_break);
OPTION(session_t, download); // -Q

View file

@ -71,7 +71,6 @@
#define HAVE_BOOST_PYTHON @HAVE_BOOST_PYTHON@
#define HAVE_BOOST_REGEX_UNICODE @HAVE_BOOST_REGEX_UNICODE@
#define HAVE_BOOST_SERIALIZATION 0
#define DEBUG_MODE @DEBUG_MODE@
#define NO_ASSERTS @NO_ASSERTS@
@ -239,86 +238,8 @@ typedef std::ostream::pos_type ostream_pos_type;
#endif
#define _f(str) boost::format(_(str))
#if HAVE_BOOST_SERIALIZATION
#include <boost/archive/binary_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/binary_object.hpp>
#include <boost/serialization/optional.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include <boost/serialization/variant.hpp>
#include <boost/serialization/utility.hpp>
#include <boost/serialization/export.hpp>
#include <boost/serialization/level.hpp>
#include <boost/serialization/string.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/deque.hpp>
#include <boost/serialization/list.hpp>
#include <boost/serialization/map.hpp>
#include <boost/date_time/posix_time/time_serialize.hpp>
#include <boost/date_time/gregorian/greg_serialize.hpp>
#include <boost/ptr_container/serialize_ptr_deque.hpp>
namespace boost {
namespace serialization {
template <class Archive>
void serialize(Archive& ar, boost::filesystem::path& p, const unsigned int)
{
std::string s;
if (Archive::is_saving::value)
s = p.string();
ar & s;
if (Archive::is_loading::value)
p = s;
}
template <class Archive, class T>
void serialize(Archive& ar, boost::intrusive_ptr<T>& ptr, const unsigned int)
{
if (Archive::is_saving::value) {
T * p = ptr.get();
ar & p;
}
else if (Archive::is_loading::value) {
T * p;
ar & p;
ptr.reset(p);
}
}
template <class Archive>
void serialize(Archive&, boost::any&, const unsigned int) {
// jww (2012-03-29): Should we really ignore any fields entirely?
// These occur inside value_t::storage_t::data's variant.
}
template <class Archive>
void serialize(Archive&, boost::blank&, const unsigned int) {}
template <class Archive, class T>
void serialize(Archive&, boost::function<T>&, const unsigned int) {}
template <class Archive>
void serialize(Archive& ar, istream_pos_type& pos, const unsigned int)
{
ar & make_binary_object(&pos, sizeof(istream_pos_type));
}
} // namespace serialization
} // namespace boost
#else // HAVE_BOOST_SERIALIZATION
#include <boost/ptr_container/ptr_deque.hpp>
#endif // HAVE_BOOST_SERIALIZATION
#if HAVE_BOOST_PYTHON
#include <boost/python.hpp>

View file

@ -153,20 +153,6 @@ struct date_traits_t
has_month == traits.has_month &&
has_day == traits.has_day);
}
#if HAVE_BOOST_SERIALIZATION
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & has_year;
ar & has_month;
ar & has_day;
}
#endif // HAVE_BOOST_SERIALIZATION
};
struct date_duration_t
@ -247,19 +233,6 @@ struct date_duration_t
}
static date_t find_nearest(const date_t& date, skip_quantum_t skip);
#if HAVE_BOOST_SERIALIZATION
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & quantum;
ar & length;
}
#endif // HAVE_BOOST_SERIALIZATION
};
class date_specifier_t
@ -343,21 +316,6 @@ public:
return out.str();
}
#if HAVE_BOOST_SERIALIZATION
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & year;
ar & month;
ar & day;
ar & wday;
}
#endif // HAVE_BOOST_SERIALIZATION
};
class date_range_t
@ -420,20 +378,6 @@ public:
return out.str();
}
#if HAVE_BOOST_SERIALIZATION
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & range_begin;
ar & range_end;
ar & end_inclusive;
}
#endif // HAVE_BOOST_SERIALIZATION
};
class date_specifier_or_range_t
@ -490,18 +434,6 @@ public:
return out.str();
}
#if HAVE_BOOST_SERIALIZATION
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & specifier_or_range;
}
#endif // HAVE_BOOST_SERIALIZATION
};
class date_interval_t : public equality_comparable<date_interval_t>
@ -594,24 +526,6 @@ public:
date_interval_t& operator++();
void dump(std::ostream& out);
#if HAVE_BOOST_SERIALIZATION
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & range;
ar & start;
ar & finish;
ar & aligned;
ar & next;
ar & duration;
ar & end_of_duration;
}
#endif // HAVE_BOOST_SERIALIZATION
};
void times_initialize();

View file

@ -227,20 +227,6 @@ public:
data = false;
type = VOID;
}
#if HAVE_BOOST_SERIALIZATION
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & data;
ar & type;
ar & refc;
}
#endif // HAVE_BOOST_SERIALIZATION
};
private:
@ -965,20 +951,6 @@ public:
* Debugging methods.
*/
bool valid() const;
#if HAVE_BOOST_SERIALIZATION
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & true_value;
ar & false_value;
ar & storage;
}
#endif // HAVE_BOOST_SERIALIZATION
};
#define NULL_VALUE (value_t())

View file

@ -87,20 +87,6 @@ public:
virtual bool valid() const {
return true;
}
#if HAVE_BOOST_SERIALIZATION
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & boost::serialization::base_object<item_t>(*this);
ar & journal;
ar & posts;
}
#endif // HAVE_BOOST_SERIALIZATION
};
class xact_t : public xact_base_t
@ -142,20 +128,6 @@ public:
const string& name);
virtual bool valid() const;
#if HAVE_BOOST_SERIALIZATION
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & boost::serialization::base_object<xact_base_t>(*this);
ar & code;
ar & payee;
}
#endif // HAVE_BOOST_SERIALIZATION
};
class auto_xact_t : public xact_base_t
@ -176,21 +148,6 @@ public:
bool _overwrite_existing)
: tag_data(_tag_data), overwrite_existing(_overwrite_existing),
apply_to_post(NULL) {}
#if HAVE_BOOST_SERIALIZATION
private:
/** Serialization. */
deferred_tag_data_t() : apply_to_post(NULL) {}
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & tag_data;
ar & overwrite_existing;
ar & apply_to_post;
}
#endif // HAVE_BOOST_SERIALIZATION
};
typedef std::list<deferred_tag_data_t> deferred_notes_list;
@ -236,21 +193,6 @@ private:
}
virtual void extend_xact(xact_base_t& xact, parse_context_t& context);
#if HAVE_BOOST_SERIALIZATION
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & boost::serialization::base_object<xact_base_t>(*this);
ar & predicate;
ar & check_exprs;
ar & deferred_notes;
}
#endif // HAVE_BOOST_SERIALIZATION
};
class period_xact_t : public xact_base_t
@ -284,20 +226,6 @@ class period_xact_t : public xact_base_t
return string(_("generated periodic transaction"));
}
}
#if HAVE_BOOST_SERIALIZATION
private:
/** Serialization. */
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive& ar, const unsigned int /* version */) {
ar & boost::serialization::base_object<xact_base_t>(*this);
ar & period;
ar & period_string;
}
#endif // HAVE_BOOST_SERIALIZATION
};
typedef std::list<xact_t *> xacts_list;

View file

@ -21,25 +21,18 @@ class CheckBaselineTests (CheckOptions):
self.untested_options = [
'anon',
'args-only',
'cache',
'debug',
'download',
'file',
'force-color',
'force-pager',
'full-help',
'help',
'help-calc',
'help-comm',
'help-disp',
'import',
'init-file',
'no-color',
'no-pager'
'options',
'price-db',
'price-exp',
'revalued-total',
'script',
'seed',
'trace',
'verbose',

View file

@ -19,13 +19,17 @@ class DocTests:
self.verbose = args.verbose
self.tests = args.examples
self.examples = dict()
self.test_files = list()
self.testin_token = 'command'
self.testout_token = 'output'
self.testdat_token = 'input'
self.examples = dict()
self.test_files = list()
self.testin_token = 'command'
self.testout_token = 'output'
self.testdat_token = 'input'
self.testfile_token = 'file'
self.validate_token = 'validate'
self.testwithdat_token = 'with_input'
self.validate_cmd_token = 'validate-command'
self.validate_dat_token = 'validate-data'
self.testwithdat_token = 'with_input'
self.testwithfile_token = 'with_file'
def read_example(self):
endexample = re.compile(r'^@end\s+smallexample\s*$')
@ -35,15 +39,15 @@ class DocTests:
self.current_line += 1
if len(line) <= 0 or endexample.match(line): break
# Replace special texinfo character sequences with their ASCII counterpart
example += line.replace("@@","@").replace("@{","{").replace("@}","}")
example += re.sub(r'@([@{}])', r'\1', line)
return example
def test_id(self, example):
return hashlib.sha1(example.rstrip()).hexdigest()[0:7].upper()
def find_examples(self):
startexample = re.compile(r'^@smallexample\s+@c\s+(%s|%s|%s)(?::([\dA-Fa-f]+|validate))?(?:,(.*))?'
% (self.testin_token, self.testout_token, self.testdat_token))
startexample = re.compile(r'^@smallexample\s+@c\s+(%s|%s|%s|%s)(?::([\dA-Fa-f]+|validate))?(?:,(.*))?'
% (self.testin_token, self.testout_token, self.testdat_token, self.testfile_token))
while True:
line = self.file.readline()
self.current_line += 1
@ -78,9 +82,9 @@ class DocTests:
if test_id == self.validate_token:
test_id = "Val-" + str(test_begin_line)
if test_kind == self.testin_token:
test_kind = "validate-command"
test_kind = self.validate_cmd_token
elif test_kind == self.testdat_token:
test_kind = "validate-data"
test_kind = self.validate_dat_token
try:
self.examples[test_id]
except KeyError:
@ -105,15 +109,15 @@ class DocTests:
try:
command = example[self.testin_token][self.testin_token]
except KeyError:
if 'validate-data' in example:
if self.validate_dat_token in example:
command = '$ ledger bal'
elif 'validate-command' in example:
elif self.validate_cmd_token in example:
validate_command = True
command = example['validate-command']['validate-command']
command = example[self.validate_cmd_token][self.validate_cmd_token]
else:
return None
command = shlex.split(command)
command = filter(lambda x: x != '\n', shlex.split(command))
if command[0] == '$': command.remove('$')
index = command.index('ledger')
command[index] = self.ledger
@ -145,7 +149,7 @@ class DocTests:
for test_id in tests:
validation = False
if "validate-data" in self.examples[test_id] or "validate-command" in self.examples[test_id]:
if self.validate_dat_token in self.examples[test_id] or self.validate_cmd_token in self.examples[test_id]:
validation = True
example = self.examples[test_id]
try:
@ -154,51 +158,52 @@ class DocTests:
failed.add(test_id)
continue
try:
output = example[self.testout_token][self.testout_token]
except KeyError:
output = None
output = example.get(self.testout_token, {}).get(self.testout_token)
input = example.get(self.testdat_token, {}).get(self.testdat_token)
if not input:
with_input = example.get(self.testin_token, {}).get('opts', {}).get(self.testwithdat_token)
input = self.examples.get(with_input, {}).get(self.testdat_token, {}).get(self.testdat_token)
if not input:
input = example.get(self.validate_dat_token, {}).get(self.validate_dat_token)
try:
input = example[self.testdat_token][self.testdat_token]
except KeyError:
try:
with_input = example[self.testin_token]['opts'][self.testwithdat_token]
input = self.examples[with_input][self.testdat_token][self.testdat_token]
except KeyError:
try:
input = example['validate-data']['validate-data']
except KeyError:
input = None
if command and (output or validation):
if command and (output != None or validation):
test_file_created = False
if findex:
scriptpath = os.path.dirname(os.path.realpath(__file__))
test_input_dir = scriptpath + '/../test/input/'
test_input_dir = os.path.join(scriptpath, '..', 'test', 'input')
test_file = command[findex]
if not os.path.exists(test_file):
if input:
test_file_created = True
with open(test_file, 'w') as f:
f.write(input)
elif os.path.exists(test_input_dir + test_file):
command[findex] = test_input_dir + test_file
error = False
elif os.path.exists(os.path.join(test_input_dir, test_file)):
command[findex] = os.path.join(test_input_dir, test_file)
try:
convert_idx = command.index('convert')
convert_file = command[convert_idx+1]
convert_data = example[self.testfile_token][self.testfile_token]
if not os.path.exists(convert_file):
with open(convert_file, 'w') as f:
f.write(convert_data)
except ValueError:
pass
error = None
try:
verify = subprocess.check_output(command, stderr=subprocess.STDOUT)
except:
verify = str()
error = True
valid = (output == verify) or (not error and validation)
valid = (output == verify) or (not error and validation)
except subprocess.CalledProcessError, e:
error = e.output
valid = False
failed.add(test_id)
if valid and test_file_created:
os.remove(test_file)
if self.verbose > 0:
print test_id, ':', 'Passed' if valid else 'FAILED'
print test_id, ':', 'Passed' if valid else 'FAILED: {}'.format(error) if error else 'FAILED'
else:
sys.stdout.write('.' if valid else 'E')
if not valid:
if not (valid or error):
failed.add(test_id)
if self.verbose > 1:
print ' '.join(command)
@ -206,6 +211,12 @@ class DocTests:
for line in unified_diff(output.split('\n'), verify.split('\n'), fromfile='generated', tofile='expected'):
print(line)
print
else:
if self.verbose > 0:
print test_id, ':', 'Skipped'
else:
sys.stdout.write('X')
if not self.verbose:
print
if len(failed) > 0:

View file

@ -30,7 +30,7 @@ test cleared
-20 0 F
-30 -30 12-Feb-26 G
-40 0 H
---------------- ---------------- ---------
---------------- ---------------- ---------
0 0
end test

View file

@ -14,17 +14,58 @@
Expenses:Food 20.00 EUR
Liabilities:CC -20.00 EUR
test --input-date-format "%Y-%m-%d" --auto-match convert test/baseline/opt-auto-match.dat
test --input-date-format "%Y-%m-%d" convert test/baseline/opt-auto-match.dat
2012/03/01 * Food
Assets:Cash 10
Expenses:Unknown 10
Equity:Unknown
2012/03/02 * Phone
Assets:Cash 10
Expenses:Unknown 10
Equity:Unknown
2012/03/02 * Dining
Liabilities:CC 10
Expenses:Unknown 10
Equity:Unknown
end test
test --input-date-format "%Y-%m-%d" --auto-match convert test/baseline/opt-auto-match.dat
2012/03/01 * Food
Expenses:Food 10
Equity:Unknown
2012/03/02 * Phone
Expenses:Phone 10
Equity:Unknown
2012/03/02 * Dining
Expenses:Food 10
Equity:Unknown
end test
test --input-date-format "%Y-%m-%d" --account Assets:Bank convert test/baseline/opt-auto-match.dat
2012/03/01 * Food
Expenses:Unknown 10
Assets:Bank
2012/03/02 * Phone
Expenses:Unknown 10
Assets:Bank
2012/03/02 * Dining
Expenses:Unknown 10
Assets:Bank
end test
test --input-date-format "%Y-%m-%d" --auto-match --account Assets:Bank convert test/baseline/opt-auto-match.dat
2012/03/01 * Food
Expenses:Food 10
Assets:Bank
2012/03/02 * Phone
Expenses:Phone 10
Assets:Bank
2012/03/02 * Dining
Expenses:Food 10
Assets:Bank
end test

View file

@ -0,0 +1 @@
--decimal-comma

View file

@ -0,0 +1,10 @@
2012-03-17 Quick
Expenses:Food 12,50 €
Assets:Cash
test --init-file test/baseline/opt-init-file.dat bal
-12,50 € Assets:Cash
12,50 € Expenses:Food
--------------------
0
end test

View file

@ -0,0 +1,2 @@
P 2012-03-16 06:47:12 CAD $2.50
P 2012-03-17 06:47:12 CAD $3.50

View file

@ -0,0 +1,8 @@
2012-03-17 KFC
Expenses:Food 20 CAD
Assets:Cash
test pricedb --price-db test/baseline/opt-price-db.dat
P 2012/03/16 06:47:12 CAD $2.5
P 2012/03/17 06:47:12 CAD $3.5
end test

View file

@ -1,3 +1,13 @@
test -f /dev/null convert test/baseline/feat-convert-with-directives.dat --now '2014/08/01'
2012/01/01 * KFC
Expenses:Unknown $10
Equity:Unknown
2012/01/02 * REWE SAGT DANKE 123454321
Expenses:Unknown 10€
Equity:Unknown
end test
test -f /dev/null convert test/baseline/feat-convert-with-directives.dat --detail --now '2014/08/01'
2012/01/01 * KFC
; CSV: 2012/01/01,KFC,$10

View file

@ -0,0 +1,3 @@
--no-pager --columns=80 bal
--no-pager --columns=80 reg
--no-pager --columns=80 print

View file

@ -0,0 +1,15 @@
2012-03-17 KFC
Expenses:Food 20 CAD
Assets:Cash
test --script test/baseline/opt-script.dat
-20 CAD Assets:Cash
20 CAD Expenses:Food
--------------------
0
12-Mar-17 KFC Expenses:Food 20 CAD 20 CAD
Assets:Cash -20 CAD 0
2012/03/17 KFC
Expenses:Food 20 CAD
Assets:Cash
end test

View file

@ -5,17 +5,17 @@
# Add [ci skip] to the commit message unless there are changes to files
# that are relevant for testing such as src/*, test/*, ledger3.texi, ...
function add_ci_skip()
add_ci_skip ()
{
pattern="$1"; shift
source="$1"
# Don't add [ci skip] if it's already in the commit message source
grep '\[ci skip\]' "$source" 2>&1 >/dev/null
grep '\[ci skip\]' "$source" >/dev/null 2>&1
[ $? -eq 0 ] && return
if [ $(git diff --cached --name-only | grep --count "$pattern") -eq 0 ]; then
tempfile=$(mktemp $0.XXXXXX)
tempfile=$(mktemp "${0}.XXXXXX")
cat - "$1" <<EOF > "$tempfile"
# It seems the changes to be committed are irrelevant for the continuous