diff options
author | John Wiegley <johnw@newartisans.com> | 2012-08-08 00:34:07 -0500 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2012-08-08 00:34:07 -0500 |
commit | e716995311076464e65ed402a9000892e8012d2e (patch) | |
tree | 6e873311f59bf6fbca4ebe3a81f8e79d134d92f2 | |
parent | a54ee9047b11b52e6bc1edf1431d65977ea9f714 (diff) | |
download | fork-ledger-e716995311076464e65ed402a9000892e8012d2e.tar.gz fork-ledger-e716995311076464e65ed402a9000892e8012d2e.tar.bz2 fork-ledger-e716995311076464e65ed402a9000892e8012d2e.zip |
Patch reports with markers to allow xact shifting
-rw-r--r-- | lisp/ldg-mode.el | 4 | ||||
-rw-r--r-- | lisp/ldg-report.el | 48 |
2 files changed, 46 insertions, 6 deletions
diff --git a/lisp/ldg-mode.el b/lisp/ldg-mode.el index 4d13d7d2..6090a312 100644 --- a/lisp/ldg-mode.el +++ b/lisp/ldg-mode.el @@ -51,7 +51,9 @@ (define-key map [tab] 'pcomplete) (define-key map [(control ?i)] 'pcomplete) (define-key map [(control ?c) tab] 'ledger-fully-complete-entry) - (define-key map [(control ?c) (control ?i)] 'ledger-fully-complete-entry))) + (define-key map [(control ?c) (control ?i)] 'ledger-fully-complete-entry)) + + (ledger-report-patch-reports (current-buffer))) (defun ledger-time-less-p (t1 t2) "Say whether time value T1 is less than time value T2." diff --git a/lisp/ldg-report.el b/lisp/ldg-report.el index 9a51c32c..f9c6afca 100644 --- a/lisp/ldg-report.el +++ b/lisp/ldg-report.el @@ -231,6 +231,28 @@ the default." (ledger-reports-custom-save)) report-cmd)) +(defvar ledger-report-patch-alist nil) + +(defun ledger-report-patch-reports (buf) + (when ledger-report-patch-alist + (let ((entry (assoc (expand-file-name (buffer-file-name buf)) + ledger-report-patch-alist))) + (when entry + (dolist (b (cdr entry)) + (if (buffer-live-p b) + (with-current-buffer b + (save-excursion + (goto-char (point-min)) + (while (not (eobp)) + (let ((record (get-text-property (point) 'ledger-source))) + (if (and record (not (markerp (cdr record)))) + (setcdr record (with-current-buffer buf + (save-excursion + (goto-char (point-min)) + (forward-line (cdr record)) + (point-marker)))))) + (forward-line 1)))))))))) + (defun ledger-do-report (cmd) "Run a report command line." (goto-char (point-min)) @@ -238,7 +260,8 @@ the default." (format "Command: %s\n" cmd) (make-string (- (window-width) 1) ?=) "\n") - (let ((register-report (string-match " reg\\(ister\\)? " cmd))) + (let ((register-report (string-match " reg\\(ister\\)? " cmd)) + files-in-report) (shell-command (if register-report (concat cmd " --prepend-format='%(filename):%(beg_line):'") @@ -250,15 +273,30 @@ the default." (line (string-to-number (match-string 2)))) (delete-region (match-beginning 0) (match-end 0)) (set-text-properties (line-beginning-position) (line-end-position) - (list 'ledger-source (cons file line)))))))) + (list 'ledger-source (cons file line))) + (let* ((fullpath (expand-file-name file)) + (entry (assoc fullpath ledger-report-patch-alist))) + (if entry + (nconc (cdr entry) (list (current-buffer))) + (push (cons (expand-file-name file) + (list (current-buffer))) + ledger-report-patch-alist)) + (add-to-list 'files-in-report fullpath))) + + (dolist (path files-in-report) + (let ((buf (get-file-buffer path))) + (if (and buf (buffer-live-p buf)) + (ledger-report-patch-reports buf)))))))) (defun ledger-report-visit-source () (interactive) (let ((prop (get-text-property (point) 'ledger-source))) - (destructuring-bind (file . line) prop + (destructuring-bind (file . line-or-marker) prop (find-file-other-window file) - (goto-char (point-min)) - (forward-line (1- line))))) + (if (markerp line-or-marker) + (goto-char line-or-marker) + (goto-char (point-min)) + (forward-line (1- line-or-marker)))))) (defun ledger-report-goto () "Goto the ledger report buffer." |