ledger/emacs.cc
John Wiegley 5a90fe7357 Moved xact_xdata_t into xact_t itself, as a set of "extended data" that might
be gathered during reporting.

Removed the references to accounts and such from the mask logic, which means
that the value expression "acount =~ /foo/" is needed in place of just
"/foo/".
2008-08-02 22:45:35 -04:00

78 lines
1.6 KiB
C++

#include "emacs.h"
namespace ledger {
void format_emacs_xacts::write_entry(entry_t& entry)
{
int idx = entry.src_idx;
foreach (const path& path, entry.journal->sources)
if (! idx--) {
out << "\"" << path << "\" ";
break;
}
out << (static_cast<unsigned long>(entry.beg_line) + 1) << " ";
tm when = gregorian::to_tm(entry.date());
std::time_t date = std::mktime(&when); // jww (2008-04-20): Is this GMT or local?
out << "(" << (date / 65536) << " " << (date % 65536) << " 0) ";
if (! entry.code)
out << "nil ";
else
out << "\"" << *entry.code << "\" ";
if (entry.payee.empty())
out << "nil";
else
out << "\"" << entry.payee << "\"";
out << "\n";
}
void format_emacs_xacts::operator()(xact_t& xact)
{
if (! xact.has_xdata() ||
! xact.xdata().has_flags(XACT_EXT_DISPLAYED)) {
if (! last_entry) {
out << "((";
write_entry(*xact.entry);
}
else if (xact.entry != last_entry) {
out << ")\n (";
write_entry(*xact.entry);
}
else {
out << "\n";
}
out << " (" << (static_cast<unsigned long>(xact.beg_line) + 1) << " ";
out << "\"" << xact.reported_account()->fullname() << "\" \""
<< xact.amount << "\"";
switch (xact.state) {
case xact_t::CLEARED:
out << " t";
break;
case xact_t::PENDING:
out << " pending";
break;
default:
out << " nil";
break;
}
if (xact.cost)
out << " \"" << *xact.cost << "\"";
if (xact.note)
out << " \"" << *xact.note << "\"";
out << ")";
last_entry = xact.entry;
xact.xdata().add_flags(XACT_EXT_DISPLAYED);
}
}
} // namespace ledger