From 4e25b535caaeeae0f3a5c269c39d3cd9e14e5781 Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Mon, 29 Aug 2022 17:58:02 +0200 Subject: [PATCH] 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. --- site-lisp/db-org.el | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/site-lisp/db-org.el b/site-lisp/db-org.el index f3504cd..901a8fa 100644 --- a/site-lisp/db-org.el +++ b/site-lisp/db-org.el @@ -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