How to bulk copy in org agenda

512 views Asked by At

After an agenda search, I want to bulk copy marked entries.

The bulk action dispatcher only allows to bulk refile. (And I do not want to modify the variable org-refile-keep.)

How does a custom function for this bulk action has to look like?

The org manual gives an example for a custom function in http://orgmode.org/manual/Agenda-commands.html#index-B-1429 but simply replacing org-set-property "CATEGORY" "web" by org-copy does not do the trick, as the function will then ask for the destination for each entry it is executed on.

1

There are 1 answers

1
lawlist On BEST ANSWER

This answer assumes the original poster wants to copy the entire subtree from the master todo file, rather than the excerpt (redacted version) in the *Org Agenda* buffer.

Mark your entries, hit the letter B, then the letter f, then type org-agenda-bulk-copy-subtree, then hit RET. The original poster may wish to modify the data gathering portion to push the entries to a list, etc.

[CAVEAT: In my testing, it appears that org-agenda-bulk-action destroys/moves the markers (invisible to the naked eye) so it will be necessary to rebuild the *Org Agenda* buffer if any additional work needs to be done with markers leading back to the master todo file. Alternatively, perhaps we could clone/duplicate the *Org Agenda* buffer and work with a temporary buffer so that the original is not altered?]

(defun org-agenda-bulk-copy-subtree ()
"Doc-string"
(interactive)
  (or (eq major-mode 'org-agenda-mode) (error "Not in agenda"))
  (let* ((marker (or (org-get-at-bol 'org-marker) (org-agenda-error)))
         (buffer (marker-buffer marker))
         (pos (marker-position marker))
         (output-buf (get-buffer-create "*RESULTS*")))
   (with-current-buffer buffer
     (goto-char pos)
     (org-back-to-heading t)
     (org-copy-subtree))
   (with-current-buffer output-buf
     (insert org-subtree-clip "\n"))
   (unless (get-buffer-window output-buf)
    (display-buffer output-buf t))))