diff options
Diffstat (limited to 'lisp/ledger-xact.el')
-rw-r--r-- | lisp/ledger-xact.el | 43 |
1 files changed, 13 insertions, 30 deletions
diff --git a/lisp/ledger-xact.el b/lisp/ledger-xact.el index e747b6b2..0eb9386a 100644 --- a/lisp/ledger-xact.el +++ b/lisp/ledger-xact.el @@ -1,6 +1,6 @@ ;;; ledger-xact.el --- Helper code for use with the "ledger" command-line tool -;; Copyright (C) 2003-2014 John Wiegley (johnw AT gnu DOT org) +;; Copyright (C) 2003-2015 John Wiegley (johnw AT gnu DOT org) ;; This file is not part of GNU Emacs. @@ -25,6 +25,11 @@ ;;; Code: +(require 'eshell) +(require 'ledger-regex) +(require 'ledger-navigate) +;; TODO: This file depends on code in ledger-mode.el, which depends on this. + (defcustom ledger-highlight-xact-under-point t "If t highlight xact under point." :type 'boolean @@ -39,26 +44,10 @@ (defvar ledger-xact-highlight-overlay (list)) (make-variable-buffer-local 'ledger-xact-highlight-overlay) -(defun ledger-find-xact-extents (pos) - "Return point for beginning of xact and and of xact containing position. -Requires empty line separating xacts. Argument POS is a location -within the transaction." - (interactive "d") - (save-excursion - (goto-char pos) - (list (progn - (backward-paragraph) - (if (/= (point) (point-min)) - (forward-line)) - (line-beginning-position)) - (progn - (forward-paragraph) - (line-beginning-position))))) - (defun ledger-highlight-xact-under-point () "Move the highlight overlay to the current transaction." (if ledger-highlight-xact-under-point - (let ((exts (ledger-find-xact-extents (point))) + (let ((exts (ledger-navigate-find-element-extents (point))) (ovl ledger-xact-highlight-overlay)) (if (not ledger-xact-highlight-overlay) (setq ovl @@ -68,7 +57,7 @@ within the transaction." (current-buffer) t nil))) (move-overlay ovl (car exts) (cadr exts))) (overlay-put ovl 'face 'ledger-font-xact-highlight-face) - (overlay-put ovl 'priority 100)))) + (overlay-put ovl 'priority '(nil . 99))))) (defun ledger-xact-payee () "Return the payee of the transaction containing point or nil." @@ -98,7 +87,7 @@ MOMENT is an encoded date" (if (ledger-time-less-p moment date) (throw 'found t)))))) (when (and (eobp) last-xact-start) - (let ((end (cadr (ledger-find-xact-extents last-xact-start)))) + (let ((end (cadr (ledger-navigate-find-xact-extents last-xact-start)))) (goto-char end) (if (eobp) (insert "\n") @@ -129,11 +118,6 @@ MOMENT is an encoded date" mark desc))))) (forward-line)))) -(defun ledger-goto-line (line-number) - "Rapidly move point to line LINE-NUMBER." - (goto-char (point-min)) - (forward-line (1- line-number))) - (defun ledger-year-and-month () (let ((sep (if ledger-use-iso-dates "-" @@ -145,7 +129,7 @@ MOMENT is an encoded date" (interactive (list (ledger-read-date "Copy to date: "))) (let* ((here (point)) - (extents (ledger-find-xact-extents (point))) + (extents (ledger-navigate-find-xact-extents (point))) (transaction (buffer-substring-no-properties (car extents) (cadr extents))) encoded-date) (if (string-match ledger-iso-date-regexp date) @@ -155,7 +139,7 @@ MOMENT is an encoded date" (string-to-number (match-string 2 date))))) (ledger-xact-find-slot encoded-date) (insert transaction "\n") - (backward-paragraph 2) + (ledger-navigate-beginning-of-xact) (re-search-forward ledger-iso-date-regexp) (replace-match date) (ledger-next-amount) @@ -163,9 +147,9 @@ MOMENT is an encoded date" (goto-char (match-beginning 0))))) (defun ledger-delete-current-transaction (pos) - "Delete the transaction surrounging point." + "Delete the transaction surrounging POS." (interactive "d") - (let ((bounds (ledger-find-xact-extents pos))) + (let ((bounds (ledger-navigate-find-xact-extents pos))) (delete-region (car bounds) (cadr bounds)))) (defun ledger-add-transaction (transaction-text &optional insert-at-point) @@ -207,7 +191,6 @@ correct chronological place in the buffer." (insert (car args) " \n\n") (end-of-line -1))))) - (provide 'ledger-xact) ;;; ledger-xact.el ends here |