Merge pull request #176 from georgek/regex

OK, lets try again.  Thanks for working on this!
This commit is contained in:
Craig Earls 2013-04-16 08:58:12 -07:00
commit 524ec0b614
3 changed files with 70 additions and 59 deletions

View file

@ -124,6 +124,7 @@ Return list."
root (cdr xact)) root (cdr xact))
(setq root nil elements nil))) (setq root nil elements nil)))
(setq elements (cdr elements))) (setq elements (cdr elements)))
(setq root (delete (list (car elements) t) root))
(and root (and root
(sort (sort
(mapcar (function (mapcar (function
@ -144,9 +145,12 @@ Return list."
(if (eq (save-excursion (if (eq (save-excursion
(ledger-thing-at-point)) 'transaction) (ledger-thing-at-point)) 'transaction)
(if (null current-prefix-arg) (if (null current-prefix-arg)
(ledger-payees-in-buffer) ;; this completes against payee names (delete
(caar (ledger-parse-arguments))
(ledger-payees-in-buffer)) ;; this completes against payee names
(progn (progn
(let ((text (buffer-substring-no-properties (line-beginning-position) (let ((text (buffer-substring-no-properties
(line-beginning-position)
(line-end-position)))) (line-end-position))))
(delete-region (line-beginning-position) (delete-region (line-beginning-position)
(line-end-position)) (line-end-position))

View file

@ -75,7 +75,10 @@ Can indent, complete or align depending on context."
(if (= (point) (line-beginning-position)) (if (= (point) (line-beginning-position))
(indent-to ledger-post-account-alignment-column) (indent-to ledger-post-account-alignment-column)
(save-excursion (save-excursion
(re-search-backward ledger-account-or-metadata-regex (re-search-backward
(rx-static-or ledger-account-any-status-regex
ledger-metadata-regex
ledger-payee-any-status-regex)
(line-beginning-position) t)) (line-beginning-position) t))
(when (= (point) (match-end 0)) (when (= (point) (match-end 0))
(ledger-pcomplete interactively)))) (ledger-pcomplete interactively))))

View file

@ -46,16 +46,16 @@
"^[;#|\\*%].*\\|[ \t]+;.*") "^[;#|\\*%].*\\|[ \t]+;.*")
(defconst ledger-payee-any-status-regex (defconst ledger-payee-any-status-regex
"^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.*?)\\)?\\s-+\\(.+?\\)\\(\t\\|\n\\| [ \t]\\)") "^[0-9]+[-/][-/.=0-9]+\\(\\s-+\\*\\)?\\(\\s-+(.*?)\\)?\\s-+\\(.+?\\)\\s-*\\(;\\|$\\)")
(defconst ledger-payee-pending-regex (defconst ledger-payee-pending-regex
"^[0-9]+[-/][-/.=0-9]+\\s-\\!\\s-+\\(([^)]+)\\s-+\\)?\\([^*].+?\\)\\(;\\|$\\)") "^[0-9]+[-/][-/.=0-9]+\\s-\\!\\s-+\\(([^)]+)\\s-+\\)?\\([^*].+?\\)\\s-*\\(;\\|$\\)")
(defconst ledger-payee-cleared-regex (defconst ledger-payee-cleared-regex
"^[0-9]+[-/][-/.=0-9]+\\s-\\*\\s-+\\(([^)]+)\\s-+\\)?\\([^*].+?\\)\\(;\\|$\\)") "^[0-9]+[-/][-/.=0-9]+\\s-\\*\\s-+\\(([^)]+)\\s-+\\)?\\([^*].+?\\)\\s-*\\(;\\|$\\)")
(defconst ledger-payee-uncleared-regex (defconst ledger-payee-uncleared-regex
"^[0-9]+[-/][-/.=0-9]+\\s-+\\(([^)]+)\\s-+\\)?\\([^*].+?\\)\\(;\\|$\\)") "^[0-9]+[-/][-/.=0-9]+\\s-+\\(([^)]+)\\s-+\\)?\\([^*].+?\\)\\s-*\\(;\\|$\\)")
(defconst ledger-init-string-regex (defconst ledger-init-string-regex
"^--.+?\\($\\|[ ]\\)") "^--.+?\\($\\|[ ]\\)")
@ -78,7 +78,11 @@
"\\|" "\\|"
ledger-metadata-regex)) ledger-metadata-regex))
(defmacro rx-static-or (&rest rx-strs)
"Returns rx union of regexps which can be symbols that eval to strings."
`(rx (or ,@(mapcar #'(lambda (rx-str)
`(regexp ,(eval rx-str)))
rx-strs))))
(defmacro ledger-define-regexp (name regex docs &rest args) (defmacro ledger-define-regexp (name regex docs &rest args)
"Simplify the creation of a Ledger regex and helper functions." "Simplify the creation of a Ledger regex and helper functions."