From 2e42cc4b3026249f87cff1f1641b84847c720b70 Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Sun, 21 Dec 2025 19:49:23 +0200 Subject: [PATCH] Add text property 'imenu-region' for Eglot and 'M-x imenu' (bug#79980) * lisp/imenu.el (imenu--flatten-index-alist) (imenu--parentify-index-alist, imenu-choose-buffer-index): Use the text property 'imenu-region' instead of 'breadcrumb-region'. * lisp/progmodes/eglot.el (eglot--imenu-SymbolInformation) (eglot--imenu-DocumentSymbol): Add new text properties 'imenu-region' and 'imenu-kind' while keeping the old text properties 'breadcrumb-region' and 'breadcrumb-kind' for backward-compatibility. --- lisp/imenu.el | 6 +++--- lisp/progmodes/eglot.el | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lisp/imenu.el b/lisp/imenu.el index a0e6a5cac72..5c554d6919e 100644 --- a/lisp/imenu.el +++ b/lisp/imenu.el @@ -866,7 +866,7 @@ Returns t for rescan and otherwise an element or subelement of INDEX-ALIST." (t (let ((subalist (imenu--flatten-index-alist pos concat-names new-prefix)) - (region (get-text-property 0 'breadcrumb-region name))) + (region (get-text-property 0 'imenu-region name))) (if region ;; Add non-leaf nodes with Eglot text properties. (append (imenu--flatten-index-alist @@ -887,7 +887,7 @@ Returns t for rescan and otherwise an element or subelement of INDEX-ALIST." (list item)) (t (let ((subalist (imenu--parentify-index-alist pos)) - (region (get-text-property 0 'breadcrumb-region name))) + (region (get-text-property 0 'imenu-region name))) (when region (setq subalist (append (list (cons ".." (car region))) subalist))) (list (cons name subalist))))))) @@ -928,7 +928,7 @@ The returned value is of the form (INDEX-NAME . INDEX-POSITION)." ((when-let* ((alist (if (eq (car index-alist) imenu--rescan-item) (cdr index-alist) index-alist)) (name (caar alist))) - (get-text-property 0 'breadcrumb-region name)) + (get-text-property 0 'imenu-region name)) ;; Change the menu structure by adding ".." to non-leaf nodes ;; only when the first node has Eglot text properties. (setq index-alist (imenu--parentify-index-alist index-alist)))) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 7d8b2fd138f..415444d0c47 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -3966,6 +3966,10 @@ for which LSP on-type-formatting should be requested." (plist-get location :range))) (kind (alist-get kind eglot--symbol-kind-names))) (cons (propertize name + 'imenu-region reg + 'imenu-kind kind + ;; Backward-compatible props + ;; to be removed later: 'breadcrumb-region reg 'breadcrumb-kind kind) (car reg)))) @@ -3981,6 +3985,10 @@ for which LSP on-type-formatting should be requested." (let* ((reg (eglot-range-region range)) (kind (alist-get kind eglot--symbol-kind-names)) (name (propertize name + 'imenu-region reg + 'imenu-kind kind + ;; Backward-compatible props + ;; to be removed later: 'breadcrumb-region reg 'breadcrumb-kind kind))) (if (seq-empty-p children)