summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ldg-mode.el2
-rw-r--r--lisp/ldg-new.el4
-rw-r--r--lisp/ldg-post.el9
-rw-r--r--lisp/ldg-regex.el152
-rw-r--r--lisp/ldg-register.el3
5 files changed, 90 insertions, 80 deletions
diff --git a/lisp/ldg-mode.el b/lisp/ldg-mode.el
index 625d9f49..c6f15eed 100644
--- a/lisp/ldg-mode.el
+++ b/lisp/ldg-mode.el
@@ -22,6 +22,8 @@
;;;###autoload
(define-derived-mode ledger-mode text-mode "Ledger"
"A mode for editing ledger data files."
+ (ledger-post-setup)
+
(set (make-local-variable 'comment-start) " ; ")
(set (make-local-variable 'comment-end) "")
(set (make-local-variable 'indent-tabs-mode) nil)
diff --git a/lisp/ldg-new.el b/lisp/ldg-new.el
index fce25984..a515d94f 100644
--- a/lisp/ldg-new.el
+++ b/lisp/ldg-new.el
@@ -34,6 +34,10 @@
(require 'ldg-post)
+(autoload #'ledger-mode "ldg-mode" nil t)
+
+(autoload #'ledger-fully-complete-entry "ldg-complete" nil t)
+
(autoload #'ledger-texi-update-test "ldg-texi" nil t)
(autoload #'ledger-texi-update-examples "ldg-texi" nil t)
diff --git a/lisp/ldg-post.el b/lisp/ldg-post.el
index 2d7a0e05..492f9467 100644
--- a/lisp/ldg-post.el
+++ b/lisp/ldg-post.el
@@ -83,6 +83,13 @@ to choose from."
(delete-char 1)))))))
(goto-char pos)))
+(defun ledger-next-amount (&optional end)
+ (when (re-search-forward "\\( \\|\t\\| \t\\)[ \t]*-?\\([A-Z$]+ *\\)?\\(-?[0-9,]+?\\)\\(.[0-9]+\\)?\\( *[A-Z$]+\\)?\\([ \t]*@@?[^\n;]+?\\)?\\([ \t]+;.+?\\)?$" (marker-position end) t)
+ (goto-char (match-beginning 0))
+ (skip-syntax-forward " ")
+ (- (or (match-end 4)
+ (match-end 3)) (point))))
+
(defun ledger-align-amounts (&optional column)
"Align amounts in the current region.
This is done so that the last digit falls in COLUMN, which defaults to 52."
@@ -164,6 +171,4 @@ This is done so that the last digit falls in COLUMN, which defaults to 52."
(add-hook 'after-change-functions 'ledger-post-maybe-align t t))
(add-hook 'after-save-hook #'(lambda () (setq ledger-post-current-list nil))))
-(add-hook 'ledger-mode-hook 'ledger-post-setup)
-
(provide 'ldg-post)
diff --git a/lisp/ldg-regex.el b/lisp/ldg-regex.el
index 15226ef1..93ef6b09 100644
--- a/lisp/ldg-regex.el
+++ b/lisp/ldg-regex.el
@@ -96,64 +96,64 @@
(cons 'progn defs)))
-(put 'ledger-define-regexp 'lisp-indent-function 2)
+(put 'ledger-define-regexp 'lisp-indent-function 1)
(ledger-define-regexp date
- (let ((sep '(or ?- (any ?. ?/)))) ; can't do (any ?- ?. ?/) due to bug
- (rx (group
- (and (? (= 4 num)
- (eval sep))
- (and num (? num))
- (eval sep)
- (and num (? num))))))
+ (let ((sep '(or ?- (any ?. ?/)))) ; can't do (any ?- ?. ?/) due to bug
+ (rx (group
+ (and (? (= 4 num)
+ (eval sep))
+ (and num (? num))
+ (eval sep)
+ (and num (? num))))))
"Match a single date, in its 'written' form.")
(ledger-define-regexp full-date
- (macroexpand
- `(rx (and (regexp ,ledger-date-regexp)
- (? (and ?= (regexp ,ledger-date-regexp))))))
+ (macroexpand
+ `(rx (and (regexp ,ledger-date-regexp)
+ (? (and ?= (regexp ,ledger-date-regexp))))))
"Match a compound date, of the form ACTUAL=EFFECTIVE"
(actual date)
(effective date))
(ledger-define-regexp state
- (rx (group (any ?! ?*)))
+ (rx (group (any ?! ?*)))
"Match a transaction or posting's \"state\" character.")
(ledger-define-regexp code
- (rx (and ?\( (group (+? (not (any ?\))))) ?\)))
+ (rx (and ?\( (group (+? (not (any ?\))))) ?\)))
"Match the transaction code.")
(ledger-define-regexp long-space
- (rx (and (*? blank)
- (or (and ? (or ? ?\t)) ?\t)))
+ (rx (and (*? blank)
+ (or (and ? (or ? ?\t)) ?\t)))
"Match a \"long space\".")
(ledger-define-regexp note
- (rx (group (+ nonl)))
+ (rx (group (+ nonl)))
"")
(ledger-define-regexp end-note
- (macroexpand
- `(rx (and (regexp ,ledger-long-space-regexp) ?\;
- (regexp ,ledger-note-regexp))))
+ (macroexpand
+ `(rx (and (regexp ,ledger-long-space-regexp) ?\;
+ (regexp ,ledger-note-regexp))))
"")
(ledger-define-regexp full-note
- (macroexpand
- `(rx (and line-start (+ blank)
- ?\; (regexp ,ledger-note-regexp))))
+ (macroexpand
+ `(rx (and line-start (+ blank)
+ ?\; (regexp ,ledger-note-regexp))))
"")
(ledger-define-regexp xact-line
- (macroexpand
- `(rx (and line-start
- (regexp ,ledger-full-date-regexp)
- (? (and (+ blank) (regexp ,ledger-state-regexp)))
- (? (and (+ blank) (regexp ,ledger-code-regexp)))
- (+ blank) (+? nonl)
- (? (regexp ,ledger-end-note-regexp))
- line-end)))
+ (macroexpand
+ `(rx (and line-start
+ (regexp ,ledger-full-date-regexp)
+ (? (and (+ blank) (regexp ,ledger-state-regexp)))
+ (? (and (+ blank) (regexp ,ledger-code-regexp)))
+ (+ blank) (+? nonl)
+ (? (regexp ,ledger-end-note-regexp))
+ line-end)))
"Match a transaction's first line (and optional notes)."
(actual-date full-date actual)
(effective-date full-date effective)
@@ -162,84 +162,84 @@
(note end-note))
(ledger-define-regexp account
- (rx (group (and (not (any blank ?\[ ?\( ?: ?\;)) (*? nonl))))
+ (rx (group (and (not (any blank ?\[ ?\( ?: ?\;)) (*? nonl))))
"")
(ledger-define-regexp account-kind
- (rx (group (? (any ?\[ ?\())))
+ (rx (group (? (any ?\[ ?\())))
"")
(ledger-define-regexp full-account
- (macroexpand
- `(rx (and (regexp ,ledger-account-kind-regexp)
- (regexp ,ledger-account-regexp)
- (? (any ?\] ?\))))))
+ (macroexpand
+ `(rx (and (regexp ,ledger-account-kind-regexp)
+ (regexp ,ledger-account-regexp)
+ (? (any ?\] ?\))))))
""
(kind account-kind)
(name account))
(ledger-define-regexp commodity
- (rx (group
- (or (and ?\" (+ (not (any ?\"))) ?\")
- (not (any blank ?\n
- digit
- ?- ?\[ ?\]
- ?. ?, ?\; ?+ ?* ?/ ?^ ?? ?: ?& ?| ?! ?=
- ?\< ?\> ?\{ ?\} ?\( ?\) ?@)))))
+ (rx (group
+ (or (and ?\" (+ (not (any ?\"))) ?\")
+ (not (any blank ?\n
+ digit
+ ?- ?\[ ?\]
+ ?. ?, ?\; ?+ ?* ?/ ?^ ?? ?: ?& ?| ?! ?=
+ ?\< ?\> ?\{ ?\} ?\( ?\) ?@)))))
"")
(ledger-define-regexp amount
- (rx (group
- (and (? ?-)
- (and (+ digit)
- (*? (and (any ?. ?,) (+ digit))))
- (? (and (any ?. ?,) (+ digit))))))
+ (rx (group
+ (and (? ?-)
+ (and (+ digit)
+ (*? (and (any ?. ?,) (+ digit))))
+ (? (and (any ?. ?,) (+ digit))))))
"")
(ledger-define-regexp commoditized-amount
- (macroexpand
- `(rx (group
- (or (and (regexp ,ledger-commodity-regexp)
- (*? blank)
- (regexp ,ledger-amount-regexp))
- (and (regexp ,ledger-amount-regexp)
- (*? blank)
- (regexp ,ledger-commodity-regexp))))))
+ (macroexpand
+ `(rx (group
+ (or (and (regexp ,ledger-commodity-regexp)
+ (*? blank)
+ (regexp ,ledger-amount-regexp))
+ (and (regexp ,ledger-amount-regexp)
+ (*? blank)
+ (regexp ,ledger-commodity-regexp))))))
"")
(ledger-define-regexp commodity-annotations
- (macroexpand
- `(rx (* (+ blank)
- (or (and ?\{ (regexp ,ledger-commoditized-amount-regexp) ?\})
- (and ?\[ (regexp ,ledger-date-regexp) ?\])
- (and ?\( (not (any ?\))) ?\))))))
+ (macroexpand
+ `(rx (* (+ blank)
+ (or (and ?\{ (regexp ,ledger-commoditized-amount-regexp) ?\})
+ (and ?\[ (regexp ,ledger-date-regexp) ?\])
+ (and ?\( (not (any ?\))) ?\))))))
"")
(ledger-define-regexp cost
- (macroexpand
- `(rx (and (or "@" "@@") (+ blank)
- (regexp ,ledger-commoditized-amount-regexp))))
+ (macroexpand
+ `(rx (and (or "@" "@@") (+ blank)
+ (regexp ,ledger-commoditized-amount-regexp))))
"")
(ledger-define-regexp balance-assertion
- (macroexpand
- `(rx (and ?= (+ blank)
- (regexp ,ledger-commoditized-amount-regexp))))
+ (macroexpand
+ `(rx (and ?= (+ blank)
+ (regexp ,ledger-commoditized-amount-regexp))))
"")
(ledger-define-regexp full-amount
- (macroexpand `(rx (group (+? (not (any ?\;))))))
+ (macroexpand `(rx (group (+? (not (any ?\;))))))
"")
(ledger-define-regexp post-line
- (macroexpand
- `(rx (and line-start (+ blank)
- (? (and (regexp ,ledger-state-regexp) (* blank)))
- (regexp ,ledger-full-account-regexp)
- (? (and (regexp ,ledger-long-space-regexp)
- (regexp ,ledger-full-amount-regexp)))
- (? (regexp ,ledger-end-note-regexp))
- line-end)))
+ (macroexpand
+ `(rx (and line-start (+ blank)
+ (? (and (regexp ,ledger-state-regexp) (* blank)))
+ (regexp ,ledger-full-account-regexp)
+ (? (and (regexp ,ledger-long-space-regexp)
+ (regexp ,ledger-full-amount-regexp)))
+ (? (regexp ,ledger-end-note-regexp))
+ line-end)))
""
state
(account-kind full-account kind)
diff --git a/lisp/ldg-register.el b/lisp/ldg-register.el
index 93611345..02e50de9 100644
--- a/lisp/ldg-register.el
+++ b/lisp/ldg-register.el
@@ -57,8 +57,7 @@
(let ((pos (point))
(inhibit-read-only t))
(erase-buffer)
- (ledger-register-render
- buf (apply #'ledger-exec-read buf args))
+ (ledger-register-render buf (apply #'ledger-exec-read buf args))
(goto-char pos))
(set-buffer-modified-p nil)
(toggle-read-only t)