dengste / org-caldav

Caldav sync for Emacs orgmode
GNU General Public License v3.0
724 stars 105 forks source link

Propose to create only necessary UID #227

Open linktohack opened 3 years ago

linktohack commented 3 years ago

Hello,

I have this function overwritten for a several months and haven't encountered syncing problems from so I would like to have your idea if I should make a PR. Basically we create only UID for either:

I also have a an advice for org-save-all-org-buffers (s in org-agenda) to create these UIDs interactively.

    (el-patch-defun org-caldav-create-uid (file &optional bell)
      "Set ID property on headlines missing it in FILE.
When optional argument BELL is non-nil, inform the user with
a message if the file was modified. This func is the same as
org-icalendar-create-uid except that it ignores entries that
match org-caldav-skip-conditions."
      (let (modified-flag)
    (el-patch-swap
      (org-map-entries
       (lambda ()
         (let ((entry (org-element-at-point)))
           (unless (org-element-property :ID entry)
         (unless (apply 'org-agenda-skip-entry-if org-caldav-skip-conditions)
           (org-id-get-create)
           (setq modified-flag t)
           (forward-line)))))
       nil nil 'comment)
      (let ((timestamps
         (thread-last
             (org-element-map (org-element-parse-buffer) '(headline timestamp) 'identity)
           (seq-map #'(lambda (el)
                (let ((ts (pcase el
                        (`(headline ,(map :scheduled :deadline) . ,_)
                         (or scheduled deadline))
                        (`(timestamp . ,_)
                         el))))
                  (pcase ts
                    (`(timestamp ,(map :type :begin) . ,_)
                     (and (or (eq type 'active) (eq type 'active-range)) begin))))))
           (seq-filter #'identity)
           (seq-reverse))))
        (save-excursion
          (mapc #'(lambda (pos)
            (goto-char pos)
            (org-back-to-heading t)
            (unless (org-element-property :ID (org-element-at-point))
              (unless (apply 'org-agenda-skip-entry-if org-caldav-skip-conditions)
                (org-id-get-create)
                (setq id-pos pos)
                (setq modified-flag t)
                (forward-line))))
            timestamps))))
    (when (and bell modified-flag)
      (message "ID properties created in file \"%s\"" file)
      (sit-for 2)))))

  (defun my/org-agenda-create-uid (&rest r)
    (thread-last
    (org-agenda-files)
      (seq-map (lambda (it)
         (with-current-buffer (get-file-buffer it)
           (org-set-tags-command '(4))
           (org-caldav-create-uid it))))))
  (advice-add 'org-save-all-org-buffers :before #'my/org-agenda-create-uid)
jtoloe commented 9 months ago

Haven't tried your patched function but would like to see this implemented.