summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ledger-fontify.el39
-rw-r--r--lisp/ledger-regex.el8
-rw-r--r--lisp/ledger-state.el10
3 files changed, 30 insertions, 27 deletions
diff --git a/lisp/ledger-fontify.el b/lisp/ledger-fontify.el
index d9e74cff..ea873d91 100644
--- a/lisp/ledger-fontify.el
+++ b/lisp/ledger-fontify.el
@@ -76,26 +76,27 @@
(forward-line))))
(defun ledger-fontify-xact-start (pos)
- "POS should be at the beginning of a line starting an xact.
+ "POS should be at the beginning of a line starting an xact.
Fontify the first line of an xact"
- (goto-char pos)
- (beginning-of-line)
- (let ((state nil)
- (cur-point (point)))
- (re-search-forward " ")
- (ledger-fontify-set-face (list cur-point (point)) 'ledger-font-posting-date-face)
- (beginning-of-line)
- (re-search-forward ledger-xact-after-date-regex)
- (save-match-data (setq state (ledger-state-from-string (match-string 1))))
- (ledger-fontify-set-face (list (match-beginning 1) (match-end 3))
- (cond ((eq state 'pending)
- 'ledger-font-payee-pending-face)
- ((eq state 'cleared)
- 'ledger-font-payee-cleared-face)
- (t
- 'ledger-font-payee-uncleared-face)))
- (ledger-fontify-set-face (list (match-beginning 4)
- (match-end 4)) 'ledger-font-comment-face)))
+ (goto-char pos)
+ (let ((line-start (line-beginning-position)))
+ (goto-char line-start)
+ (re-search-forward "[ \t]")
+ (ledger-fontify-set-face (list line-start (match-beginning 0)) 'ledger-font-posting-date-face)
+ (goto-char line-start)
+ (re-search-forward ledger-xact-after-date-regex)
+ (let ((state (save-match-data (ledger-state-from-string (match-string 1)))))
+ (ledger-fontify-set-face (list (match-beginning 3) (match-end 3))
+ (cond ((eq state 'pending)
+ 'ledger-font-payee-pending-face)
+ ((eq state 'cleared)
+ 'ledger-font-payee-cleared-face)
+ (t
+ 'ledger-font-payee-uncleared-face))))
+ (when (match-beginning 4)
+ (ledger-fontify-set-face (list (match-beginning 4)
+ (match-end 4)) 'ledger-font-comment-face))
+ (forward-line)))
(defun ledger-fontify-posting (pos)
"Fontify the posting at POS."
diff --git a/lisp/ledger-regex.el b/lisp/ledger-regex.el
index 1ff731fc..99655716 100644
--- a/lisp/ledger-regex.el
+++ b/lisp/ledger-regex.el
@@ -338,10 +338,10 @@
))
(defconst ledger-xact-after-date-regex
- (concat " ?\\([ *!]\\)" ;; mark, subexp 1
- " ?\\((.*)\\)?" ;; code, subexp 2
- " ?\\([^;\n]+\\)" ;; desc, subexp 3
- "\\(\n\\|;.*\\)" ;; comment, subexp 4
+ (concat "\\([ \t]+[*!]\\)?" ;; mark, subexp 1
+ "\\([ \t]+(.*?)\\)?" ;; code, subexp 2
+ "\\([ \t]+[^;\n]+\\)" ;; desc, subexp 3
+ "\\(;[^\n]*\\)?" ;; comment, subexp 4
))
(defconst ledger-posting-regex
diff --git a/lisp/ledger-state.el b/lisp/ledger-state.el
index b2574b10..8fe84053 100644
--- a/lisp/ledger-state.el
+++ b/lisp/ledger-state.el
@@ -68,10 +68,12 @@
(defun ledger-state-from-string (state-string)
"Get state from STATE-CHAR."
- (cond ((string-match "\\!" state-string) 'pending)
- ((string-match "\\*" state-string) 'cleared)
- ((string-match ";" state-string) 'comment)
- (t nil)))
+ (when state-string
+ (cond
+ ((string-match "\\!" state-string) 'pending)
+ ((string-match "\\*" state-string) 'cleared)
+ ((string-match ";" state-string) 'comment)
+ (t nil))))
(defun ledger-toggle-current-posting (&optional style)
"Toggle the cleared status of the transaction under point.