summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Kettleborough <g.kettleborough@member.fsf.org>2013-04-13 21:57:03 +0100
committerGeorge Kettleborough <g.kettleborough@member.fsf.org>2013-04-13 21:57:03 +0100
commite604fe5cbb50a70d9c938c5076b2f971145328ec (patch)
treee43387dfbbd80629b7f3d36dbdbec5ffb1fce7d1
parent902d0f41ef610ab54786db7c859dbc86c4f6e1db (diff)
downloadfork-ledger-e604fe5cbb50a70d9c938c5076b2f971145328ec.tar.gz
fork-ledger-e604fe5cbb50a70d9c938c5076b2f971145328ec.tar.bz2
fork-ledger-e604fe5cbb50a70d9c938c5076b2f971145328ec.zip
Allow completion on accounts and metadata
-rw-r--r--lisp/ldg-complete.el24
-rw-r--r--lisp/ldg-mode.el17
2 files changed, 33 insertions, 8 deletions
diff --git a/lisp/ldg-complete.el b/lisp/ldg-complete.el
index bd907bc8..3ba35909 100644
--- a/lisp/ldg-complete.el
+++ b/lisp/ldg-complete.el
@@ -38,6 +38,11 @@
(point)))
(end (point))
begins args)
+ ;; to support end of line metadata
+ (save-excursion
+ (when (search-backward ";"
+ (line-beginning-position) t)
+ (setq begin (match-beginning 0))))
(save-excursion
(goto-char begin)
(when (< (point) end)
@@ -73,7 +78,7 @@ Return tree structure"
(save-excursion
(goto-char (point-min))
(while (re-search-forward
- ledger-account-any-status-regex nil t)
+ ledger-account-or-metadata-regex nil t)
(unless (and (>= origin (match-beginning 0))
(< origin (match-end 0)))
(setq account-elements
@@ -90,6 +95,21 @@ Return tree structure"
(setq account-elements (cdr account-elements)))))))
account-tree))
+(defun ledger-find-metadata-in-buffer ()
+ "Search through buffer and build list of metadata.
+Return list."
+ (let ((origin (point)) accounts)
+ (save-excursion
+ (setq ledger-account-tree (list t))
+ (goto-char (point-min))
+ (while (re-search-forward
+ ledger-metadata-regex
+ nil t)
+ (unless (and (>= origin (match-beginning 0))
+ (< origin (match-end 0)))
+ (setq accounts (cons (match-string-no-properties 2) accounts)))))
+ accounts))
+
(defun ledger-accounts ()
"Return a tree of all accounts in the buffer."
(let* ((current (caar (ledger-parse-arguments)))
@@ -157,7 +177,7 @@ Does not use ledger xact"
(setq rest-of-name (match-string 3))
;; Start copying the postings
(forward-line)
- (while (looking-at ledger-account-any-status-regex)
+ (while (looking-at ledger-account-or-metadata-regex)
(setq xacts (cons (buffer-substring-no-properties
(line-beginning-position)
(line-end-position))
diff --git a/lisp/ldg-mode.el b/lisp/ldg-mode.el
index 4bc195ed..86889dda 100644
--- a/lisp/ldg-mode.el
+++ b/lisp/ldg-mode.el
@@ -68,13 +68,18 @@ And calculate the target-delta of the account being reconciled."
(message balance))))
(defun ledger-magic-tab (&optional interactively)
- "Decide what to with with <TAB> .
-Can be pcomplete, or align-posting"
+ "Decide what to with with <TAB>.
+Can indent, complete or align depending on context."
(interactive "p")
- (if (and (> (point) 1)
- (looking-back "[:A-Za-z0-9]" 1))
- (ledger-pcomplete interactively)
- (ledger-post-align-postings)))
+ (when (= (point) (line-end-position))
+ (if (= (point) (line-beginning-position))
+ (indent-to ledger-post-account-alignment-column)
+ (save-excursion
+ (re-search-backward ledger-account-or-metadata-regex
+ (line-beginning-position) t))
+ (when (= (point) (match-end 0))
+ (ledger-pcomplete interactively))))
+ (ledger-post-align-postings))
(defvar ledger-mode-abbrev-table)