emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 660b17e: Indicate selected occur target with fringe arrow


From: Mattias Engdegård
Subject: master 660b17e: Indicate selected occur target with fringe arrow
Date: Sun, 1 Aug 2021 08:44:19 -0400 (EDT)

branch: master
commit 660b17ef3e2f169478b56aaaacf6b9aa761b0619
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>

    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.
---
 etc/NEWS        |  3 +++
 lisp/replace.el | 16 ++++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index bd5c803..95a2c87 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -792,6 +792,9 @@ 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
 match on the line but can now also be a list of '(BEGIN . END)' pairs
diff --git a/lisp/replace.el b/lisp/replace.el
index 148b7ce..462cc26 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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]