diff --git a/init.el b/init.el index e6ab04a..5c31248 100644 --- a/init.el +++ b/init.el @@ -766,7 +766,8 @@ db/org-add-link-to-other-item db/org-add-link-to-current-clock hydra-org-linking/body - org-dblock-write:db/org-backlinks)) + org-dblock-write:db/org-backlinks + db/org-goto-first-open-checkbox-in-subtree)) (use-package org :pin "gnu" diff --git a/site-lisp/db-org.el b/site-lisp/db-org.el index 97df017..f3504cd 100644 --- a/site-lisp/db-org.el +++ b/site-lisp/db-org.el @@ -759,6 +759,24 @@ cache if that's in use." (when (derived-mode-p 'org-agenda-mode) (org-agenda-redo))) +(defun db/org-goto-first-open-checkbox-in-subtree () + "Jump to first open checkbox in the current subtree. + +First search for started checkboxes, i.e. [-], and if those are +not found, go to the first open checkbox, i.e. [ ]. + +If there's no such open checkbox, emit a message and stay put." + (interactive) + (unless (derived-mode-p 'org-mode) + (user-error "Not in Org buffer, exiting")) + (save-restriction + (widen) + (org-back-to-heading 'invisible-ok) + (org-narrow-to-subtree) + (unless (or (re-search-forward "\\[-\\]" nil 'no-error) + (re-search-forward "\\[ \\]" nil 'no-error)) + (message "No open checkbox in subtree")))) + ;;; Calendar @@ -767,35 +785,35 @@ cache if that's in use." This is done only if the value of this variable is not null." (interactive) (cond - ((null org-icalendar-combined-agenda-file) - (message "`org-icalendar-combined-agenda-file’ not set, not exporting diary.")) - ((not (file-name-absolute-p org-icalendar-combined-agenda-file)) - (user-error "`org-icalendar-combined-agenda-file’ not an absolute path, aborting")) - (t - (progn - (org-save-all-org-buffers) - (let ((org-agenda-files (cl-remove-if #'null - (list db/org-default-org-file - db/org-default-home-file - db/org-default-work-file))) - (org-agenda-new-buffers nil)) - ;; check whether we need to do something - (when (cl-some (lambda (org-file) - (file-newer-than-file-p org-file - org-icalendar-combined-agenda-file)) - org-agenda-files) - (message "Exporting diary ...") - ;; open files manually to avoid polluting `org-agenda-new-buffers’; we - ;; don’t want these buffers to be closed after exporting - (mapc #'find-file-noselect org-agenda-files) - ;; actual export; calls `org-release-buffers’ and may thus close - ;; buffers we want to keep around … which is why we set - ;; `org-agenda-new-buffers’ to nil - (when (file-exists-p org-icalendar-combined-agenda-file) - (delete-file org-icalendar-combined-agenda-file) - (sit-for 3)) - (org-icalendar-combine-agenda-files) - (message "Exporting diary ... done."))))))) + ((null org-icalendar-combined-agenda-file) + (message "`org-icalendar-combined-agenda-file’ not set, not exporting diary.")) + ((not (file-name-absolute-p org-icalendar-combined-agenda-file)) + (user-error "`org-icalendar-combined-agenda-file’ not an absolute path, aborting")) + (t + (progn + (org-save-all-org-buffers) + (let ((org-agenda-files (cl-remove-if #'null + (list db/org-default-org-file + db/org-default-home-file + db/org-default-work-file))) + (org-agenda-new-buffers nil)) + ;; check whether we need to do something + (when (cl-some (lambda (org-file) + (file-newer-than-file-p org-file + org-icalendar-combined-agenda-file)) + org-agenda-files) + (message "Exporting diary ...") + ;; open files manually to avoid polluting `org-agenda-new-buffers’; we + ;; don’t want these buffers to be closed after exporting + (mapc #'find-file-noselect org-agenda-files) + ;; actual export; calls `org-release-buffers’ and may thus close + ;; buffers we want to keep around … which is why we set + ;; `org-agenda-new-buffers’ to nil + (when (file-exists-p org-icalendar-combined-agenda-file) + (delete-file org-icalendar-combined-agenda-file) + (sit-for 3)) + (org-icalendar-combine-agenda-files) + (message "Exporting diary ... done."))))))) ;;; Find items by link to current headline