Make union of regexps at compile time

This commit is contained in:
George Kettleborough 2013-04-16 16:45:01 +01:00
parent a052898b60
commit 03b3ef5f0b
2 changed files with 8 additions and 5 deletions

View file

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

View file

@ -78,7 +78,11 @@
"\\|"
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)
"Simplify the creation of a Ledger regex and helper functions."