Fix search logic when jumping to first non-finished checkbox

Also stay put when no open checkbox is found, i.e., do not move to the end of
the subtree.
This commit is contained in:
Daniel - 2022-08-29 17:58:02 +02:00
parent 5479efabee
commit 4e25b535ca
No known key found for this signature in database
GPG Key ID: 784AA8DF0CCDF625
1 changed files with 14 additions and 6 deletions

View File

@ -770,12 +770,20 @@ If there's no such open checkbox, emit a message and stay put."
(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"))))
(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.
(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")
(goto-char original-point)))))
;;; Calendar