Merge pull request #122 from enderw88/Lisp-fixes

Fix ledger-add-entry
This commit is contained in:
John Wiegley 2013-01-16 12:18:33 -08:00
commit 6ff7dac73f
4 changed files with 58 additions and 3 deletions

View file

@ -76,6 +76,47 @@ Return the difference in the format of a time value."
(if (ledger-time-less-p moment date)
(throw 'found t)))))))
(defun ledger-iterate-entries (callback)
(goto-char (point-min))
(let* ((now (current-time))
(current-year (nth 5 (decode-time now))))
(while (not (eobp))
(when (looking-at
(concat "\\(Y\\s-+\\([0-9]+\\)\\|"
"\\([0-9]\\{4\\}+\\)?[./]?"
"\\([0-9]+\\)[./]\\([0-9]+\\)\\s-+"
"\\(\\*\\s-+\\)?\\(.+\\)\\)"))
(let ((found (match-string 2)))
(if found
(setq current-year (string-to-number found))
(let ((start (match-beginning 0))
(year (match-string 3))
(month (string-to-number (match-string 4)))
(day (string-to-number (match-string 5)))
(mark (match-string 6))
(desc (match-string 7)))
(if (and year (> (length year) 0))
(setq year (string-to-number year)))
(funcall callback start
(encode-time 0 0 0 day month
(or year current-year))
mark desc)))))
(forward-line))))
(defun ledger-set-year (newyear)
"Set ledger's idea of the current year to the prefix argument."
(interactive "p")
(if (= newyear 1)
(setq ledger-year (read-string "Year: " (ledger-current-year)))
(setq ledger-year (number-to-string newyear))))
(defun ledger-set-month (newmonth)
"Set ledger's idea of the current month to the prefix argument."
(interactive "p")
(if (= newmonth 1)
(setq ledger-month (read-string "Month: " (ledger-current-month)))
(setq ledger-month (format "%02d" newmonth))))
(defun ledger-add-entry (entry-text &optional insert-at-point)
(interactive "sEntry: ")
(let* ((args (with-temp-buffer
@ -95,7 +136,7 @@ Return the difference in the format of a time value."
(insert
(with-temp-buffer
(setq exit-code
(apply #'ledger-run-ledger ledger-buf "entry"
(apply #'ledger-exec-ledger ledger-buf ledger-buf "entry"
(mapcar 'eval args)))
(goto-char (point-min))
(if (looking-at "Error: ")

View file

@ -308,6 +308,13 @@ std::ostream& operator<<(std::ostream& out, const account_t& account);
void put_account(property_tree::ptree& pt, const account_t& acct,
function<bool(const account_t&)> pred);
//simple struct added to allow std::map to compare accounts in the accounts report
struct account_compare {
bool operator() (const account_t& lhs, const account_t& rhs){
return (lhs.fullname().compare(rhs.fullname()) < 0);
}
};
} // namespace ledger
#endif // _ACCOUNT_H

View file

@ -349,6 +349,13 @@ inline std::ostream& operator<<(std::ostream& out, const commodity_t& comm) {
void put_commodity(property_tree::ptree& pt, const commodity_t& comm,
bool commodity_details = false);
//simple struct to allow std::map to compare commodities names
struct commodity_compare {
bool operator() (const commodity_t* lhs, const commodity_t* rhs){
return (lhs->symbol().compare(rhs->symbol()) < 0);
}
};
} // namespace ledger
#endif // _COMMODITY_H

View file

@ -142,7 +142,7 @@ class report_accounts : public item_handler<post_t>
protected:
report_t& report;
std::map<account_t *, std::size_t> accounts;
std::map<account_t *, std::size_t, account_compare> accounts;
typedef std::map<account_t *, std::size_t>::value_type accounts_pair;
@ -194,7 +194,7 @@ class report_commodities : public item_handler<post_t>
protected:
report_t& report;
std::map<commodity_t *, std::size_t> commodities;
std::map<commodity_t *, std::size_t, commodity_compare> commodities;
typedef std::map<commodity_t *, std::size_t>::value_type commodities_pair;