From: Mattias EngdegÄrd Date: Sun, 1 Aug 2021 09:52:00 +0000 (+0200) Subject: Indicate selected occur target with fringe arrow X-Git-Tag: emacs-28.0.90~1611 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=660b17ef3e2f169478b56aaaacf6b9aa761b0619;p=emacs.git Indicate selected occur target with fringe arrow * lisp/replace.el (occur--set-arrow): New function. (occur-mode-goto-occurrence) (occur-mode-goto-occurrence-other-window) (occur-mode-display-occurrence): Call it. * etc/NEWS: Announce. --- diff --git a/etc/NEWS b/etc/NEWS index bd5c803d376..95a2c87d054 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -791,6 +791,9 @@ compilation buffers, recenters the current displayed occurrence/error. The method of highlighting is specified by the user options 'next-error-highlight' and 'next-error-highlight-no-select'. +--- +*** A fringe arrow in the '*Occur*' buffer indicates the selected match. + --- *** Occur mode may use a different type for 'occur-target' property values. The value was previously always a marker set to the start of the first diff --git a/lisp/replace.el b/lisp/replace.el index 148b7ce48b1..462cc26e993 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -1443,6 +1443,19 @@ To return to ordinary Occur mode, use \\[occur-cease-edit]." (error "Buffer for this occurrence was killed")) targets)) +(defun occur--set-arrow () + "Set the overlay arrow at the first line of the occur match at point." + (save-excursion + (let ((start (point)) + (target (get-text-property (point) 'occur-target)) + ;; Find the start of the occur match, in case it's multi-line. + (prev (previous-single-property-change (point) 'occur-target))) + (when (and prev (eq (get-text-property prev 'occur-target) target)) + (goto-char prev)) + (setq overlay-arrow-position + (set-marker (or overlay-arrow-position (make-marker)) + (line-beginning-position)))))) + (defalias 'occur-mode-mouse-goto 'occur-mode-goto-occurrence) (defun occur-mode-goto-occurrence (&optional event) "Go to the occurrence specified by EVENT, a mouse click. @@ -1460,6 +1473,7 @@ If not invoked by a mouse click, go to occurrence on the current line." (goto-char (posn-point (event-end event))) (occur-mode--find-occurrences))))) (pos (occur--targets-start targets))) + (occur--set-arrow) (pop-to-buffer (marker-buffer pos)) (goto-char pos) (occur--highlight-occurrences targets) @@ -1471,6 +1485,7 @@ If not invoked by a mouse click, go to occurrence on the current line." (interactive) (let ((buffer (current-buffer)) (pos (occur--targets-start (occur-mode--find-occurrences)))) + (occur--set-arrow) (switch-to-buffer-other-window (marker-buffer pos)) (goto-char pos) (next-error-found buffer (current-buffer)) @@ -1530,6 +1545,7 @@ If not invoked by a mouse click, go to occurrence on the current line." '(nil (inhibit-same-window . t))) window) (setq window (display-buffer (marker-buffer pos) t)) + (occur--set-arrow) ;; This is the way to set point in the proper window. (save-selected-window (select-window window)