REF clean up property code

This commit is contained in:
Nathan Dwarshuis 2021-04-19 23:37:26 -04:00
parent ecf6ebbab0
commit f07867c3c1
2 changed files with 50 additions and 31 deletions

View File

@ -2233,11 +2233,20 @@ Also here are the properties for repeated tasks and a few others (see comments i
org-x-prop-time-shift)) org-x-prop-time-shift))
(let ((effort-choices (list "0:05" "0:15" "0:30" "1:00" "1:30" "2:00" "3:00" (let ((effort-choices (list "0:05" "0:15" "0:30" "1:00" "1:30" "2:00" "3:00"
"4:00" "5:00" "6:00"))) "4:00" "5:00" "6:00"))
(parent-type-choices (list org-x-prop-parent-type-periodical
org-x-prop-parent-type-iterator))
(routine-choices (list org-x-prop-routine-morning
org-x-prop-routine-evening)))
(cl-flet
((def-choices
(prop options &optional allow-other)
(let ((options* (if allow-other (-snoc options ":ETC") options)))
(cons (format "%s_ALL" prop) (s-join " " options*)))))
(setq org-global-properties (setq org-global-properties
(list org-x-prop-parent-type-choices (list (def-choices org-x-prop-parent-type parent-type-choices)
(org-x-define-prop-choices org-effort-property effort-choices t) (def-choices org-effort-property effort-choices t)
org-x-prop-routine-choices))) (def-choices org-x-prop-routine routine-choices)))))
#+END_SRC #+END_SRC
*** capture *** capture
**** templates **** templates
@ -2610,11 +2619,13 @@ original org entry before executing BODY."
(org-super-agenda-groups (org-super-agenda-groups
`((:name "Morning routine" `((:name "Morning routine"
:pred ,(nd/org-x-mk-super-agenda-pred :pred ,(nd/org-x-mk-super-agenda-pred
(equal "morning" (org-entry-get nil org-x-prop-routine))) (org-x-headline-has-property org-x-prop-routine
org-x-prop-routine-morning))
:order 0) :order 0)
(:name "Evening routine" (:name "Evening routine"
:pred ,(nd/org-x-mk-super-agenda-pred :pred ,(nd/org-x-mk-super-agenda-pred
(equal "evening" (org-entry-get nil org-x-prop-routine))) (org-x-headline-has-property org-x-prop-routine
org-x-prop-routine-evening))
:order 3) :order 3)
(:name "Calendar" :order 1 :time-grid t) (:name "Calendar" :order 1 :time-grid t)
(:name "Habits" :order 6 :habit t) (:name "Habits" :order 6 :habit t)
@ -2862,8 +2873,9 @@ original org entry before executing BODY."
(not (org-x-is-created-heading-p)))))) (not (org-x-is-created-heading-p))))))
(:name "Missing Archive Target (iterators)" :pred (:name "Missing Archive Target (iterators)" :pred
,(nd/org-x-mk-super-agenda-pred ,(nd/org-x-mk-super-agenda-pred
(and (equal "iterator" (org-entry-get nil org-x-prop-parent-type)) (and (org-x-headline-has-property
(not (org-entry-get nil "ARCHIVE"))))) org-x-prop-parent-type org-x-prop-parent-type-iterator)
(org-x-headline-has-property "ARCHIVE" nil))))
(:name "Future Creation Timestamp" :pred (:name "Future Creation Timestamp" :pred
,(nd/org-x-mk-super-agenda-pred ,(nd/org-x-mk-super-agenda-pred
;; TODO extend this to non-todoitems ;; TODO extend this to non-todoitems

View File

@ -165,19 +165,17 @@
;;; PROPERTIES ;;; PROPERTIES
(eval-and-compile ;; all follow the nomenclature `org-x-prop-PROPNAME' (key) or
(defun org-x-define-prop-choices (prop options &optional allow-other) ;; `org-x-prop-PROPNAME-VALNAME' (value)
(let ((options* (if allow-other (-snoc options ":ETC") options)))
(cons (format "%s_ALL" prop) (s-join " " options*)))))
(eval-and-compile
(defconst org-x-prop-parent-type "PARENT_TYPE" (defconst org-x-prop-parent-type "PARENT_TYPE"
"Property denoting iterator/periodical headline.")) "Property denoting iterator/periodical headline.")
(eval-and-compile (defconst org-x-prop-parent-type-periodical "periodical"
(defconst org-x-prop-parent-type-choices "Property value for a periodical parent type.")
(org-x-define-prop-choices org-x-prop-parent-type '("periodical" "iterator"))
"Choices for `org-x-prop-parent-type'.")) (defconst org-x-prop-parent-type-iterator "iterator"
"Property value for an iterator parent type.")
(defconst org-x-prop-time-shift "TIME_SHIFT" (defconst org-x-prop-time-shift "TIME_SHIFT"
"Property denoting time shift when cloning iterator/periodical headlines.") "Property denoting time shift when cloning iterator/periodical headlines.")
@ -186,14 +184,14 @@
(defconst org-x-prop-thread "THREAD" (defconst org-x-prop-thread "THREAD"
"Property denoting an email thread to track.") "Property denoting an email thread to track.")
(eval-and-compile
(defconst org-x-prop-routine "X-ROUTINE" (defconst org-x-prop-routine "X-ROUTINE"
"Property denoting a routine group.")) "Property denoting a routine group.")
(eval-and-compile (defconst org-x-prop-routine-morning "morning"
(defconst org-x-prop-routine-choices "Property value for morning routine.")
(org-x-define-prop-choices org-x-prop-routine '("morning" "evening"))
"Choices for `org-x-prop-routine'.")) (defconst org-x-prop-routine-evening "evening"
"Property value for evening routine.")
(defconst org-x-prop-created "CREATED" (defconst org-x-prop-created "CREATED"
"Property denoting when a headline was created.") "Property denoting when a headline was created.")
@ -426,22 +424,31 @@ compared to REF-TIME. Returns nil if no timestamp is found."
;; property testing ;; property testing
(defun org-x-headline-has-property (property value &optional inherit)
"Return t if headline under point has PROPERTY with VALUE.
INHERIT is passed to `org-entry-get'."
(equal value (org-entry-get nil property inherit)))
(defun org-x-is-periodical-heading-p () (defun org-x-is-periodical-heading-p ()
"Return t if heading is a periodical." "Return t if heading is a periodical."
(equal "periodical" (org-entry-get nil org-x-prop-parent-type t))) (org-x-headline-has-property org-x-prop-parent-type
org-x-prop-parent-type-periodical t))
(defun org-x-is-iterator-heading-p () (defun org-x-is-iterator-heading-p ()
"Return t if heading is an iterator." "Return t if heading is an iterator."
(equal "iterator" (org-entry-get nil org-x-prop-parent-type t))) (org-x-headline-has-property org-x-prop-parent-type
org-x-prop-parent-type-iterator t))
(defun org-x-is-habit-heading-p () (defun org-x-is-habit-heading-p ()
"Return t if heading is an iterator." "Return t if heading is an iterator."
(equal "habit" (org-entry-get nil "STYLE" t))) (org-x-headline-has-property "STYLE" "habit"))
(defun org-x-headline-has-effort-p () (defun org-x-headline-has-effort-p ()
"Return t if heading has an effort." "Return t if heading has an effort."
(org-entry-get nil org-effort-property)) (org-entry-get nil org-effort-property))
;; tag testing
(defun org-x-headline-has-context-p () (defun org-x-headline-has-context-p ()
"Return non-nil if heading has a context tag." "Return non-nil if heading has a context tag."
(--any (--any