aboutsummaryrefslogtreecommitdiffstats
path: root/test/lisp/replace-tests.el
diff options
context:
space:
mode:
authorTino Calancha2020-05-31 12:31:27 +0200
committerTino Calancha2020-05-31 12:31:27 +0200
commitabe7c22da96694ced1bc80ec7eb9eb8a662a568b (patch)
treefe3b5f03fd32b3ab65738a27e0721052cc250940 /test/lisp/replace-tests.el
parent780f674a82a90c4e3e32583059b498bfa57e4a06 (diff)
downloademacs-abe7c22da96694ced1bc80ec7eb9eb8a662a568b.tar.gz
emacs-abe7c22da96694ced1bc80ec7eb9eb8a662a568b.zip
occur: Add bindings for next-error-no-select
Make the navigation in the occur buffer closer to the navigation in the compilation buffer. Add bindings to navigate the occur matches (Bug#39121). Honor `next-error-highlight' and `next-error-highlight-no-select' when navigating the occurrences. * lisp/replace.el (occur-highlight-regexp, occur-highlight-overlay): New variables. (occur-1): Set `occur-highlight-regexp' to the searched regexp. (occur-goto-locus-delete-o, occur--highlight-occurrence): New defuns. (occur-mode-display-occurrence, occur-mode-goto-occurrence): Use `occur--highlight-occurrence'. (occur-mode-map): Bind n to `next-error-no-select' and p to `previous-error-no-select' * etc/NEWS (Changes in Specialized Modes and Packages in Emacs 28.1): Announce this change. * test/lisp/replace-tests.el (replace-tests-with-highlighted-occurrence): Add helper macro. (occur-highlight-occurrence): Add test.
Diffstat (limited to 'test/lisp/replace-tests.el')
-rw-r--r--test/lisp/replace-tests.el42
1 files changed, 42 insertions, 0 deletions
diff --git a/test/lisp/replace-tests.el b/test/lisp/replace-tests.el
index f5cff92d546..aed14c33572 100644
--- a/test/lisp/replace-tests.el
+++ b/test/lisp/replace-tests.el
@@ -546,4 +546,46 @@ Return the last evalled form in BODY."
546 ?q 546 ?q
547 (string= expected (buffer-string)))))) 547 (string= expected (buffer-string))))))
548 548
549(defmacro replace-tests-with-highlighted-occurrence (highlight-locus &rest body)
550 "Helper macro to test the highlight of matches when navigating occur buffer.
551
552Eval BODY with `next-error-highlight' and `next-error-highlight-no-select'
553bound to HIGHLIGHT-LOCUS."
554 (declare (indent 1) (debug (form body)))
555 `(let ((regexp "foo")
556 (next-error-highlight ,highlight-locus)
557 (next-error-highlight-no-select ,highlight-locus)
558 (buffer (generate-new-buffer "test"))
559 (inhibit-message t))
560 (unwind-protect
561 ;; Local bind to disable the deletion of `occur-highlight-overlay'
562 (cl-letf (((symbol-function 'occur-goto-locus-delete-o) (lambda ())))
563 (with-current-buffer buffer (dotimes (_ 3) (insert regexp ?\n)))
564 (pop-to-buffer buffer)
565 (occur regexp)
566 (pop-to-buffer "*Occur*")
567 (occur-next)
568 ,@body)
569 (kill-buffer buffer)
570 (kill-buffer "*Occur*"))))
571
572(ert-deftest occur-highlight-occurrence ()
573 "Test for https://debbugs.gnu.org/39121 ."
574 (let ((alist '((nil . nil) (0.5 . t) (t . t) (fringe-arrow . nil)))
575 (check-overlays
576 (lambda (has-ov)
577 (eq has-ov (not (null (overlays-in (point-min) (point-max))))))))
578 (pcase-dolist (`(,highlight-locus . ,has-overlay) alist)
579 ;; Visiting occurrences
580 (replace-tests-with-highlighted-occurrence highlight-locus
581 (occur-mode-goto-occurrence)
582 (should (funcall check-overlays has-overlay)))
583 ;; Displaying occurrences
584 (replace-tests-with-highlighted-occurrence highlight-locus
585 (occur-mode-display-occurrence)
586 (with-current-buffer (marker-buffer
587 (get-text-property (point) 'occur-target))
588 (should (funcall check-overlays has-overlay)))))))
589
590
549;;; replace-tests.el ends here 591;;; replace-tests.el ends here