um-date-separator and build um-date-re from it using rx

This commit is contained in:
bth 2026-01-04 13:08:20 -08:00
commit c9adc0a23a

View file

@ -42,7 +42,12 @@
:type '(string) :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." "Format passed to `format-time-string' when creating `um-journal-header'. Defaults to ISO8601."
:type '(string) :type '(string)
) )
@ -50,15 +55,28 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; faces ;; 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 -. ;; NOTE: regexp-opt wraps the whole expression in (), so I can't omit the -.
(defcustom um-locale-re (regexp-opt '( (defcustom um-locale-re (regexp-opt '(
"- Brooklyn" "- home"
"- Fool's Bluff" "- away"
)) "um locale regexp") ))
"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 (defface font-lock-um-date-face
`((((type tty) (class mono))) `((((type tty) (class mono)))
@ -82,6 +100,7 @@
"um tag face") "um tag face")
;; TODO: should this be a user setup hook? ;; 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 (font-lock-add-keywords 'markdown-mode
`( `(
(,um-date-re 1 'font-lock-um-date-face) (,um-date-re 1 'font-lock-um-date-face)