From 1d9dd90f77a594cd50b368e6efc85d44539ec209 Mon Sep 17 00:00:00 2001 From: Denis Zubarev Date: Thu, 7 Mar 2024 20:16:22 +0300 Subject: Close #31: Switch to base buffer when updating imenu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- breadcrumb.el | 45 +++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/breadcrumb.el b/breadcrumb.el index 0abe57c..1dc3ed5 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 -- cgit v1.0