branch: elpa/git-commit commit 07e172a11fccf4ed4e4fb4f0109e467ac5c0fe5b Author: Jonas Bernoulli <jo...@bernoul.li> Commit: Jonas Bernoulli <jo...@bernoul.li>
magit-imenu--index-function: Exit early if buffer not ready If `which-function-mode' is active, then the create-index function is called at the time the major-mode is being enabled. Modes that derive from `magit-mode' have not populated the buffer at that time yet, so we have to abort. Before [1: 2db1172b1] failing to explicitly abort did not cause an error. Closes #4481. 1: 2021-08-21 2db1172b1c95782a9497f388638c28f2e3136872 magit-imenu--index-function: Move away from root section first --- lisp/magit-imenu.el | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lisp/magit-imenu.el b/lisp/magit-imenu.el index 8633121..a2a337d 100644 --- a/lisp/magit-imenu.el +++ b/lisp/magit-imenu.el @@ -52,9 +52,14 @@ elements of ENTRY-TYPES. This function is used as a helper for functions set as `imenu-create-index-function'." - (let ((entries (make-hash-table :test 'equal))) + ;; If `which-function-mode' is active, then the create-index + ;; function is called at the time the major-mode is being enabled. + ;; Modes that derive from `magit-mode' have not populated the buffer + ;; at that time yet, so we have to abort. + (when-let ((section (magit-current-section)) + (entries (make-hash-table :test 'equal))) (goto-char (point-max)) - (unless (oref (magit-current-section) parent) + (unless (oref section parent) (forward-line -1)) (while (magit-section--backward-find (lambda ()