Skip to content

Commit

Permalink
POC seems up and running
Browse files Browse the repository at this point in the history
  • Loading branch information
Trevoke committed Aug 1, 2024
1 parent f82eb97 commit ffe02e0
Show file tree
Hide file tree
Showing 37 changed files with 833 additions and 1,214 deletions.
143 changes: 143 additions & 0 deletions new.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
(setq action
'((keyword . "NEXT")
(properties . ((ORG_GTD . ((value . "Actions")
(selectable . nil)))
(id . ((value . org-gtd-id-get-create)
(selectable . nil)))))))

(setq calendared-draft-one
'((properties . ((id . ((value . org-gtd-id-get-create)
(selectable . nil)))
(ORG_GTD . ((value . "Calendar")
(selectable . nil)))
(ORG_GTD_TIMESTAMP . ((type . 'active-timestamp)
(prompt . "Timestamp: ")
(selectable . t)))))))


(setq calendared
'((metadata . ((id . org-gtd-id-get-create)
(ORG_GTD . "Calendar")))
(definition . (properties . ((ORG_GTD_TIMESTAMP . ((type . 'active-timestamp)
(prompt . "Timestamp: "))))))
(views . (engage . ((ORG_GTD_TIMESTAMP . :today))))))

(setq habits
'((keyword . "SCHEDULED")
(properties . ((id . ((value . org-gtd-id-get-create)
(selectable . nil)))
(ORG_GTD . ((value . "Habits")
(selectable . nil)))
(style . ((value . "habit")
(selectable . nil)))))))

(setq incubated
'((properties . ((id . ((value . org-gtd-id-get-create)
(selectable . nil)))
(ORG_GTD . ((value . "incubated")
(selectable . nil)))
(ORG_GTD_TIMESTAMP . ((type . 'active-timestamp)
(prompt . "Timestamp: ")
(selectable . t)))))))

(setq project
'((properties . ((id . ((value . org-gtd-id-get-create)
(selectable . nil)))
(ORG_GTD . ((value . "project")
(selectable . nil)))
(trigger . ((value . "org-gtd-next-project-action org-gtd-update-project-task!")
(selectable . nil)))
(first_action . ((type . 'string)
(value . org-gtd-id-get-create)
(selectable . t)))))))

