From fc4bbb28f81d09caf971e539357ec920b305f991 Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Tue, 27 Dec 2022 13:00:50 +0300 Subject: [PATCH] org-search-view: Fix searching across inlinetasks * lisp/org-agenda.el (org-search-view): Consider that `outline-next-heading' may move to inlinetask. * testing/examples/agenda-search.org: New test file. * testing/lisp/test-org-agenda.el (test-org-agenda/org-search-view): New test. Reported-by: Alain.Cochard@unistra.fr Link: https://orgmode.org/list/25514.763.379510.806150@gargle.gargle.HOWL --- lisp/org-agenda.el | 5 +++-- testing/examples/agenda-search.org | 8 ++++++++ testing/lisp/test-org-agenda.el | 25 +++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 testing/examples/agenda-search.org diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el index d31391d11..32579e265 100644 --- a/lisp/org-agenda.el +++ b/lisp/org-agenda.el @@ -4678,7 +4678,7 @@ is active." (org-agenda-text-search-extra-files org-agenda-text-search-extra-files) regexp rtn rtnall files file pos inherited-tags marker category level tags c neg re boolean - ee txt beg end words regexps+ regexps- hdl-only buffer beg1 str) + ee txt beg end last-search-end words regexps+ regexps- hdl-only buffer beg1 str) (unless (and (not edit-at) (stringp string) (string-match "\\S-" string)) @@ -4817,6 +4817,7 @@ is active." (throw 'nextfile t)) (goto-char (max (point-min) (1- (point)))) (while (re-search-forward regexp nil t) + (setq last-search-end (point)) (org-back-to-heading t) (while (and (not (zerop org-agenda-search-view-max-outline-level)) (> (org-reduced-level (org-outline-level)) @@ -4878,7 +4879,7 @@ is active." 'priority 1000 'type "search") (push txt ee) - (goto-char (1- end)))))))))) + (goto-char (max (1- end) last-search-end)))))))))) (setq rtn (nreverse ee)) (setq rtnall (append rtnall rtn))) (org-agenda--insert-overriding-header diff --git a/testing/examples/agenda-search.org b/testing/examples/agenda-search.org new file mode 100644 index 000000000..2772acf2e --- /dev/null +++ b/testing/examples/agenda-search.org @@ -0,0 +1,8 @@ +* Test heading with text +foo +* Test heading with inlinetask +foo +****************** inline +text inside inlinetask +****************** END +bar diff --git a/testing/lisp/test-org-agenda.el b/testing/lisp/test-org-agenda.el index bd96163e9..c138d5668 100644 --- a/testing/lisp/test-org-agenda.el +++ b/testing/lisp/test-org-agenda.el @@ -115,6 +115,31 @@ See https://list.orgmode.org/20220101200103.GB29829@itccanarias.org/T/#t." (should (= 2 (count-lines (point-min) (point-max))))) (org-test-agenda--kill-all-agendas)) +(ert-deftest test-org-agenda/org-search-view () + "Test `org-search-view' specifications." + (cl-assert (not org-agenda-sticky) nil "precondition violation") + (cl-assert (not (org-test-agenda--agenda-buffers)) + nil "precondition violation") + ;; Search a string. + (let ((org-agenda-files `(,(expand-file-name "examples/agenda-search.org" + org-test-dir)))) + (org-search-view nil "foo") + (set-buffer org-agenda-buffer-name) + (should (= 4 (count-lines (point-min) (point-max))))) + ;; Search past inlinetask. + (let ((org-agenda-files `(,(expand-file-name "examples/agenda-search.org" + org-test-dir)))) + (org-search-view nil "bar") + (set-buffer org-agenda-buffer-name) + (should (= 3 (count-lines (point-min) (point-max))))) + ;; Search inside inlinetask. + (let ((org-agenda-files `(,(expand-file-name "examples/agenda-search.org" + org-test-dir)))) + (org-search-view nil "text inside inlinetask") + (set-buffer org-agenda-buffer-name) + (should (= 3 (count-lines (point-min) (point-max))))) + (org-test-agenda--kill-all-agendas)) + (ert-deftest test-org-agenda/property-timestamp () "Match timestamps inside property drawer. See https://list.orgmode.org/06d301d83d9e$f8b44340$ea1cc9c0$@tomdavey.com"