org-gtd.el icon indicating copy to clipboard operation
org-gtd.el copied to clipboard

New possible function for inclusion (org-gtd-schedule-appointment)

Open Sabicool opened this issue 1 year ago • 6 comments

As mentioned in https://github.com/Trevoke/org-gtd.el/issues/179#issuecomment-1614068573

We should implement a command to allow setting a new date for an existing appointment

I believe this should work when called on an item in org-mode or a heading when in the agenda buffer:

(defun my/org-agenda-set-property (prop val)
  "Set a property for the current headline non-interactively"
  (org-agenda-check-no-diary)
  (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
           (org-agenda-error)))
     (buffer (marker-buffer hdmarker))
     (pos (marker-position hdmarker))
     (inhibit-read-only t)
     newhead)
    (org-with-remote-undo buffer
       (with-current-buffer buffer
          (widen)
          (goto-char pos)
          (org-show-context 'agenda)
          (org-set-property prop val)))))

(defun my/org-gtd-schedule-appointment (&optional appointment-date)
  "Schedule or reschedule date/time for item in org-gtd"
  (interactive)
  (let ((date (or appointment-date
                  (org-read-date t nil nil "When is this going to happen? "))))
    (if (equal major-mode #'org-agenda-mode)
      (my/org-agenda-set-property "ORG_GTD_TIMESTAMP" (format "<%s>" date))
    (org-set-property "ORG_GTD_TIMESTAMP" (format "<%s>" date)))))

A new function my/org-agenda-set-property had to be created that is the same as org-agenda-set-property except it doesn't (call-interactively 'org-set-property) and instead calls it non-interactively.

I realise it would be nice to add functionality to remove the timestamp with the C-u prefix.

Sabicool avatar Jul 18 '23 05:07 Sabicool

Added ability to remove timestamp with C-u prefix:

(defun my/org-agenda-set-property (prop val)
  "Set a property for the current headline in an org-agenda buffer non-interactively"
  (org-agenda-check-no-diary)
  (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
                       (org-agenda-error)))
         (buffer (marker-buffer hdmarker))
         (pos (marker-position hdmarker))
         (inhibit-read-only t)
         newhead)
    (org-with-remote-undo buffer
      (with-current-buffer buffer
        (widen)
        (goto-char pos)
        (org-show-context 'agenda)
        (org-set-property prop val)))))

(defun my/org-agenda-delete-property (prop)
  "Delete a property for the current headline in an org-agenda buffer non-interactively"
  (org-agenda-check-no-diary)
  (let* ((hdmarker (or (org-get-at-bol 'org-hd-marker)
                       (org-agenda-error)))
         (buffer (marker-buffer hdmarker))
         (pos (marker-position hdmarker))
         (inhibit-read-only t)
         newhead)
    (org-with-remote-undo buffer
      (with-current-buffer buffer
        (widen)
        (goto-char pos)
        (org-show-context 'agenda)
        (org-delete-property prop)))))

(defun my/org-gtd-schedule-appointment (ARG &optional appointment-date)
  "Schedule or reschedule date/time for item in org-gtd"
  (interactive "P")
  (pcase ARG
    ('nil (let ((date (or appointment-date
                          (org-read-date t nil nil "When is this going to happen? "))))
            (if (equal major-mode #'org-agenda-mode)
                (my/org-agenda-set-property "ORG_GTD_TIMESTAMP" (format "<%s>" date))
              (org-set-property "ORG_GTD_TIMESTAMP" (format "<%s>" date)))))
    (`(4) (if (equal major-mode #'org-agenda-mode)
               (my/org-agenda-delete-property "ORG_GTD_TIMESTAMP")
             (org-delete-property "ORG_GTD_TIMESTAMP")))))

Though I suppose removing the gtd timestamp would mean that it won't come up in the engage view at all unless it has the NEXT todo keyword. Could be worthwhile making it ask the user to clarify what they want to do with the item (using org-gtd-clarify-item) after removing the gtd timestamp.

Sabicool avatar Jul 18 '23 06:07 Sabicool

Ah, thank you!

I think you're right; C-u is better off calling org-gtd-clarify-agenda-item, for the reason you mention.

Are you comfortable adding a test or two and making a pull request for this function? If not, no worries, I'll do it soon.

Trevoke avatar Jul 20 '23 16:07 Trevoke

Ah, thank you!

I think you're right; C-u is better off calling org-gtd-clarify-agenda-item, for the reason you mention.

Are you comfortable adding a test or two and making a pull request for this function? If not, no worries, I'll do it soon.

I guess in that case it doesn't make sense to add a C-u prefix as the user can just call org-gtd-clarify-item themselves, unless I am missing something? I also realise that there is an extra timestamp after the drawer that is inserted. Is there any reason for this?

Sabicool avatar Jul 21 '23 02:07 Sabicool

The extra timestamp is, unfortunately, necessary for orgzly compatibility ( https://github.com/Trevoke/org-gtd.el/issues/118 / https://github.com/orgzly/orgzly-android/issues/640 ).

Trevoke avatar Aug 12 '23 15:08 Trevoke

Think it might be better to try and resolve on orgzly end. Adds support for other packages as well like org-review

Sabicool avatar Oct 29 '23 05:10 Sabicool

There's now a community-revived orgzly, I opened that issue there : so .. fingers crossed! https://github.com/orgzly-revived/orgzly-android-revived/issues/126

Trevoke avatar Dec 21 '23 13:12 Trevoke