Jump to first open checkbox in currently clocked-in item by default

When no open checkbox is found, just jump to the headline of the item, as
before.
This commit is contained in:
Daniel - 2022-11-19 16:09:38 +01:00
parent 69f3f80a6e
commit 64bc1c762b
Signed by: dbo
GPG Key ID: 784AA8DF0CCDF625
3 changed files with 59 additions and 36 deletions

View File

@ -767,7 +767,7 @@
db/org-add-link-to-current-clock
hydra-org-linking/body
org-dblock-write:db/org-backlinks
db/org-goto-first-open-checkbox-in-subtree))
db/org-clock-goto-first-open-checkbox))
(use-package org
:pin "gnu"

View File

@ -145,7 +145,7 @@ in the main agenda view."
("Shell" ?s db/run-or-hide-shell)
("EShell" ?e db/run-or-hide-eshell)
("Refile File" ?r #'(lambda () (interactive) (find-file db/org-default-refile-file)))
("Org Clock Goto" ?c org-clock-goto)
("Goto Currnet Clock" ?c db/org-clock-goto-first-open-checkbox)
("Info Lookup" ?I counsel-info-lookup-symbol)
("Unicode Lookup" ?U counsel-unicode-char)
("Timeline of Day" ?T timeline-tools-format-timeline-of-day)

View File

@ -1015,32 +1015,55 @@ 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 ()
(defun db/org-goto-first-open-checkbox-in-subtree (&optional silent)
"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)
If there's no such open checkbox, emit a message (unless SILENT
is non-nil) and stay put.
Note: when lists are nested, those are not (yet) descended into
to find the logically first open checkbox. This should be fixed
somewhen, though."
(unless (derived-mode-p 'org-mode)
(user-error "Not in Org buffer, exiting"))
(save-restriction
(let ((original-point (point)))
(widen)
(org-back-to-heading 'invisible-ok)
(org-narrow-to-subtree)
(unless
;; Yes, progn is not strictly necessary, but it feels cleaner this way.
;; Yes, those `progn's are not strictly necessary, but it feels
;; cleaner this way.
(or (progn
(goto-char (point-min))
(re-search-forward " \\[-\\] " nil 'no-error))
(progn
(goto-char (point-min))
(re-search-forward " \\[ \\] " nil 'no-error)))
(message "No open checkbox in subtree")
(unless silent
(message "No open checkbox in subtree"))
(goto-char original-point)))))
(defun db/org-clock-goto-first-open-checkbox (&optional select)
"Go to the currently clocked-in item or most recently clocked item.
Move point to first open checkbox there, if there's one. See
`db/org-goto-first-open-checkbox-in-subtree' for details.
If SELECT is non-nil, offer a choice of the most recently
clocked-in tasks to jump to."
(interactive "@P")
(org-clock-goto select)
;; `org-clock-goto' will barf if there's no currently clocked-in task, so
;; there is no need to check this again; just try to find the first checkbox
;; now.
(db/org-goto-first-open-checkbox-in-subtree :silent))
;;; Calendar