Skip to content

Commit

Permalink
Speed up adding ledger report links
Browse files Browse the repository at this point in the history
Closes ledger#122

Bug#192
  • Loading branch information
jabranham committed Sep 21, 2019
1 parent 1d229f8 commit 47a186e
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions ledger-report.el
Original file line number Diff line number Diff line change
Expand Up @@ -480,16 +480,13 @@ Optionally EDIT the command."
"Replace file and line annotations with buttons."
(while (re-search-forward "^\\(/[^:]+\\)?:\\([0-9]+\\)?:" nil t)
(let ((file (match-string 1))
(line (string-to-number (match-string 2))))
(delete-region (match-beginning 0) (match-end 0))
(when file
(line (string-to-number (match-string 2)))
(beg (match-beginning 0))
(end (match-end 0)))
(when (and file line beg end)
(delete-region beg end)
(add-text-properties (line-beginning-position) (line-end-position)
(list 'ledger-source (cons file (save-window-excursion
(save-excursion
(find-file file)
(widen)
(ledger-navigate-to-line line)
(point-marker))))))
(list 'ledger-source (cons file line)))
(make-text-button
(line-beginning-position) (line-end-position)
'type 'ledger-report-register-entry
Expand Down Expand Up @@ -538,21 +535,14 @@ arguments returned by `ledger-report--compute-extra-args'."
"Visit the transaction under point in the report window."
(interactive)
(let* ((prop (get-text-property (point) 'ledger-source))
(file (if prop (car prop)))
(line-or-marker (if prop (cdr prop))))
(when (and file line-or-marker)
(file (car prop))
(line (cdr prop)))
(when (and file line)
(find-file-other-window file)
(widen)
(if (markerp line-or-marker)
(goto-char line-or-marker)
(goto-char (point-min))
(forward-line (1- line-or-marker))
(re-search-backward "^[0-9]+")
(beginning-of-line)
(let ((start-of-txn (point)))
(forward-paragraph)
(narrow-to-region start-of-txn (point))
(backward-paragraph))))))
(goto-char (point-min))
(forward-line (1- line))
(ledger-navigate-beginning-of-xact))))

(defun ledger-report-goto ()
"Goto the ledger report buffer."
Expand Down

0 comments on commit 47a186e

Please sign in to comment.