summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--ledger.el16
-rw-r--r--reports.cc14
3 files changed, 26 insertions, 8 deletions
diff --git a/Makefile b/Makefile
index 42cc7bf4..44153cd9 100644
--- a/Makefile
+++ b/Makefile
@@ -1,8 +1,8 @@
CODE = amount.cc ledger.cc parse.cc reports.cc
OBJS = $(patsubst %.cc,%.o,$(CODE))
CFLAGS = -Wall -ansi -pedantic
-#DFLAGS = -O3 -fomit-frame-pointer -mcpu=pentium
-DFLAGS = -g -DDEBUG=1
+DFLAGS = -O3 -fomit-frame-pointer
+#DFLAGS = -g -DDEBUG=1
INCS =
LIBS = -lgmpxx -lgmp -lpcre
diff --git a/ledger.el b/ledger.el
new file mode 100644
index 00000000..42be85a6
--- /dev/null
+++ b/ledger.el
@@ -0,0 +1,16 @@
+(defun ledger-add-entry (entry)
+ (interactive
+ (list (read-string "Entry: "
+ (format-time-string "%m.%d " (current-time)))))
+ (let ((args (mapcar 'shell-quote-argument (split-string entry))))
+ (shell-command
+ (concat "ledger entry "
+ (mapconcat 'identity args " ")) t)
+ (delete-char 5)
+ (exchange-point-and-mark)))
+
+(define-derived-mode ledger-mode text-mode "Ledger"
+ "A mode for editing ledger data files."
+ (setq comment-start ";" comment-end nil)
+ (let ((map (current-local-map)))
+ (define-key map [(control ?c) ?n] 'ledger-add-entry)))
diff --git a/reports.cc b/reports.cc
index abce67df..5d5aea18 100644
--- a/reports.cc
+++ b/reports.cc
@@ -366,6 +366,8 @@ void add_new_entry(int index, int argc, char **argv)
entry added(main_ledger);
entry * matching = NULL;
+ assert(index < argc);
+
if (! parse_date(argv[index++], &added.date)) {
std::cerr << "Error: Bad add date: " << argv[index - 1]
<< std::endl;
@@ -405,7 +407,7 @@ void add_new_entry(int index, int argc, char **argv)
std::exit(1);
}
- transaction * m_xact, * xact, * first;
+ transaction * m_xact, * xact, * first;
m_xact = matching->xacts.front();
@@ -645,7 +647,7 @@ int main(int argc, char * argv[])
const std::string command = argv[index++];
int name_index = index;
- if (command == "register") {
+ if (command == "register" || command == "reg") {
if (optind == argc) {
std::cerr << ("Error: Must specify an account name "
"after the 'register' command.") << std::endl;
@@ -657,7 +659,7 @@ int main(int argc, char * argv[])
// Compile the list of specified regular expressions, which can be
// specified after the command, or using the '-i FILE' option
- if (command != "add")
+ if (command != "entry")
for (; index < argc; index++)
regexps.push_back(mask(argv[index]));
@@ -697,10 +699,10 @@ int main(int argc, char * argv[])
// Process the command
- if (command == "balance") {
+ if (command == "balance" || command == "bal") {
report_balances(std::cout, regexps);
}
- else if (command == "register") {
+ else if (command == "register" || command == "reg") {
if (show_sorted)
main_ledger->sort(cmp_entry_date());
print_register(argv[name_index], std::cout, regexps);
@@ -713,7 +715,7 @@ int main(int argc, char * argv[])
else if (command == "equity") {
equity_ledger(std::cout, regexps);
}
- else if (command == "add") {
+ else if (command == "entry") {
add_new_entry(index, argc, argv);
}