branch: externals/breadcrumb
commit 1d9dd90f77a594cd50b368e6efc85d44539ec209
Author: Denis Zubarev <[email protected]>
Commit: João Távora <[email protected]>

    Close #31: Switch to base buffer when updating imenu
    
    Fix #30.
    
    It is done to assure that imenu is updated only once for all indirect 
buffers.
    
    * breadcrumb.el (bc--ipath-alist): switch to base buffer.
    
    Co-authored-by: João Távora <[email protected]>
---
 breadcrumb.el | 45 +++++++++++++++++++++++----------------------
 1 file changed, 23 insertions(+), 22 deletions(-)

diff --git a/breadcrumb.el b/breadcrumb.el
index 0abe57c24e..1dc3ed5af8 100644
--- a/breadcrumb.el
+++ b/breadcrumb.el
@@ -235,28 +235,29 @@ These structures don't have a `breadcrumb-region' 
property on."
 
 (defun bc--ipath-alist ()
   "Return `imenu--index-alist', maybe arrange for its update."
-  (let ((nochangep (= (buffer-chars-modified-tick) bc--last-update-tick))
-        (buf (current-buffer)))
-    (unless nochangep
-      (setq bc--last-update-tick (buffer-chars-modified-tick))
-      (when bc--idle-timer (cancel-timer bc--idle-timer))
-      (setq bc--idle-timer
-            (run-with-idle-timer
-             bc-idle-time nil
-             (lambda ()
-               (when (buffer-live-p buf)
-                 (with-current-buffer buf
-                   (setq bc--last-update-tick (buffer-chars-modified-tick))
-                   (let ((non-essential t)
-                         (imenu-auto-rescan t))
-                     (ignore-errors
-                       (imenu--make-index-alist t))
-                     (setq bc--ipath-plain-cache nil)
-                     ;; no point is taxing the mode-line machinery now
-                     ;; if the buffer isn't showing anywhere.
-                     (when (get-buffer-window buf t)
-                       (force-mode-line-update t)))))))))
-    imenu--index-alist))
+  ;; Be mindful of indirect buffers (github#31)
+  (let ((buf (or (buffer-base-buffer) (current-buffer))))
+    (with-current-buffer buf
+      (unless (= (buffer-chars-modified-tick) bc--last-update-tick)
+        (setq bc--last-update-tick (buffer-chars-modified-tick))
+        (when bc--idle-timer (cancel-timer bc--idle-timer))
+        (setq bc--idle-timer
+              (run-with-idle-timer
+               bc-idle-time nil
+               (lambda ()
+                 (when (buffer-live-p buf)
+                   (with-current-buffer buf
+                     (setq bc--last-update-tick (buffer-chars-modified-tick))
+                     (let ((non-essential t)
+                           (imenu-auto-rescan t))
+                       (ignore-errors
+                         (imenu--make-index-alist t))
+                       (setq bc--ipath-plain-cache nil)
+                       ;; no point is taxing the mode-line machinery now
+                       ;; if the buffer isn't showing anywhere.
+                       (when (get-buffer-window buf t)
+                         (force-mode-line-update t)))))))))
+      imenu--index-alist)))
 
 
 ;;;; Higher-level functions

Reply via email to