Trevoke / org-gtd.el

A package for using GTD with org-mode
GNU General Public License v3.0
367 stars 45 forks source link

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

Open Sabicool opened 11 months ago

Sabicool commented 11 months ago

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 commented 11 months ago

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.

Trevoke commented 11 months ago

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.

Sabicool commented 11 months ago

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?

Trevoke commented 10 months ago

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 ).

Sabicool commented 8 months ago

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

Trevoke commented 6 months ago

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