summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2016-05-05 13:15:34 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2016-05-05 13:15:34 +0200
commit8127b3c30d8a2217468068a73f23bfa4945573dc (patch)
tree71935191a2884c423c307e28915b7bb2745b1841
parent3308a5ecfe0ac254e2582362703dff6cff151cc9 (diff)
parent83e373f109e58900201e7cb3daa8bbebd7121b84 (diff)
downloadorg-mode-8127b3c30d8a2217468068a73f23bfa4945573dc.tar.gz
Merge branch 'maint'
-rw-r--r--lisp/org.el48
-rw-r--r--testing/lisp/test-org.el21
2 files changed, 52 insertions, 17 deletions
diff --git a/lisp/org.el b/lisp/org.el
index c320db2..f45d5d0 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -7204,9 +7204,11 @@ show that drawer instead."
(defun org-first-headline-recenter ()
"Move cursor to the first headline and recenter the headline."
- (goto-char (point-min))
- (when (re-search-forward (concat "^\\(" org-outline-regexp "\\)") nil t)
- (set-window-start (selected-window) (point-at-bol))))
+ (let ((window (get-buffer-window)))
+ (when window
+ (goto-char (point-min))
+ (when (re-search-forward (concat "^\\(" org-outline-regexp "\\)") nil t)
+ (set-window-start window (line-beginning-position))))))
;;; Saving and restoring visibility
@@ -13866,14 +13868,18 @@ as well.")
(defun org-occur (regexp &optional keep-previous callback)
"Make a compact tree which shows all matches of REGEXP.
-The tree will show the lines where the regexp matches, and all higher
-headlines above the match. It will also show the heading after the match,
-to make sure editing the matching entry is easy.
-If KEEP-PREVIOUS is non-nil, highlighting and exposing done by a previous
-call to `org-occur' will be kept, to allow stacking of calls to this
-command.
-If CALLBACK is non-nil, it is a function which is called to confirm
-that the match should indeed be shown."
+
+The tree will show the lines where the regexp matches, and any other context
+defined in `org-show-context-detail', which see.
+
+When optional argument KEEP-PREVIOUS is non-nil, highlighting and exposing
+done by a previous call to `org-occur' will be kept, to allow stacking of
+calls to this command.
+
+Optional argument CALLBACK can be a function of no argument. In this case,
+it is called with point at the end of the match, match data being set
+accordingly. Current match is shown only if the return value is non-nil.
+The function must neither move point nor alter narrowing."
(interactive "sRegexp: \nP")
(when (equal regexp "")
(user-error "Regexp cannot be empty"))
@@ -13883,12 +13889,11 @@ that the match should indeed be shown."
(let ((cnt 0))
(save-excursion
(goto-char (point-min))
- (when (or (not keep-previous) ; do not want to keep
- (not org-occur-highlights)) ; no previous matches
+ (when (or (not keep-previous) ; do not want to keep
+ (not org-occur-highlights)) ; no previous matches
;; hide everything
(org-overview))
(while (re-search-forward regexp nil t)
- (backward-char) ;; FIXME: Match timestamps at the end of a headline
(when (or (not callback)
(save-match-data (funcall callback)))
(setq cnt (1+ cnt))
@@ -17507,7 +17512,10 @@ both scheduled and deadline timestamps."
(lambda ()
(let ((match (match-string 1)))
(and (if (memq ts-type '(active inactive all))
- (eq (org-element-type (org-element-context)) 'timestamp)
+ (eq (org-element-type (save-excursion
+ (backward-char)
+ (org-element-context)))
+ 'timestamp)
(org-at-planning-p))
(time-less-p
(org-time-string-to-time match)
@@ -17526,7 +17534,10 @@ both scheduled and deadline timestamps."
(lambda ()
(let ((match (match-string 1)))
(and (if (memq ts-type '(active inactive all))
- (eq (org-element-type (org-element-context)) 'timestamp)
+ (eq (org-element-type (save-excursion
+ (backward-char)
+ (org-element-context)))
+ 'timestamp)
(org-at-planning-p))
(not (time-less-p
(org-time-string-to-time match)
@@ -17547,7 +17558,10 @@ both scheduled and deadline timestamps."
(let ((match (match-string 1)))
(and
(if (memq type '(active inactive all))
- (eq (org-element-type (org-element-context)) 'timestamp)
+ (eq (org-element-type (save-excursion
+ (backward-char)
+ (org-element-context)))
+ 'timestamp)
(org-at-planning-p))
(not (time-less-p
(org-time-string-to-time match)
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 591e83f..c1aaa8f 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -4318,6 +4318,27 @@ Paragraph<point>"
(search-forward "H2")
(org-invisible-p2))))
+(ert-deftest test-org/occur ()
+ "Test `org-occur' specifications."
+ ;; Count number of matches.
+ (should
+ (= 1
+ (org-test-with-temp-text "* H\nA\n* H2"
+ (org-occur "A"))))
+ (should
+ (= 2
+ (org-test-with-temp-text "* H\nA\n* H2\nA"
+ (org-occur "A"))))
+ ;; Test CALLBACK optional argument.
+ (should
+ (= 0
+ (org-test-with-temp-text "* H\nA\n* H2"
+ (org-occur "A" nil (lambda () (equal (org-get-heading) "H2"))))))
+ (should
+ (= 1
+ (org-test-with-temp-text "* H\nA\n* H2\nA"
+ (org-occur "A" nil (lambda () (equal (org-get-heading) "H2")))))))
+
;;; Tags