Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Sabicool opened this issue Jul 18, 2023 · 6 comments
Open

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

Sabicool opened this issue Jul 18, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@Sabicool
Copy link

Sabicool commented Jul 18, 2023

As mentioned in #179 (comment)

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
Copy link
Author

Sabicool commented Jul 18, 2023

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
Copy link
Owner

Trevoke commented Jul 20, 2023

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 Trevoke added the enhancement New feature or request label Jul 20, 2023
@Sabicool
Copy link
Author

Sabicool commented Jul 21, 2023

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
Copy link
Owner

Trevoke commented Aug 12, 2023

The extra timestamp is, unfortunately, necessary for orgzly compatibility ( #118 / orgzly/orgzly-android#640 ).

@Sabicool
Copy link
Author

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

@Trevoke
Copy link
Owner

Trevoke commented Dec 21, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants