Add function to jump to first open checkbox in subtree

Still needs a nice key binding.
This commit is contained in:
Daniel Borchmann 2022-08-28 19:07:51 +02:00
parent 63a03f0038
commit 5479efabee
No known key found for this signature in database
GPG Key ID: 784AA8DF0CCDF625
2 changed files with 49 additions and 30 deletions

View File

@ -766,7 +766,8 @@
db/org-add-link-to-other-item db/org-add-link-to-other-item
db/org-add-link-to-current-clock db/org-add-link-to-current-clock
hydra-org-linking/body 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 (use-package org
:pin "gnu" :pin "gnu"

View File

@ -759,6 +759,24 @@ cache if that's in use."
(when (derived-mode-p 'org-agenda-mode) (when (derived-mode-p 'org-agenda-mode)
(org-agenda-redo))) (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 ;;; Calendar
@ -767,35 +785,35 @@ cache if that's in use."
This is done only if the value of this variable is not null." This is done only if the value of this variable is not null."
(interactive) (interactive)
(cond (cond
((null org-icalendar-combined-agenda-file) ((null org-icalendar-combined-agenda-file)
(message "`org-icalendar-combined-agenda-file not set, not exporting diary.")) (message "`org-icalendar-combined-agenda-file not set, not exporting diary."))
((not (file-name-absolute-p org-icalendar-combined-agenda-file)) ((not (file-name-absolute-p org-icalendar-combined-agenda-file))
(user-error "`org-icalendar-combined-agenda-file not an absolute path, aborting")) (user-error "`org-icalendar-combined-agenda-file not an absolute path, aborting"))
(t (t
(progn (progn
(org-save-all-org-buffers) (org-save-all-org-buffers)
(let ((org-agenda-files (cl-remove-if #'null (let ((org-agenda-files (cl-remove-if #'null
(list db/org-default-org-file (list db/org-default-org-file
db/org-default-home-file db/org-default-home-file
db/org-default-work-file))) db/org-default-work-file)))
(org-agenda-new-buffers nil)) (org-agenda-new-buffers nil))
;; check whether we need to do something ;; check whether we need to do something
(when (cl-some (lambda (org-file) (when (cl-some (lambda (org-file)
(file-newer-than-file-p org-file (file-newer-than-file-p org-file
org-icalendar-combined-agenda-file)) org-icalendar-combined-agenda-file))
org-agenda-files) org-agenda-files)
(message "Exporting diary ...") (message "Exporting diary ...")
;; open files manually to avoid polluting `org-agenda-new-buffers; we ;; open files manually to avoid polluting `org-agenda-new-buffers; we
;; dont want these buffers to be closed after exporting ;; dont want these buffers to be closed after exporting
(mapc #'find-file-noselect org-agenda-files) (mapc #'find-file-noselect org-agenda-files)
;; actual export; calls `org-release-buffers and may thus close ;; actual export; calls `org-release-buffers and may thus close
;; buffers we want to keep around … which is why we set ;; buffers we want to keep around … which is why we set
;; `org-agenda-new-buffers to nil ;; `org-agenda-new-buffers to nil
(when (file-exists-p org-icalendar-combined-agenda-file) (when (file-exists-p org-icalendar-combined-agenda-file)
(delete-file org-icalendar-combined-agenda-file) (delete-file org-icalendar-combined-agenda-file)
(sit-for 3)) (sit-for 3))
(org-icalendar-combine-agenda-files) (org-icalendar-combine-agenda-files)
(message "Exporting diary ... done."))))))) (message "Exporting diary ... done.")))))))
;;; Find items by link to current headline ;;; Find items by link to current headline