(setq project-action
'((keyword . "TODO")
(properties . ((ORG_GTD . ((value . "actions")
(selectable . nil)))
(id . ((value . org-gtd-id-get-create)
(selectable . nil)))
(parent_id . ((type . 'string)
(value . org-gtd-id-get-create)
(selectable . t)))
(following-action . ((type . 'string)
(value . "")
(selectable . t)))))))

(setq delegated
'((keyword . "WAIT")
(properties . ((id . ((value . org-gtd-id-get-create)
(selectable . nil)))
(ORG_GTD_TIMESTAMP . ((type . 'active-timestamp)
(prompt . "When to check in on this? ")
(selectable . t)))
(ORG_GTD . ((value . "actions")
(selectable . nil)))))))

(defun prompt-for-property (property-data)
"Prompt the user for a value based on PROPERTY-DATA if it is selectable."
(interactive)
(let ((type (cdr (assoc 'type property-data)))
(prompt (cdr (assoc 'prompt property-data)))
(selectable (cdr (assoc 'selectable property-data)))
(value (cdr (assoc 'value property-data))))
(if selectable
(pcase type
('string (read-string (format "%s: " prompt)))
('active-timestamp (prompt-for-active-date prompt))
('active-timestamp-with-repeater (prompt-for-date-with-repeater))
(_ (read-string (format "%s: " prompt))))
(if (functionp value)
(funcall value)
value))))

(defun prompt-for-date-with-repeater ()
(interactive)
(let ((start-date (org-read-date nil nil nil "When do you want this repeating event to start?"))
(repeater (read-from-minibuffer "How do you want this to repeat? ")))
(format "<%s %s>" today repeater)))

(defun prompt-for-active-date (prompt)
(interactive)
(let ((date (org-read-date nil nil nil prompt)))
(format "<%s>" date)))

(defun make-new-heading (action-alist &optional epom)
"Create a new org heading with the information from ACTION-ALIST at EPOM."
(interactive)
(let ((epom (or epom (org-element-at-point)))
(properties (cdr (assoc 'properties action-alist)))
(keyword (cdr (assoc 'keyword action-alist))))
;; Navigate to EPOM
(goto-char (org-element-property :begin epom))

;; Iterate over properties and set them
(dolist (property properties)
(let ((property-name (symbol-name (car property)))
(property-data (cdr property)))
(org-set-property property-name (prompt-for-property property-data))))
;; Set keyword if present
(when keyword
(org-todo keyword))))


(defun generate-org-ql-query (alist)
"Generate an org-ql query from the provided ALIST, focusing on ORG_GTD, ORG_GTD_TIMESTAMP, and style."
(let ((keyword (cdr (assoc 'keyword alist)))
(properties (cdr (assoc 'properties alist))))
(delq nil
(append
'(and)
(when keyword
`((todo ,keyword)))
(mapcar (lambda (property)
(let ((name (symbol-name (car property)))
(value (cdr (assoc 'value (cdr property)))))
(when (and value (member name '("ORG_GTD" "ORG_GTD_TIMESTAMP" "style")))
`(property ,name ,value t))))
properties)))))


(org-ql-search (org-agenda-files) (generate-org-ql-query action))
(org-ql-search (org-agenda-files) '(todo "NEXT"))
(org-ql-search (org-agenda-files) '(and (property "ORG_GTD" "Calendar" t)))
66 changes: 30 additions & 36 deletions org-gtd-agenda.el
Original file line number Diff line number Diff line change
Expand Up @@ -51,53 +51,47 @@ This is where the project name is displayed, on the left side."
(defun org-gtd-engage ()
"Display `org-agenda' customized by org-gtd."
(interactive)
(org-gtd-core-prepare-agenda-buffers)
(with-org-gtd-context
(let* ((project-format-prefix
(format " %%i %%-%d:(org-gtd-agenda--prefix-format) "
org-gtd-engage-prefix-width))
(org-agenda-custom-commands
`(("g" "Scheduled today and all NEXT items"
((agenda ""
((org-agenda-span 1)
(org-agenda-start-day nil)
(org-agenda-skip-additional-timestamps-same-entry t)))
(todo org-gtd-next
((org-agenda-overriding-header "All actions ready to be executed.")
(org-agenda-prefix-format
'((todo . ,project-format-prefix))))))))))
(org-agenda nil "g")
(goto-char (point-min)))))
(let* ((project-format-prefix
(format " %%i %%-%d:(org-gtd-agenda--prefix-format) "
org-gtd-engage-prefix-width))
(org-agenda-custom-commands
`(("g" "Scheduled today and all NEXT items"
((agenda ""
((org-agenda-span 1)
(org-agenda-start-day nil)
(org-agenda-skip-additional-timestamps-same-entry t)))
(todo org-gtd-next
((org-agenda-overriding-header "All actions ready to be executed.")
(org-agenda-prefix-format
'((todo . ,project-format-prefix))))))))))
(org-agenda nil "g")
(goto-char (point-min))))

;;;###autoload
(defun org-gtd-engage-grouped-by-context ()
"Show all `org-gtd-next' actions grouped by context (tag prefixed with @)."
(interactive)
(org-gtd-core-prepare-agenda-buffers)
(with-org-gtd-context
(let* ((contexts (seq-map
(lambda (x) (substring-no-properties x))
(seq-uniq
(flatten-list
(org-map-entries
(lambda () org-scanner-tags)
(format "{^@}+TODO=\"%s\"" org-gtd-next)
'agenda)))))
(blocks (seq-map
(lambda (x) `(tags ,(format "+%s+TODO=\"%s\"" x org-gtd-next)
((org-agenda-overriding-header ,x))))
contexts))
(org-agenda-custom-commands `(("g" "actions by context" ,blocks))))
(org-agenda nil "g"))))
(let* ((contexts (seq-map
(lambda (x) (substring-no-properties x))
(seq-uniq
(flatten-list
(org-map-entries
(lambda () org-scanner-tags)
(format "{^@}+TODO=\"%s\"" org-gtd-next)
'agenda)))))
(blocks (seq-map
(lambda (x) `(tags ,(format "+%s+TODO=\"%s\"" x org-gtd-next)
((org-agenda-overriding-header ,x))))
contexts))
(org-agenda-custom-commands `(("g" "actions by context" ,blocks))))
(org-agenda nil "g")))

;;;###autoload
(defun org-gtd-show-all-next ()
"Show all next actions from all agenda files in a single list.
This assumes all GTD files are also agenda files."
(interactive)
(org-gtd-core-prepare-agenda-buffers)
(with-org-gtd-context
(org-todo-list org-gtd-next)))
(org-todo-list org-gtd-next))

;;;; Functions

Expand Down
19 changes: 4 additions & 15 deletions org-gtd-archive.el
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ into a datetree."
(defun org-gtd-archive-completed-items ()
"Archive everything that needs to be archived in your org-gtd."
(interactive)
(org-gtd-core-prepare-agenda-buffers)
(with-org-gtd-context
(org-gtd--archive-complete-projects)
(org-gtd--archive-complete-projects)
(org-map-entries #'org-gtd--archive-completed-actions
"+LEVEL=2&+ORG_GTD=\"Actions\""
'agenda)
Expand All @@ -79,7 +77,8 @@ into a datetree."
'agenda)
(org-map-entries #'org-gtd--archive-completed-actions
"+LEVEL=2&+ORG_GTD=\"Incubated\""
'agenda)))
'agenda)
)

(defun org-gtd-archive-item-at-point ()
"Dirty hack to force archiving where I know I can."
Expand All @@ -93,23 +92,13 @@ into a datetree."
(with-current-buffer buffer
(org-paste-subtree)
(goto-char (point-min))
(with-org-gtd-context (org-archive-subtree))
(org-archive-subtree)
(basic-save-buffer)
(kill-buffer))
(delete-file temp-file))))

;;;; Functions

;;;;; Public

(defun org-gtd-archive-location-func ()
"Default function to define where to archive items."
(let* ((year (number-to-string (caddr (calendar-current-date))))
(full-org-gtd-path (expand-file-name org-gtd-directory))
(filename (format org-gtd-archive-file-format year))
(filepath (f-join full-org-gtd-path filename)))
(string-join `(,filepath "::" "datetree/"))))

;;;;; Private

(defun org-gtd--all-subheadings-in-done-type-p ()
Expand Down
103 changes: 103 additions & 0 deletions org-gtd-calendar-old.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
;;; org-gtd-calendar.el --- Define calendar items in org-gtd -*- lexical-binding: t; coding: utf-8 -*-
;;
;; Copyright © 2019-2023 Aldric Giacomoni

;; Author: Aldric Giacomoni <[email protected]>
;; This file is not part of GNU Emacs.

;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.

;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this file. If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:
;;
;; Calendar items have their own state and logic, defined here.
;;
;;; Code:

;;;; Requirements

(require 'org-gtd-clarify)

(declare-function 'org-gtd-organize--call 'org-gtd-organize)
(declare-function 'org-gtd-organize-apply-hooks 'org-gtd-organize)

;;;; Constants

(defconst org-gtd-calendar "Calendar")

(defconst org-gtd-calendar-func #'org-gtd-calendar--apply
"Function called when item at point is a task that must happen on a given day.
Keep this clean and don't load your calendar with things that aren't
actually appointments or deadlines.")

(defconst org-gtd-calendar-template
(format "* Calendar
:PROPERTIES:
:ORG_GTD: %s
:END:
" org-gtd-calendar))

;;;; Commands

(defun org-gtd-calendar (&optional appointment-date)
"Decorate and refile item at point as a calendar item.
You can pass APPOINTMENT-DATE as a YYYY-MM-DD string if you want to use this
non-interactively."
(interactive)
(org-gtd-organize--call
(apply-partially org-gtd-calendar-func
appointment-date)))

;;;; Functions

;;;;; Public

(defun org-gtd-calendar-create (topic appointment-date)
"Automatically create a calendar task in the GTD flow.
Takes TOPIC as the string from which to make the heading to add to `org-gtd' and
APPOINTMENT-DATE as a YYYY-MM-DD string."
(let ((buffer (generate-new-buffer "Org GTD programmatic temp buffer"))
(org-id-overriding-file-name "org-gtd"))
(with-current-buffer buffer
(org-mode)
(insert (format "* %s" topic))
(org-gtd-clarify-item)
(org-gtd-calendar appointment-date))
(kill-buffer buffer)))

;;;;; Private

(defun org-gtd-calendar--apply (&optional appointment-date rfloc)
"Add a date/time to this item and store in org gtd.
You can pass APPOINTMENT-DATE as a YYYY-MM-DD string if you want to use this
non-interactively."
(let ((date (or appointment-date
(org-read-date t nil nil "When is this going to happen? "))))
(org-entry-put (point) org-gtd-timestamp (format "<%s>" date))
(save-excursion
(org-end-of-meta-data t)
(open-line 1)
(insert (format "<%s>" date))))
(setq-local org-gtd--organize-type 'calendar)
(org-gtd-organize-apply-hooks)
(org-refile nil nil rfloc))

;;;; Footer

(provide 'org-gtd-calendar)

;;; org-gtd-calendar.el ends here
Loading

0 comments on commit ffe02e0

Please sign in to comment.