summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lisp/ledger-fontify.el38
-rw-r--r--lisp/ledger-mode.el4
-rw-r--r--lisp/ledger-sort.el25
-rw-r--r--lisp/ledger-xact.el38
4 files changed, 51 insertions, 54 deletions
diff --git a/lisp/ledger-fontify.el b/lisp/ledger-fontify.el
index 00fe249a..a820065d 100644
--- a/lisp/ledger-fontify.el
+++ b/lisp/ledger-fontify.el
@@ -35,29 +35,41 @@
:type 'boolean
:group 'ledger-fontification)
-(defun ledger-fontify-buffer-part (beg end len)
+(defun ledger-fontify-buffer-part (&optional beg end len)
+ ;; (message (concat "ledger-fontify-buffer-part: ("
+ ;; (int-to-string beg) ", "
+ ;; (int-to-string end)
+ ;; ")"))
(save-excursion
(unless beg (setq beg (point-min)))
(unless end (setq end (point-max)))
- (goto-char beg)
+ (beginning-of-line)
(while (< (point) end)
(cond ((or (looking-at ledger-xact-start-regex)
(looking-at ledger-posting-regex))
(ledger-fontify-xact-at (point)))
((looking-at ledger-directive-start-regex)
(ledger-fontify-directive-at (point))))
- (ledger-xact-next-xact-or-directive))))
+ (ledger-next-record-function))))
(defun ledger-fontify-xact-at (position)
(interactive "d")
- (let ((extents (ledger-find-xact-extents position))
- (state (ledger-transaction-state)))
- (if (and ledger-fontify-xact-state-overrides state)
- (cond ((eq state 'cleared)
- (ledger-fontify-set-face extents 'ledger-font-xact-cleared-face))
- ((eq state 'pending)
- (ledger-fontify-set-face extents 'ledger-font-xact-pending-face)))
- (ledger-fontify-xact-by-line extents))))
+ (save-excursion
+ (goto-char position)
+ (let ((extents (ledger-find-xact-extents position))
+ (state (ledger-transaction-state)))
+ ;; (message (concat "ledger-fontify-xact-at: "
+ ;; (int-to-string position)
+ ;; " ("
+ ;; (int-to-string (car extents)) ", "
+ ;; (int-to-string (cadr extents))
+ ;; ")"))
+ (if (and ledger-fontify-xact-state-overrides state)
+ (cond ((eq state 'cleared)
+ (ledger-fontify-set-face extents 'ledger-font-xact-cleared-face))
+ ((eq state 'pending)
+ (ledger-fontify-set-face extents 'ledger-font-xact-pending-face)))
+ (ledger-fontify-xact-by-line extents)))))
(defun ledger-fontify-xact-by-line (extents)
"do line-by-line detailed fontification of xact"
@@ -68,8 +80,9 @@
(forward-line))))
(defun ledger-fontify-xact-start (pos)
- (interactive "d")
+ "POS shoul dbe at the beginning of a line starting an xact"
(goto-char pos)
+ (beginning-of-line)
(let ((state nil))
(re-search-forward ledger-xact-start-regex)
(ledger-fontify-set-face (list (match-beginning 1) (match-end 1)) 'ledger-font-posting-date-face)
@@ -108,7 +121,6 @@
'ledger-font-comment-face)))
(defun ledger-fontify-directive-at (position)
- (interactive "d")
(let ((extents (ledger-find-xact-extents position))
(face 'ledger-font-default-face))
(cond ((looking-at "=")
diff --git a/lisp/ledger-mode.el b/lisp/ledger-mode.el
index cd1a587c..e7771f40 100644
--- a/lisp/ledger-mode.el
+++ b/lisp/ledger-mode.el
@@ -261,8 +261,8 @@ With a prefix argument, remove the effective date. "
(define-key map [(control ?c) (control ?o) (control ?r)] 'ledger-report)
(define-key map [(control ?c) (control ?o) (control ?s)] 'ledger-report-save)
- (define-key map [(meta ?p)] 'ledger-xact-prev-xact)
- (define-key map [(meta ?n)] 'ledger-xact-next-xact-or-directive)
+ (define-key map [(meta ?p)] 'ledger-prev-record-function)
+ (define-key map [(meta ?n)] 'ledger-next-record-function)
map)
"Keymap for `ledger-mode'.")
diff --git a/lisp/ledger-sort.el b/lisp/ledger-sort.el
index 10018149..41f8af3c 100644
--- a/lisp/ledger-sort.el
+++ b/lisp/ledger-sort.el
@@ -28,17 +28,34 @@
(defun ledger-next-record-function ()
"Move point to next transaction."
+ ;; make sure we actually move to the next xact, even if we are the
+ ;; beginning of one now.
(if (looking-at ledger-payee-any-status-regex)
- (forward-line)) ;; make sure we actually move to the next xact,
- ;; even if we are the beginning of one now.
+ (forward-line))
(if (re-search-forward ledger-payee-any-status-regex nil t)
(goto-char (match-beginning 0))
(goto-char (point-max))))
+(defun ledger-prev-record-function ()
+ "Move point to beginning of previous xact."
+ (ledger-beginning-record-function)
+ (re-search-backward ledger-xact-start-regex nil t))
+
+(defun ledger-beginning-record-function ()
+ "Move point to the beginning of the current xact"
+ (interactive)
+ (unless (looking-at ledger-xact-start-regex)
+ (re-search-backward ledger-xact-start-regex nil t)
+ (beginning-of-line))
+ (point))
+
(defun ledger-end-record-function ()
- "Move point to end of transaction."
+ "Move point to end of xact."
+ (interactive)
(ledger-next-record-function)
- (backward-char))
+ (backward-char)
+ (end-of-line)
+ (point))
(defun ledger-sort-find-start ()
(if (re-search-forward ";.*Ledger-mode:.*Start sort" nil t)
diff --git a/lisp/ledger-xact.el b/lisp/ledger-xact.el
index 277788e6..f38bec74 100644
--- a/lisp/ledger-xact.el
+++ b/lisp/ledger-xact.el
@@ -45,14 +45,8 @@ Requires empty line separating xacts."
(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)))))
+ (list (ledger-beginning-record-function)
+ (ledger-end-record-function))))
(defun ledger-highlight-xact-under-point ()
"Move the highlight overlay to the current transaction."
@@ -154,7 +148,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-beginning-record-function)
(re-search-forward ledger-iso-date-regexp)
(replace-match date)
(ledger-next-amount)
@@ -224,32 +218,6 @@ beginning with whitespace"
(ledger-xact-start-xact-or-directive-p)))
(forward-line))))
-(defun ledger-xact-prev-xact ()
- "Move point to the previous transaction."
- (interactive)
- (backward-paragraph)
- (when (re-search-backward ledger-xact-line-regexp nil t)
- (goto-char (match-beginning 0))
- (re-search-forward ledger-post-line-regexp)
- (goto-char (match-end ledger-regex-post-line-group-account))))
-
-;; (defun ledger-post-next-xact ()
-;; "Move point to the next transaction."
-;; (interactive)
-;; (when (re-search-forward ledger-xact-line-regexp nil t)
-;; (goto-char (match-beginning 0))
-;; (re-search-forward ledger-post-line-regexp)
-;; (goto-char (match-end ledger-regex-post-line-group-account))))
-
-;; (defun ledger-xact-next-xact ()
-;; (interactive)
-;; (beginning-of-line)
-;; (if (looking-at ledger-xact-start-regex)
-;; (forward-line))
-;; (re-search-forward ledger-xact-start-regex)
-;; (forward-line -1))
-
-
(provide 'ledger-xact)
;;; ledger-xact.el ends here