everything appears to work with no empty lines between xacts.

This commit is contained in:
Craig Earls 2014-09-13 17:11:40 -07:00
parent 20dd0b706a
commit 84dc532b06
4 changed files with 51 additions and 54 deletions

View file

@ -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")
(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))))
(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 "=")

View file

@ -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'.")

View file

@ -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)

View file

@ -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