about summary refs log tree commit diff
path: root/org-clubhouse.el
diff options
context:
space:
mode:
authorGriffin Smith <root@gws.fyi>2019-02-01T16·58-0500
committerGriffin Smith <root@gws.fyi>2019-02-01T16·58-0500
commit627799d4dc848aefa0ff9ab5bb755384d933b0fa (patch)
tree7dd5d656fa3b5c9bcbce493a41cf815abbe74de0 /org-clubhouse.el
parentbaeff81f89f80751a8cb7257c750f3b4b1b8b36f (diff)
feat: Add org-clubhouse-update-description
Add a command to update the description of the current story with the
contents of a drawer labeled DESCRIPTION, if one exists
Diffstat (limited to 'org-clubhouse.el')
-rw-r--r--org-clubhouse.el49
1 files changed, 47 insertions, 2 deletions
diff --git a/org-clubhouse.el b/org-clubhouse.el
index 456f372bd9eb..81df7220245a 100644
--- a/org-clubhouse.el
+++ b/org-clubhouse.el
@@ -238,6 +238,32 @@ not be prompted")
           (goto-char (plist-get elt :end)))))
     (append elt `(:children ,(reverse children)))))
 
+(defun +org-element-contents (elt)
+  (buffer-substring-no-properties
+   (plist-get (cadr elt) :contents-begin)
+   (plist-get (cadr elt) :contents-end)))
+
+(defun org-clubhouse-find-description-drawer ()
+  "Try to find a DESCRIPTION drawer in the current element."
+  (let ((elt (org-element-at-point)))
+    (cl-case (car elt)
+      ('drawer (+org-element-contents elt))
+      ('headline
+       (when-let ((drawer-pos (string-match
+                               ":DESCRIPTION:"
+                               (+org-element-contents elt))))
+         (save-excursion
+           (goto-char (+ (plist-get (cadr elt) :contents-begin)
+                         drawer-pos))
+           (org-clubhouse-find-description-drawer)))))))
+
+(comment
+ --elt
+ (equal 'drawer (car --elt))
+ ()
+ --elt
+ )
+
 ;;;
 ;;; API integration
 ;;;
@@ -697,8 +723,10 @@ allows manually passing a clubhouse ID and list of org-element plists to write"
 ;;;
 
 (defun org-clubhouse-update-story-title ()
-  "Updates the title of the Clubhouse story linked to the current headline with
-the text of the headline"
+  "Update the title of the Clubhouse story linked to the current headline.
+
+Update the title of the story linked to the current headline with the text of
+the headline."
   (interactive)
 
   (when-let (clubhouse-id (org-element-clubhouse-id))
@@ -721,6 +749,11 @@ the text of the headline"
    (json-encode attrs)))
 
 (defun org-clubhouse-update-status ()
+  "Update the status of the Clubhouse story linked to the current element.
+
+Update the status of the Clubhouse story linked to the current element with the
+entry in `org-clubhouse-state-alist' corresponding to the todo-keyword of the
+element."
   (interactive)
   (when-let* ((clubhouse-id (org-element-clubhouse-id)))
     (let* ((elt (org-element-find-headline))
@@ -735,6 +768,18 @@ the text of the headline"
         (message "Successfully updated clubhouse status to \"%s\""
                  clubhouse-workflow-state)))))
 
+(defun org-clubhouse-update-description ()
+  "Update the description of the Clubhouse story linked to the current element.
+
+Update the status of the Clubhouse story linked to the current element with the
+contents of a drawer inside the element called DESCRIPTION, if any."
+  (interactive)
+  (when-let* ((clubhouse-id (org-element-clubhouse-id))
+              (new-description (org-clubhouse-find-description-drawer)))
+    (org-clubhouse-update-story-internal
+     clubhouse-id
+     :description new-description)
+    (message "Successfully updated story description")))
 
 (defun org-clubhouse-headlines-from-query (level query)
   "Create `org-mode' headlines from a clubhouse query.