emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: pinmacs <pinmacs@cas.cat>
To: emacs-orgmode@gnu.org
Subject: org agenda bulk todo with note
Date: Sun, 5 Jan 2025 21:17:48 +0100	[thread overview]
Message-ID: <3f608117-fdcd-454a-9989-1a6be0bb6637@cas.cat> (raw)

[-- Attachment #1: Type: text/plain, Size: 3091 bytes --]

Given:

1. A tendency of massively marking all items as schedule [1]
2. Some of that items should be done on daily basis (I generate them 
with a daily template and the power of org-capture)
3. Life happens and some of them are accumulated, for my last case, that 
was 29 entries pending to be processed

Action:

I procedure with a batch action for that 29 entries (imagine here a 
batch script), and now that it is done, then I need to clear it up from 
my org-agenda

org-agenda-bulk-action  [2] does not serve me because it marks the TODO 
thing without a note, and it's not possible to add a note with the 
prefix. Going to offtopic, I also discovered that does not respect the 
enforce-todo-dependencies [3], ignores if that entries have child todo 
items.

I tried to create a org-agenda-bulk-custom-functions but I failed 
because I wanted a chosen state and a shared note for all the bulk items 
and the way that functions work cannot be done.

But the bulk items are in a variable (nice), 
org-agenda-bulk-marked-entries, and you can traverse it with a generic 
function, so I did it. It took me, unexpectetly, 1h30m to get it working 
(and I could not find other stuff around), so I am sharing what I have 
done so other people can benefit, and by the way, I would like to know 
what do you think of that approach and if you have ideas to improve it.

See it attached in file org-agenda-bulk-todo-with-note.el

With that script I added a note of resolution of that items saying that 
it was resolved through my task with CUSTOM_ID/ID X (like when you close 
multiple issues in a ticketing software) [4]

A healthy 2025 for you guys,
pinmacs


[1] offtopic, but I am sharing it anyway

#+begin_src emacs-lisp
(defun my/org-heading-insert-scheduled ()
   (if (or
        (and (string-match-p my/diary-file (buffer-name))
             (= (org-current-level) 4))
        (and (string-match-p my/board-file (buffer-name))
             (= (org-current-level) 4))
        (and (string-match-p "projects.org" (buffer-name))
             ;; projects are 4-level (tasks start at 6-level, we don't 
care on its children)
             (> (org-current-level) 5))
        (and (string-match-p "projects-candidates.org" (buffer-name))
             ;; projects are 4-level (tasks start at 3-level, we don't 
care on its children)
             (> (org-current-level) 3))
        )
       (save-excursion
         ;; src 
https://emacs.stackexchange.com/questions/72147/org-mode-adding-creation-date-property-upon-heading-creation
         ;;(org-back-to-heading)
         (org-schedule nil (format-time-string "[%Y-%m-%d %a]" nil)))))

(add-hook 'org-insert-heading-hook 'my/org-heading-insert-scheduled 'append)
#+end_src

[2] https://orgmode.org/manual/Agenda-Commands.html

[3] (setq org-enforce-todo-dependencies t) 
https://orgmode.org/manual/TODO-dependencies.html

[4] all that state changes are stored, in my case, in (setq 
org-log-state-notes-into-drawer "TRACE")

[-- Attachment #2: org-agenda-bulk-todo-with-note.el --]
[-- Type: text/x-emacs-lisp, Size: 1081 bytes --]

;; this should be run with M-x
;; all selected bulk entries should have same todo keywords
(defun my/bulk-todo-with-note ()
  "For each marked entry in the Org agenda, set the TODO state with a shared note,
and insert the same user-provided note for all items."
  (interactive)
  (unless org-agenda-bulk-marked-entries
    (user-error "No entries are marked in the agenda"))
(let* ((buffer-todo-keywords (with-current-buffer (marker-buffer (car org-agenda-bulk-marked-entries)) org-todo-keywords-1))
       (chosen-state
        ;; not good when specific on a buffer
        (org-icompleting-read "Choose new TODO state: " buffer-todo-keywords nil t))
       (shared-note (read-string "Enter note for all marked items: ")))
    (dolist (marker org-agenda-bulk-marked-entries)
      (with-current-buffer (marker-buffer marker)
        (goto-char marker)
        (org-todo chosen-state)
        (org-add-log-setup 'state chosen-state nil nil)
        ;; Insert the shared note and finalize it.
        (org-add-log-note)
        (insert shared-note)
        (org-store-log-note)))))

                 reply	other threads:[~2025-01-05 20:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3f608117-fdcd-454a-9989-1a6be0bb6637@cas.cat \
    --to=pinmacs@cas.cat \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).