Merge pull request #172 from georgek/regex
Looks good. Thanks for cleaning up the regexes. Separating the metadata form the account completion seems likely needless added complexity. What does it get us?
This commit is contained in:
commit
b2c88149cb
4 changed files with 47 additions and 13 deletions
|
|
@ -38,6 +38,11 @@
|
||||||
(point)))
|
(point)))
|
||||||
(end (point))
|
(end (point))
|
||||||
begins args)
|
begins args)
|
||||||
|
;; to support end of line metadata
|
||||||
|
(save-excursion
|
||||||
|
(when (search-backward ";"
|
||||||
|
(line-beginning-position) t)
|
||||||
|
(setq begin (match-beginning 0))))
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(goto-char begin)
|
(goto-char begin)
|
||||||
(when (< (point) end)
|
(when (< (point) end)
|
||||||
|
|
@ -73,7 +78,7 @@ Return tree structure"
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(while (re-search-forward
|
(while (re-search-forward
|
||||||
ledger-account-any-status-regex nil t)
|
ledger-account-or-metadata-regex nil t)
|
||||||
(unless (and (>= origin (match-beginning 0))
|
(unless (and (>= origin (match-beginning 0))
|
||||||
(< origin (match-end 0)))
|
(< origin (match-end 0)))
|
||||||
(setq account-elements
|
(setq account-elements
|
||||||
|
|
@ -90,6 +95,21 @@ Return tree structure"
|
||||||
(setq account-elements (cdr account-elements)))))))
|
(setq account-elements (cdr account-elements)))))))
|
||||||
account-tree))
|
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 ()
|
(defun ledger-accounts ()
|
||||||
"Return a tree of all accounts in the buffer."
|
"Return a tree of all accounts in the buffer."
|
||||||
(let* ((current (caar (ledger-parse-arguments)))
|
(let* ((current (caar (ledger-parse-arguments)))
|
||||||
|
|
@ -157,7 +177,7 @@ Does not use ledger xact"
|
||||||
(setq rest-of-name (match-string 3))
|
(setq rest-of-name (match-string 3))
|
||||||
;; Start copying the postings
|
;; Start copying the postings
|
||||||
(forward-line)
|
(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
|
(setq xacts (cons (buffer-substring-no-properties
|
||||||
(line-beginning-position)
|
(line-beginning-position)
|
||||||
(line-end-position))
|
(line-end-position))
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@
|
||||||
(defvar ledger-font-lock-keywords
|
(defvar ledger-font-lock-keywords
|
||||||
`( ;; (,ledger-other-entries-regex 1
|
`( ;; (,ledger-other-entries-regex 1
|
||||||
;; ledger-font-other-face)
|
;; ledger-font-other-face)
|
||||||
(,ledger-comment-regex 2
|
(,ledger-comment-regex 0
|
||||||
'ledger-font-comment-face)
|
'ledger-font-comment-face)
|
||||||
(,ledger-payee-pending-regex 2
|
(,ledger-payee-pending-regex 2
|
||||||
'ledger-font-payee-pending-face) ; Works
|
'ledger-font-payee-pending-face) ; Works
|
||||||
|
|
|
||||||
|
|
@ -68,13 +68,18 @@ And calculate the target-delta of the account being reconciled."
|
||||||
(message balance))))
|
(message balance))))
|
||||||
|
|
||||||
(defun ledger-magic-tab (&optional interactively)
|
(defun ledger-magic-tab (&optional interactively)
|
||||||
"Decide what to with with <TAB> .
|
"Decide what to with with <TAB>.
|
||||||
Can be pcomplete, or align-posting"
|
Can indent, complete or align depending on context."
|
||||||
(interactive "p")
|
(interactive "p")
|
||||||
(if (and (> (point) 1)
|
(when (= (point) (line-end-position))
|
||||||
(looking-back "[:A-Za-z0-9]" 1))
|
(if (= (point) (line-beginning-position))
|
||||||
(ledger-pcomplete interactively)
|
(indent-to ledger-post-account-alignment-column)
|
||||||
(ledger-post-align-postings)))
|
(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)
|
(defvar ledger-mode-abbrev-table)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@
|
||||||
"\\(^[~=A-Za-z].+\\)+")
|
"\\(^[~=A-Za-z].+\\)+")
|
||||||
|
|
||||||
(defconst ledger-comment-regex
|
(defconst ledger-comment-regex
|
||||||
"\\( \\| \\|^\\)\\(;.*\\)")
|
"^[;#|\\*%].*\\|[ \t]+;.*")
|
||||||
|
|
||||||
(defconst ledger-payee-any-status-regex
|
(defconst ledger-payee-any-status-regex
|
||||||
"^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.*?)\\)?\\s-+\\(.+?\\)\\(\t\\|\n\\| [ \t]\\)")
|
"^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.*?)\\)?\\s-+\\(.+?\\)\\(\t\\|\n\\| [ \t]\\)")
|
||||||
|
|
@ -61,13 +61,22 @@
|
||||||
"^--.+?\\($\\|[ ]\\)")
|
"^--.+?\\($\\|[ ]\\)")
|
||||||
|
|
||||||
(defconst ledger-account-any-status-regex
|
(defconst ledger-account-any-status-regex
|
||||||
"^[ \t]+\\([*!]\\s-+\\)?\\([[(]?.+?\\)\\(\t\\|\n\\| [ \t]\\)")
|
"^[ \t]+\\(?1:[*!]\\s-*\\)?\\(?2:[^ ;].*?\\)\\( \\|\t\\|$\\)")
|
||||||
|
|
||||||
(defconst ledger-account-pending-regex
|
(defconst ledger-account-pending-regex
|
||||||
"\\(^[ \t]+\\)\\(!.+?\\)\\( \\|$\\)")
|
"\\(^[ \t]+\\)\\(!\\s-*.*?\\)\\( \\|\t\\|$\\)")
|
||||||
|
|
||||||
(defconst ledger-account-cleared-regex
|
(defconst ledger-account-cleared-regex
|
||||||
"\\(^[ \t]+\\)\\(\\*.+?\\)\\( \\|$\\)")
|
"\\(^[ \t]+\\)\\(*\\s-*.*?\\)\\( \\|\t\\|$\\)")
|
||||||
|
|
||||||
|
(defconst ledger-metadata-regex
|
||||||
|
"[ \t]+\\(?2:;[ \t]+.+\\)$")
|
||||||
|
|
||||||
|
(defconst ledger-account-or-metadata-regex
|
||||||
|
(concat
|
||||||
|
ledger-account-any-status-regex
|
||||||
|
"\\|"
|
||||||
|
ledger-metadata-regex))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue