From c9adc0a23ac410b43d66266006901406756e4eb4 Mon Sep 17 00:00:00 2001 From: bth Date: Sun, 4 Jan 2026 13:08:20 -0800 Subject: [PATCH] um-date-separator and build um-date-re from it using rx --- elisp/um.el | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/elisp/um.el b/elisp/um.el index 7e37146..f1c6dc8 100644 --- a/elisp/um.el +++ b/elisp/um.el @@ -42,7 +42,12 @@ :type '(string) ) -(defcustom um-date-format "%Y-%m-%d" +(defcustom um-date-separator "-" + "Seperator used in date strings, used by `um-date-format' and `um-date-re'." + :type '(string) + ) + +(defcustom um-date-format (concat "%Y" um-date-separator "%m" um-date-separator "%d") "Format passed to `format-time-string' when creating `um-journal-header'. Defaults to ISO8601." :type '(string) ) @@ -50,15 +55,28 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; faces -(defconst um-date-re "^: \\([[:digit:]]+\\.[[:digit:]]+\\.[[:digit:]]+$\\)" "um date regexp") +;; TODO: doesn't currently respect um-date-format: +(defconst um-date-re (rx + line-start + (literal ": ") + (group (repeat 4 digit) + (literal um-date-separator) + (repeat 1 2 digit) + (literal um-date-separator) + (repeat 1 2 digit)) + line-end + ) + "um date regexp. built from `um-date-separator'. NOTE: currently assumes ISO8601.") ;; NOTE: regexp-opt wraps the whole expression in (), so I can't omit the -. (defcustom um-locale-re (regexp-opt '( - "- Brooklyn" - "- Fool's Bluff" - )) "um locale regexp") + "- home" + "- away" + )) + "um locale regexp. Add your custom places within a `regexp-opt' or make it general.") -(defconst um-tag-re "^\\+ \\([[:alpha:]\\_\\-]+$\\)" "um tag regexp") +(defconst um-tag-re "^\\+ \\([[:alpha:]\\_\\-]+$\\)" + "um tag regexp. Allows hypens and underscores within the tag.") (defface font-lock-um-date-face `((((type tty) (class mono))) @@ -82,6 +100,7 @@ "um tag face") ;; TODO: should this be a user setup hook? +;; TODO: these matchers should be functions which only match against the header. (font-lock-add-keywords 'markdown-mode `( (,um-date-re 1 'font-lock-um-date-face)