summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ldg-mode.el1
-rw-r--r--lisp/ldg-post.el2
-rw-r--r--lisp/ldg-test.el75
-rw-r--r--lisp/ledger.el6
4 files changed, 80 insertions, 4 deletions
diff --git a/lisp/ldg-mode.el b/lisp/ldg-mode.el
index cc9e8d92..4d13d7d2 100644
--- a/lisp/ldg-mode.el
+++ b/lisp/ldg-mode.el
@@ -47,6 +47,7 @@
(define-key map [(control ?c) (control ?e)] 'ledger-toggle-current-entry)
(define-key map [(control ?c) (control ?r)] 'ledger-reconcile)
(define-key map [(control ?c) (control ?s)] 'ledger-sort)
+ (define-key map [(control ?c) (control ?t)] 'ledger-test-run)
(define-key map [tab] 'pcomplete)
(define-key map [(control ?i)] 'pcomplete)
(define-key map [(control ?c) tab] 'ledger-fully-complete-entry)
diff --git a/lisp/ldg-post.el b/lisp/ldg-post.el
index da4a2806..05b9d352 100644
--- a/lisp/ldg-post.el
+++ b/lisp/ldg-post.el
@@ -4,7 +4,7 @@
""
:group 'ledger)
-(defcustom ledger-post-auto-adjust-amounts t
+(defcustom ledger-post-auto-adjust-amounts nil
"If non-nil, ."
:type 'boolean
:group 'ledger-post)
diff --git a/lisp/ldg-test.el b/lisp/ldg-test.el
new file mode 100644
index 00000000..478c62d8
--- /dev/null
+++ b/lisp/ldg-test.el
@@ -0,0 +1,75 @@
+(defcustom ledger-source-directory "~/src/ledger"
+ "Directory where the Ledger sources are located."
+ :type 'directory
+ :group 'ledger)
+
+(defcustom ledger-test-binary "~/Products/ledger/debug/ledger"
+ "Directory where the Ledger sources are located."
+ :type 'file
+ :group 'ledger)
+
+(defun ledger-test-org-narrow-to-entry ()
+ (outline-back-to-heading)
+ (narrow-to-region (point) (progn (outline-next-heading) (point)))
+ (goto-char (point-min)))
+
+(defun ledger-test-create ()
+ (interactive)
+ (let ((uuid (org-entry-get (point) "ID")))
+ (when (string-match "\\`\\([^-]+\\)-" uuid)
+ (let ((prefix (match-string 1 uuid))
+ input output)
+ (save-restriction
+ (ledger-test-org-narrow-to-entry)
+ (goto-char (point-min))
+ (while (re-search-forward "#\\+begin_src ledger" nil t)
+ (goto-char (match-end 0))
+ (forward-line 1)
+ (let ((beg (point)))
+ (re-search-forward "#\\+end_src")
+ (setq input
+ (concat (or input "")
+ (buffer-substring beg (match-beginning 0))))))
+ (goto-char (point-min))
+ (while (re-search-forward ":OUTPUT:" nil t)
+ (goto-char (match-end 0))
+ (forward-line 1)
+ (let ((beg (point)))
+ (re-search-forward ":END:")
+ (setq output
+ (concat (or output "")
+ (buffer-substring beg (match-beginning 0)))))))
+ (find-file-other-window
+ (expand-file-name (concat prefix ".test")
+ (expand-file-name "test/regress"
+ ledger-source-directory)))
+ (ledger-mode)
+ (if input
+ (insert input)
+ (insert "2012-03-17 Payee\n")
+ (insert " Expenses:Food $20\n")
+ (insert " Assets:Cash\n"))
+ (insert "\ntest reg\n")
+ (if output
+ (insert output))
+ (insert "end test\n")))))
+
+(defun ledger-test-run ()
+ (interactive)
+ (save-excursion
+ (goto-char (point-min))
+ (when (re-search-forward "^test \\(.+?\\)\\( ->.*\\)?$" nil t)
+ (let ((command (expand-file-name ledger-test-binary))
+ (args (format "--args-only --columns=80 --no-color -f \"%s\" %s"
+ buffer-file-name (match-string 1))))
+ (setq args (replace-regexp-in-string "\\$sourcepath"
+ ledger-source-directory args))
+ (kill-new args)
+ (message "Testing: ledger %s" args)
+ (let ((prev-directory default-directory))
+ (cd ledger-source-directory)
+ (unwind-protect
+ (async-shell-command (format "\"%s\" %s" command args))
+ (cd prev-directory)))))))
+
+(provide 'ldg-test)
diff --git a/lisp/ledger.el b/lisp/ledger.el
index 1c8aade3..4fc21d6a 100644
--- a/lisp/ledger.el
+++ b/lisp/ledger.el
@@ -128,12 +128,12 @@ text that should replace the format specifier."
(defvar bold 'bold)
(defvar ledger-font-lock-keywords
- '(("\\( \\| \\|^\\)\\(;.*\\)" 2 font-lock-comment-face)
+ '(("\\( \\| \\|^\\)\\(;.*\\)" 2 font-lock-comment-face)
("^[0-9]+[-/.=][-/.=0-9]+\\s-+\\(([^)]+)\\s-+\\)?\\([^*].+?\\)\\(\\( ;\\| ;\\|$\\)\\)" 2 bold)
;;("^[0-9]+[-/.=][-/.=0-9]+\\s-+\\(([^)]+)\\s-+\\)?\\([*].+?\\)\\(\\( ;\\| ;\\|$\\)\\)"
;; 2 font-lock-type-face)
("^\\s-+\\([*]\\s-*\\)?\\(\\([[(]\\)?\\([^*;]\\)+?\\(:\\|\\s-\\)[^]);
- ]+?\\([])]\\)?\\)\\( \\| \\|$\\)"
+ ]+?\\([])]\\)?\\)\\( \\| \\|$\\)"
2 font-lock-keyword-face)
("^\\([~=].+\\)" 1 font-lock-function-name-face)
("^\\([A-Za-z]+ .+\\)" 1 font-lock-function-name-face))
@@ -545,7 +545,7 @@ dropped."
(defun ledger-reconcile-visit ()
(interactive)
(let ((where (get-text-property (point) 'where)))
- (when (or (equal (car where) "<stdin>") (equal (car where) "/dev/stdin"))
+ (when (markerp (cdr where))
(switch-to-buffer-other-window ledger-buf)
(goto-char (cdr where)))))