From f07867c3c1a254e645bd3f045deeca8767cf8291 Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Mon, 19 Apr 2021 23:37:26 -0400 Subject: [PATCH] REF clean up property code --- etc/conf.org | 30 ++++++++++++++++------- local/lib/org-x/org-x.el | 51 +++++++++++++++++++++++----------------- 2 files changed, 50 insertions(+), 31 deletions(-) diff --git a/etc/conf.org b/etc/conf.org index 3826c51..ffc31c5 100644 --- a/etc/conf.org +++ b/etc/conf.org @@ -2233,11 +2233,20 @@ Also here are the properties for repeated tasks and a few others (see comments i org-x-prop-time-shift)) (let ((effort-choices (list "0:05" "0:15" "0:30" "1:00" "1:30" "2:00" "3:00" - "4:00" "5:00" "6:00"))) - (setq org-global-properties - (list org-x-prop-parent-type-choices - (org-x-define-prop-choices org-effort-property effort-choices t) - org-x-prop-routine-choices))) + "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 + (list (def-choices org-x-prop-parent-type parent-type-choices) + (def-choices org-effort-property effort-choices t) + (def-choices org-x-prop-routine routine-choices))))) #+END_SRC *** capture **** templates @@ -2610,11 +2619,13 @@ original org entry before executing BODY." (org-super-agenda-groups `((:name "Morning routine" :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) (:name "Evening routine" :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) (:name "Calendar" :order 1 :time-grid t) (:name "Habits" :order 6 :habit t) @@ -2862,8 +2873,9 @@ original org entry before executing BODY." (not (org-x-is-created-heading-p)))))) (:name "Missing Archive Target (iterators)" :pred ,(nd/org-x-mk-super-agenda-pred - (and (equal "iterator" (org-entry-get nil org-x-prop-parent-type)) - (not (org-entry-get nil "ARCHIVE"))))) + (and (org-x-headline-has-property + org-x-prop-parent-type org-x-prop-parent-type-iterator) + (org-x-headline-has-property "ARCHIVE" nil)))) (:name "Future Creation Timestamp" :pred ,(nd/org-x-mk-super-agenda-pred ;; TODO extend this to non-todoitems diff --git a/local/lib/org-x/org-x.el b/local/lib/org-x/org-x.el index 836e2cd..ae9181a 100644 --- a/local/lib/org-x/org-x.el +++ b/local/lib/org-x/org-x.el @@ -78,7 +78,7 @@ "Prefix character denoting life category tag.") (defconst org-x-tag-errand - (org-x-prepend-char org-x-tag-location-prefix "errand") +(org-x-prepend-char org-x-tag-location-prefix "errand") "Tag denoting an errand location.") (defconst org-x-tag-home @@ -165,19 +165,17 @@ ;;; PROPERTIES -(eval-and-compile - (defun org-x-define-prop-choices (prop options &optional allow-other) - (let ((options* (if allow-other (-snoc options ":ETC") options))) - (cons (format "%s_ALL" prop) (s-join " " options*))))) +;; all follow the nomenclature `org-x-prop-PROPNAME' (key) or +;; `org-x-prop-PROPNAME-VALNAME' (value) -(eval-and-compile - (defconst org-x-prop-parent-type "PARENT_TYPE" - "Property denoting iterator/periodical headline.")) +(defconst org-x-prop-parent-type "PARENT_TYPE" + "Property denoting iterator/periodical headline.") -(eval-and-compile - (defconst org-x-prop-parent-type-choices - (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-periodical "periodical" + "Property value for a periodical 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" "Property denoting time shift when cloning iterator/periodical headlines.") @@ -186,14 +184,14 @@ (defconst org-x-prop-thread "THREAD" "Property denoting an email thread to track.") -(eval-and-compile - (defconst org-x-prop-routine "X-ROUTINE" - "Property denoting a routine group.")) +(defconst org-x-prop-routine "X-ROUTINE" + "Property denoting a routine group.") -(eval-and-compile - (defconst org-x-prop-routine-choices - (org-x-define-prop-choices org-x-prop-routine '("morning" "evening")) - "Choices for `org-x-prop-routine'.")) +(defconst org-x-prop-routine-morning "morning" + "Property value for morning routine.") + +(defconst org-x-prop-routine-evening "evening" + "Property value for evening routine.") (defconst org-x-prop-created "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 +(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 () "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 () "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 () "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 () "Return t if heading has an effort." (org-entry-get nil org-effort-property)) +;; tag testing + (defun org-x-headline-has-context-p () "Return non-nil if heading has a context tag." (--any