summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Purcell <steve@sanityinc.com>2019-07-02 10:55:58 +1200
committerSteve Purcell <steve@sanityinc.com>2019-07-05 08:17:40 +1200
commit739b777ff597d7680778dfb0777f795091392cf0 (patch)
tree54b80c5bdb781cd3febf0c0f0799739430439533
parent78ab0095621150833292dfb2aa0e1338f9044ea7 (diff)
Match account names more liberally for the sake of completion
See #141
-rw-r--r--ledger-complete.el2
-rw-r--r--ledger-regex.el21
2 files changed, 9 insertions, 14 deletions
diff --git a/ledger-complete.el b/ledger-complete.el
index a62883f..9a2eb04 100644
--- a/ledger-complete.el
+++ b/ledger-complete.el
@@ -117,7 +117,7 @@ Considers both accounts listed in postings and those declared with \"account\" d
(goto-char (point-min))
(let (results)
(while (re-search-forward ledger-account-name-or-directive-regex nil t)
- (setq results (cons (match-string-no-properties 2) results)))
+ (setq results (cons (match-string-no-properties 1) results)))
(ledger-accounts-deduplicate-sorted
(sort results #'ledger-string-greaterp)))))
diff --git a/ledger-regex.el b/ledger-regex.el
index 9d858c8..e8b004e 100644
--- a/ledger-regex.el
+++ b/ledger-regex.el
@@ -71,28 +71,23 @@
(defconst ledger-init-string-regex
"^--.+?\\($\\|[ ]\\)")
-(defconst ledger-account-directive-regex
- "^account [ \t]*\\(?2:[^;]+?\\)\\(?3:[ \t]*\\)\\(;.*\\)?$")
+(defconst ledger-account-name-regex
+ "\\([^;[:space:]\r\n]+\\(?: [^;[:space:]\r\n]+\\)*\\)")
-(defconst ledger-account-any-status-no-trailing-spaces-regex
- "^[ \t]+\\(?1:[*!]\\s-+\\)?[[(]?\\(?2:[^; ].+?\\)[])]?")
+(defconst ledger-account-directive-regex
+ (concat "^account[ \t]+" ledger-account-name-regex))
(defconst ledger-account-any-status-regex
- (format "%s%s"
- ledger-account-any-status-no-trailing-spaces-regex
- "\\(?3:\t\\| [ \t]\\|$\\)"))
+ (concat "^[[:space:]]+\\(?:[!*][[:space:]]*\\)?" ledger-account-name-regex))
(defconst ledger-account-name-or-directive-regex
- (format "\\(?:%s\\|%s\\(?3:\t\\| [ \t]\\)\\)"
- ledger-account-directive-regex
- ledger-account-any-status-no-trailing-spaces-regex))
+ (concat "^\\(?:[[:space:]]+\\(?:[!*][[:space:]]*\\)?\\|account[ \t]+\\)" ledger-account-name-regex))
(defconst ledger-account-pending-regex
- "\\(^[ \t]+\\)\\(!\\s-*[^ ].*?\\)\\( \\|\t\\|$\\)")
+ (concat "\\(^[[:space:]]+\\)!" ledger-account-name-regex))
(defconst ledger-account-cleared-regex
- "\\(^[ \t]+\\)\\(*\\s-*[^ ].*?\\)\\( \\|\t\\|$\\)")
-
+ (concat "\\(^[[:space:]]+\\)*" ledger-account-name-regex))
(defmacro ledger-define-regexp (name regex docs &rest args)
"Simplify the creation of a Ledger regex and helper functions."